Sophie

Sophie

distrib > Fedora > 14 > x86_64 > by-pkgid > 65cedb422b5b18cbc6c81220baa7524d > files > 50

libsigc++-devel-1.2.7-8.fc12.i686.rpm

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Chapter 3. Writing your own signals</title><meta name="generator" content="DocBook XSL Stylesheets V1.75.2" /><link rel="home" href="index.html" title="LibSigC++" /><link rel="up" href="index.html" title="LibSigC++" /><link rel="prev" href="ch02s04.html" title="Disconnecting" /><link rel="next" href="ch03s02.html" title="What about return values?" /></head><body><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" title="Chapter 3. Writing your own signals"><div class="titlepage"><div><div><h2 class="title"><a id="sec-writing"></a>Chapter 3. Writing your own signals</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="sect1"><a href="ch03.html#id3051675">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" title="Quick recap"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="id3051675"></a>Quick recap</h2></div></div></div><p>If all you want to do is use gtkmm, and connect your functionality to its
	signals, you can probably stop reading here.</p><p>You might benefit from reading on anyway though, as this section is going to
	be quite simple, and the 'Rebinding' technique from the next section is
	occasionally useful.</p><p>We've already covered the way the types of signals are made up, but lets
	recap:</p><p>A signal is an instance of a template, named <code class="literal">SigC::SignalN</code> where
	N is the number of arguments taken, 0-5. The template arguments are the types,
	in the order they appear in the function signature that can be connected to that
	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
	instance of that <code class="literal">SigC::Signal</code>. In <code class="literal">AlienDetector</code> this was done
	with a public data member. That's not considered good practice usually, so you
	might want to consider making a member function that returns the signal by
	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
	ready. Look at the code for <code class="literal">AlienDetector::run()</code>:</p><pre class="programlisting">
void AlienDetector::run()
{
    sleep(3); // wait for aliens
    detected.emit(); // panic!
}
</pre><p>As a shortcut, <code class="literal">Signal</code> defines <code class="literal">operator()</code> as a synonym for
	<code class="literal">emit()</code>, so you could just write <code class="literal">detected();</code> as in the second
	example version:</p><pre class="programlisting">
void AlienDetector::run()
{
    sleep(3);                // wait for aliens
    detected("the carpark"); // this is the std::string version, looks like
       	                     // they landed in the carpark afterall.
}
</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"> </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>