~ubuntu-branches/ubuntu/wily/libsigc++-2.0/wily-proposed

« back to all changes in this revision

Viewing changes to docs/manual/html/ch03.html

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Burrows
  • Date: 2005-07-10 14:34:54 UTC
  • mfrom: (2.1.1 sarge)
  • Revision ID: james.westby@ubuntu.com-20050710143454-1lickjxb8hzzupx7
Tags: 2.0.10-3
Fix dh_makeshlibs call (it WOULD be the one that I didn't check that
needed to be changed; Closes: #317682).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Chapter�3.�Writing your own signals</title><meta name="generator" content="DocBook XSL Stylesheets V1.65.1"><link rel="home" href="index.html" title="LibSigC++"><link rel="up" href="index.html" title="LibSigC++"><link rel="previous" href="ch02s04.html" title="Disconnecting"><link rel="next" href="ch03s02.html" title="What about return values?"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter�3.�Writing your own signals</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch02s04.html">Prev</a>�</td><th width="60%" align="center">�</th><td width="20%" align="right">�<a accesskey="n" href="ch03s02.html">Next</a></td></tr></table><hr></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="sec-writing"></a>Chapter�3.�Writing your own signals</h2></div></div><div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="sect1"><a href="ch03.html#id2447554">Quick recap</a></span></dt><dt><span class="sect1"><a href="ch03s02.html">What about return values?</a></span></dt></dl></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2447554"></a>Quick recap</h2></div></div><div></div></div><p>If all you want to do is use gtkmm, and connect your functionality to its
 
2
        signals, you can probably stop reading here.</p><p>You might benefit from reading on anyway though, as this section is going to
 
3
        be quite simple, and the 'Rebinding' technique from the next section is
 
4
        occasionally useful.</p><p>We've already covered the way the types of signals are made up, but lets
 
5
        recap:</p><p>A signal is an instance of a template, named <tt class="literal">sigc::signal</tt>. 
 
6
        The template arguments are the types,
 
7
        in the order they appear in the function signature that can be connected to that
 
8
        signal; that is the return type, then the argument types.</p><p>To provide a signal for people to connect to, you must make available an
 
9
        instance of that <tt class="literal">sigc::signal</tt>. In <tt class="literal">AlienDetector</tt> this was done
 
10
        with a public data member. That's not considered good practice usually, so you
 
11
        might want to consider making a member function that returns the signal by
 
12
        reference. (This is what gtkmm does.)</p><p>Once you've done this, all you have to do is emit the signal when you're
 
13
        ready. Look at the code for <tt class="literal">AlienDetector::run()</tt>:</p><pre class="programlisting">
 
14
void AlienDetector::run()
 
15
{
 
16
    sleep(3); // wait for aliens
 
17
    signal_detected.emit(); // panic!
 
18
}
 
19
</pre><p>As a shortcut, <tt class="literal">sigc::signal</tt> defines <tt class="literal">operator()</tt> as a synonym for
 
20
        <tt class="literal">emit()</tt>, so you could just write <tt class="literal">signal_detected();</tt> as in the second
 
21
        example version:</p><pre class="programlisting">
 
22
void AlienDetector::run()
 
23
{
 
24
    sleep(3);                // wait for aliens
 
25
    signal_detected("the carpark"); // this is the std::string version, looks like
 
26
                             // they landed in the carpark afterall.
 
27
}
 
28
</pre></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch02s04.html">Prev</a>�</td><td width="20%" align="center"><a accesskey="u" href="index.html">Up</a></td><td width="40%" align="right">�<a accesskey="n" href="ch03s02.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Disconnecting�</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top">�What about return values?</td></tr></table></div></body></html>