[boost-doc-zh commit] r261 - Signals2教程(还差最后两小节). 同时更新Signal教程.

  • From: codesite-noreply@xxxxxxxxxx
  • To: boost-doc-zh-notify@xxxxxxxxxxxxx
  • Date: Fri, 05 Jun 2009 14:28:05 +0000

Author: jinq0123@xxxxxxx
Date: Fri Jun  5 07:20:42 2009
New Revision: 261

Modified:
   trunk/doc/html/signals/tutorial.html
   trunk/doc/html/signals2/tutorial.html

Log:
Signals2教程(还差最后两小节). 同时更新Signal教程.

Modified: trunk/doc/html/signals/tutorial.html
==============================================================================
--- trunk/doc/html/signals/tutorial.html        (original)
+++ trunk/doc/html/signals/tutorial.html        Fri Jun  5 07:20:42 2009
@@ -4,9 +4,9 @@
 <title>Tutorial</title>
 <link rel="stylesheet" href="../boostbook.css" type="text/css">
 <meta name="generator" content="DocBook XSL Stylesheets V1.73.2">
-<link rel="start" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
-<link rel="up" href="../signals.html" title="Chapter 14. Boost.Signals">
-<link rel="prev" href="../signals.html" title="Chapter 14. Boost.Signals">
+<link rel="home" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
+<link rel="up" href="../signals.html" title="Chapter 16. Boost.Signals">
+<link rel="prev" href="../signals.html" title="Chapter 16. Boost.Signals">
 <link rel="next" href="reference.html" title="Reference">
 </head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
@@ -106,7 +106,7 @@
 <p>
 本教程不是用来线性阅读的。

-其顶层结构大致按库中不同的概念划分,(如处理调用多个插槽、传值到插槽及回传 ),并且在每一个这些概念中,首先介绍其基本思想,然后说明库较复杂的使用。 +其顶层结构大致按库中不同的概念划分,(如处理多个插槽的调用、传值到插槽及回 传),并且在每一个概念中,首先介绍其基本思想,然后说明库较复杂的使用。

 每个部分都标注了<span class="emphasis"><em>初级</em></span>、
<span class="emphasis"><em>中级</em></span>,或<span class="emphasis"><em>高级</em></span>,以帮助指导读者。
@@ -348,7 +348,7 @@
 <p>The second slot will print ", World!" and a newline, to complete
 the program. The second slot may look like this:</p>

-<p>第二个插槽将打印", World!"并回车以完成该程序。
+<p>第二个插槽将打印", World!"和换行,以完成该程序。
 第二个插槽可能看起来像这样:</p>

 <pre class="programlisting">
@@ -366,7 +366,7 @@
<code class="computeroutput">hello</code> and a <code class="computeroutput">world</code> slot to the same
 signal, and when we call the signal both slots will be called.</p>

-<p>就像我们的上个例子,我们创建信号
+<p>和上个例子一样,我们创建信号
 <code class="computeroutput">sig</code>,
 它没有参数并且返回值为
 <code class="computeroutput">void</code>。
@@ -441,18 +441,18 @@
are, by default, <code class="computeroutput">int</code>s, and are ordered by the integer
 &lt; relation. Here's how we construct Hello, World:</p>

-<p>插槽可以随意具有副作用,即某些插槽必须在另一些之前调用,即使它们不是按那 个次序连接的。 +<p>插槽可以有副作用,这意味着某些插槽必须在另一些之前调用,即使它们不是按那 个次序连接的。

-Boost.Signals 库允许插槽被置于按某种方式排序的编组中。
+Boost.Signals 库允许插槽进行分组,并按某种方式排序编组。

 对于我们的 Hello, World 程序,我们要"Hello"在", World!"之前打印,
 所以我们将"Hello"放入一个组,该组将在", World!"所在组之前执行。

 为了做到这一点,我们可以在
 <code class="computeroutput">connect</code>
-调用的头部提供一个额外的参数,以指定该组。
+调用的头部提供一个额外的参数,以指定编组。

-编组的值默认为
+编组值默认为
 <code class="computeroutput">int</code>,
 并按整型的 &lt; 关系排序。

@@ -522,7 +522,7 @@
 而默认为链表的结尾。

 当指定了编组时,最后的参数描述的是插槽在组内的次序。
-如果我们如下向我们的例子添加新的插槽:
+如果在我们的例子中添加新的插槽,如下:
 </p>

 <pre class="programlisting">
@@ -538,7 +538,7 @@
 </pre>
 <p>... we will get the result we wanted:</p>

-<p>......我们将得到我们想要的结果:</p>
+<p>......我们会得到想要的结果:</p>

 <pre class="programlisting">
 Hello, World!
@@ -589,10 +589,10 @@
 slots that print the results of various arithmetic operations on
 these values.</p>

-<p>作为一个例子,我们将创建一个信号,它将传入两个
+<p>例如,我们创建一个信号,它将传入两个
 <code class="computeroutput">float</code> 参数到它的插槽。

-然后我们将创建几个插槽,它们将打印对这两个参数进行算术运算的各种结果。
+然后我们再创建几个插槽,打印对这两个参数进行算术运算的各种结果。
 </p>

 <pre class="programlisting">
@@ -792,15 +792,15 @@
 类模板的第一个模板参数)的信号的默认行为是,
 调用所有的插槽,然后返回最后一个被调用插槽的结果。

-对本例来说,该行为确实有点傻,因为这些插槽没有副作用并且结果就是最后的插槽 连接。 +对本例来说,该行为确实有点傻,因为这些插槽没有副作用,所以结果就是最后连接 的插槽。
 </p>

 <p>A more interesting signal result would be the maximum of the
 values returned by any slot. To do this, we create a custom
 combiner that looks like this:</p>

-<p>一个更有意思的信号结果是,求所有插槽返回值的最大值。
-为了做到这一点,我们创建了一个自定义合并器,看起来像这样:
+<p>求所有插槽返回值的最大值,这样的信号结果才有点意思。
+为些,我们创建一个自定义合并器如下:
 </p>

 <pre class="programlisting">
@@ -921,9 +921,9 @@
 computed by the slots together, in one large data structure. This
 is easily done with a different combiner:</p>

-<p>在其他情况下,我们可能要同时返回插槽计算的所有值,
+<p>在其他情况下,我们可能需要同时返回插槽计算的所有值,
 如保存在一个大型的数据结构中。
-这可以用一个不同的合并器来轻松完成:
+用一个不同的合并器就可以轻松做到:
 </p>

 <pre class="programlisting">
@@ -1000,7 +1000,7 @@
 signal.</p>

 <p>该程序的输出将包含 15、8、1.6667,和 2。
-这里有趣的是,
+有趣的是,
 <code class="computeroutput">signal</code>
 类的第一个模板参数,
 <code class="computeroutput">float</code>,
@@ -1111,9 +1111,10 @@
 are then disconnected, and the programmer needs control to decide
 when a slot should no longer be connected.</p>

-<p>插槽不要求在它们被连接后无限期地存在。
-往往插槽只是用来接收一些事件然后断开,
-而程序员需要控制决定何时插槽不应该再继续连接。
+<p>插槽在连接之后不必无限期地存在。
+插槽往往只是用来接收一些事件然后断开,
+当插槽不再需要保持连接时,
+程序员可以做出决定并控制。
 </p>

 <p>The entry point for managing connections explicitly is the
@@ -1475,7 +1476,7 @@
 signal's <code class="computeroutput">disconnect</code> method or
 <code class="computeroutput">scoped_connection</code>'s destructor.</p>

-<p>连接显式断开:
+<p>连接被显式地断开:
 直接通过连接的
 <code class="computeroutput">disconnect</code> 方法,
 或间接地通过信号的
@@ -1490,14 +1491,14 @@
 destroyed.</p>

 <p>
-销毁绑定于插槽的 <code class="computeroutput">trackable</code> 对象。
+绑定于插槽的 <code class="computeroutput">trackable</code> 对象被销毁。
 </p>

 </li>

 <li><p>The signal is destroyed.</p>

-<p>销毁信号。</p>
+<p>信号被销毁。</p>

 </li>
 </ul></div>
@@ -1804,9 +1805,9 @@
simple <code class="computeroutput">main</code> function that sets up two views and then
     modifies the document:</p>

-<p>将例子合起来,下面一个简单的
+<p>为了把例子串起来,有个简单的
   <code class="computeroutput">main</code>
-  函数建立了两个视图,然后更改文档:
+  函数,它建立了两个视图,然后更改文档:
     </p>

 <pre class="programlisting">int main(int argc, char* argv[])
@@ -1821,9 +1822,9 @@
 <p>The complete example source, contributed by Keith MacDonald,
is available in <a href="../../../libs/signals/example/doc_view.cpp" target="_top"><code class="computeroutput">libs/signals/example/doc_view.cpp</code></a>.</p>

-<p>例子完整的源代码在
- <a href="../../../libs/signals/example/doc_view.cpp" target="_top"><code class="computeroutput">libs/signals/example/doc_view.cpp</code></a>,
-    由 Keith MacDonald 提供。</p>
+<p>完整的例程源码,由 Keith MacDonald 提供,在
+ <a href="../../../libs/signals/example/doc_view.cpp" target="_top"><code class="computeroutput">libs/signals/example/doc_view.cpp</code></a>。
+    </p>

 </div>
 <div class="section" lang="en">
@@ -1859,7 +1860,7 @@
<code class="filename">LICENSE_1_0.txt</code> or copy at <a href="http://www.boost.org/LICENSE_1_0.txt"; target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)</p>

       <p>翻译:<a href="http://blog.csdn.net/jq0123";>金庆</a></p>
-      <p>译文更新:2008.6.30</p>
+      <p>译文更新:2009.6.5</p>

 </div></td>
 </tr></table>

Modified: trunk/doc/html/signals2/tutorial.html
==============================================================================
--- trunk/doc/html/signals2/tutorial.html       (original)
+++ trunk/doc/html/signals2/tutorial.html       Fri Jun  5 07:20:42 2009
@@ -1,12 +1,12 @@
 <html>
 <head>
-<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 <title>Tutorial</title>
 <link rel="stylesheet" href="../boostbook.css" type="text/css">
 <meta name="generator" content="DocBook XSL Stylesheets V1.74.3">
<link rel="home" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
-<link rel="up" href="../signals2.html" title="Chapter 17. Boost.Signals2">
-<link rel="prev" href="../signals2.html" title="Chapter 17. Boost.Signals2">
+<link rel="up" href="../signals2.html" title="Chapter 17. Boost.Signals2">
+<link rel="prev" href="../signals2.html" title="Chapter 17. Boost.Signals2">
 <link rel="next" href="examples.html" title="Example programs">
 </head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
@@ -23,8 +23,13 @@
<a accesskey="p" href="../signals2.html"><img src="../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../signals2.html"><img src="../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="examples.html"><img src="../../../doc/html/images/next.png" alt="Next"></a>
 </div>
 <div class="section" lang="en">
+
 <div class="titlepage"><div><div><h2 class="title" style="clear: both">
 <a name="signals2.tutorial"></a>Tutorial</h2></div></div></div>
+
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="signals2.tutorial"></a>教程</h2></div></div></div>
+
 <div class="toc"><dl>
<dt><span class="section"><a href="tutorial.html#id3351397">How to Read this Tutorial</a></span></dt> <dt><span class="section"><a href="tutorial.html#id3351460">Compatibility Note</a></span></dt>
@@ -37,9 +42,53 @@
<dt><span class="section"><a href="tutorial.html#signals2.tutorial.signal-mutex-template-parameter">Changing the Mutex Type of a Signal (Advanced).</a></span></dt> <dt><span class="section"><a href="tutorial.html#id3353969">Linking against the Signals2 library</a></span></dt>
 </dl></div>
+
+<div class="toc"><dl>
+<dt><span class="section"><a href="tutorial.html#terms20090605">术语表 </a></span></dt> +<dt><span class="section"><a href="tutorial.html#id3351397">如何阅读本教程 </a></span></dt> +<dt><span class="section"><a href="tutorial.html#id3351460">对兼容性的注释 </a></span></dt> +<dt><span class="section"><a href="tutorial.html#id3351478">Hello, World! (初级)</a></span></dt> +<dt><span class="section"><a href="tutorial.html#id3351586">调用多个插槽 </a></span></dt> +<dt><span class="section"><a href="tutorial.html#id3351941">传值到插槽及回 传</a></span></dt> +<dt><span class="section"><a href="tutorial.html#id3352571">连接管理 </a></span></dt> +<dt><span class="section"><a href="tutorial.html#signals2.tutorial.document-view">例子:文档-视图 </a></span></dt> +<dt><span class="section"><a href="tutorial.html#signals2.tutorial.extended-slot-type">让插槽可以操作其连 接(高级)</a></span></dt> +<dt><span class="section"><a href="tutorial.html#signals2.tutorial.signal-mutex-template-parameter">改变 信号的互斥体类型(高级)</a></span></dt> +<dt><span class="section"><a href="tutorial.html#id3353969">链接 Signals2 库</a></span></dt>
+</dl></div>
+
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="terms20090605"></a>术语表</h3>
+</div></div></div>
+
+<table cellpadding="2" border="1">
+<tr><th>英文</th> <th>中文</th> <th>注释</th></tr>
+
+<tr><td>block</td><td>阻塞</td><td>&nbsp;</td></tr>
+<tr><td>combiner</td><td>合并器</td><td>&nbsp;</td></tr>
+<tr><td>compatibility form</td><td>兼容形式</td><td>&nbsp;</td></tr>
+<tr><td>connect</td><td>连接</td><td>&nbsp;</td></tr>
+<tr><td>connection</td><td>连接</td><td>&nbsp;</td></tr>
+<tr><td>disconnect</td><td>断开</td><td>&nbsp;</td></tr>
+<tr><td>portable syntax</td><td>兼容句法</td><td>可移植句法</td></tr>
+<tr><td>preferred form</td><td>首选形式</td><td>&nbsp;</td></tr>
+<tr><td>preferred syntax</td><td>首选句法</td><td>&nbsp;</td></tr>
+<tr><td>scoped</td><td>域内的</td><td>作用域内的</td></tr>
+<tr><td>signal</td><td>信号</td><td>&nbsp;</td></tr>
+<tr><td>slot</td><td>插槽</td><td>&nbsp;</td></tr>
+
+</table>
+</div>
+
 <div class="section" lang="en">
+
 <div class="titlepage"><div><div><h3 class="title">
 <a name="id3351397"></a>How to Read this Tutorial</h3></div></div></div>
+
+<div class="titlepage"><div><div><h3 class="title">
+<a name="id3351397"></a>如何阅读本教程</h3></div></div></div>
+
 <p>This tutorial is not meant to be read linearly. Its top-level
 structure roughly separates different concepts in the library
 (e.g., handling calling multiple slots, passing values to and from
@@ -56,10 +105,34 @@
 Signals2 library, that often require a solid working knowledge of
the <span class="emphasis"><em>Beginner</em></span> and <span class="emphasis"><em>Intermediate</em></span> topics; most users will not need to read the <span class="emphasis"><em>Advanced</em></span> sections.</p>
+
+<p>
+本教程不是用来线性阅读的。
+
+其顶层结构大致按库中不同的概念划分,(如处理多个插槽的调用、传值到插槽及回 传),并且在每一个概念中,首先介绍其基本思想,然后说明库较复杂的使用。
+
+每个部分都标注了<span class="emphasis"><em>初级</em></span>、
+<span class="emphasis"><em>中级</em></span>,或<span class="emphasis"><em>高级</em></span>,以帮助指导读者。
+
+<span class="emphasis"><em>初级</em></span>部分包括库的所有使用者都该了解的 信息;只要阅读了<span class="emphasis"><em>初级</em></span>部分,就可以很好 地使用 Signals2 库。
+
+<span class="emphasis"><em>中级</em></span>部分建立在<span class="emphasis"><em>初级</em></span>
+部分之上,是库的稍复杂的使用。
+
+最后,<span class="emphasis"><em>高级</em></span>部分详述了 Signals2 库很高 级的应用,这往往需要对<span class="emphasis"><em>初级</em></span>和<span class="emphasis"><em>中级</em></span>内容扎实的实践经验;
+大多数用户无需阅读<span class="emphasis"><em>高级</em></span>部分。
+</p>
+
 </div>
+
 <div class="section" lang="en">
+
 <div class="titlepage"><div><div><h3 class="title">
 <a name="id3351460"></a>Compatibility Note</h3></div></div></div>
+
+<div class="titlepage"><div><div><h3 class="title">
+<a name="id3351460"></a>对兼容性的注释</h3></div></div></div>
+
 <p>Boost.Signals2 has two syntactical forms: the preferred form and
 the compatibility form. The preferred form fits more closely with the
 C++ language and reduces the number of separate template parameters
@@ -68,10 +141,26 @@
 bugs. Users of Boost.Function, please note
 that the preferred syntactic form in Signals2 is equivalent to that of
 Function's preferred syntactic form.</p>
+
+<p>Boost.Signals2 有两种句法形式:首选形式(preferred form)和兼容形式 (compatibility form)。
+
+首选形式能更紧密地适合C++语言,
+并减少需要考虑的独立模板参数的个数,
+往往能提高可读性;
+然而,由于编译器的错误,首选形式并非所有平台都支持。
+
+Boost.Function 的用户请注意,Signals2 中的首选句法形式等效于 Function 的首 选句法形式。
+</p>
+
 </div>
 <div class="section" lang="en">
+
 <div class="titlepage"><div><div><h3 class="title">
 <a name="id3351478"></a>Hello, World! (Beginner)</h3></div></div></div>
+
+<div class="titlepage"><div><div><h3 class="title">
+<a name="id3351478"></a>Hello, World! (初级)</h3></div></div></div>
+
 <p>The following example writes "Hello, World!" using signals and
slots. First, we create a signal <code class="computeroutput">sig</code>, a signal that
 takes no arguments and has a void return value. Next, we connect
@@ -80,6 +169,22 @@
<code class="computeroutput">sig</code> like a function to call the slots, which in turns invokes <code class="computeroutput">HelloWorld::operator()</code> to print "Hello,
 World!".</p>
+
+<p>下例将使用信号和插槽写出"Hello, World!"。
+
+首先,我们创建信号 <code class="computeroutput">sig</code>,该信号无参数并 且返回值为空。
+
+接着,我们使用 <code class="computeroutput">connect</code>
+方法将 <code class="computeroutput">hello</code>
+函数对象连接到信号。
+
+最后,像函数一样使用信号
+<code class="computeroutput">sig</code>
+来调用插槽,
+它将转而调用 <code class="computeroutput">HelloWorld::operator()</code>
+打印"Hello, World!"。
+</p>
+
 <pre class="programlisting"><code class="computeroutput">struct HelloWorld
 {
   void operator()() const
@@ -125,21 +230,45 @@
 </tr></tbody>
 </table></div>
 </div>
+
 <div class="section" lang="en">
+
 <div class="titlepage"><div><div><h3 class="title">
 <a name="id3351586"></a>Calling Multiple Slots</h3></div></div></div>
+
+<div class="titlepage"><div><div><h3 class="title">
+<a name="id3351586"></a>调用多个插槽</h3></div></div></div>
+
 <div class="toc"><dl>
<dt><span class="section"><a href="tutorial.html#id3351590">Connecting Multiple Slots (Beginner)</a></span></dt> <dt><span class="section"><a href="tutorial.html#id3351728">Ordering Slot Call Groups (Intermediate)</a></span></dt>
 </dl></div>
+
+<div class="toc"><dl>
+<dt><span class="section"><a href="tutorial.html#id3351590">连接多个插槽 (初级)</a></span></dt> +<dt><span class="section"><a href="tutorial.html#id3351728">插槽调用组排序 (中级)</a></span></dt>
+</dl></div>
+
 <div class="section" lang="en">
+
 <div class="titlepage"><div><div><h4 class="title">
<a name="id3351590"></a>Connecting Multiple Slots (Beginner)</h4></div></div></div>
+
+<div class="titlepage"><div><div><h4 class="title">
+<a name="id3351590"></a>连接多个插槽(初级)</h4></div></div></div>
+
 <p>Calling a single slot from a signal isn't very interesting, so
 we can make the Hello, World program more interesting by splitting
 the work of printing "Hello, World!" into two completely separate
 slots. The first slot will print "Hello" and may look like
 this:</p>
+
+<p>从信号调用单个插槽不是很有意思,
+因此我们将打印"Hello, World!"的工作拆分到两个完全独立的插槽,
+让 Hello, World 程序更有趣点。
+
+第一个插槽将打印"Hello",可能看起来像这样:</p>
+
 <pre class="programlisting"><code class="computeroutput">struct Hello
 {
   void operator()() const
@@ -148,8 +277,13 @@
   }
 };
 </code></pre>
+
 <p>The second slot will print ", World!" and a newline, to complete
 the program. The second slot may look like this:</p>
+
+<p>第二个插槽将打印", World!"和换行,以完成该程序。
+第二个插槽可能看起来像这样:</p>
+
 <pre class="programlisting"><code class="computeroutput">struct World
 {
   void operator()() const
@@ -163,6 +297,19 @@
<code class="computeroutput">void</code> return value. This time, we connect both a <code class="computeroutput">hello</code> and a <code class="computeroutput">world</code> slot to the same
 signal, and when we call the signal both slots will be called.</p>
+
+<p>和上个例子一样,我们创建信号
+<code class="computeroutput">sig</code>,
+它没有参数并且返回值为
+<code class="computeroutput">void</code>。
+
+这次,我们将
+<code class="computeroutput">hello</code>
+和 <code class="computeroutput">world</code>
+插槽都连接到同一个信号,
+当我们调用该信号,两个插槽都将会被调用。
+</p>
+
 <div class="informaltable"><table class="table">
 <colgroup>
 <col>
@@ -195,6 +342,11 @@
 </table></div>
 <p>By default, slots are pushed onto the back of the slot list,
 so the output of this program will be as expected:</p>
+
+<p>默认情况下,插槽会被加到插槽链表的尾部,
+因此该程序的输出应该是:
+</p>
+
 <pre class="programlisting">
 Hello, World!
 </pre>
@@ -202,6 +354,10 @@
 <div class="section" lang="en">
 <div class="titlepage"><div><div><h4 class="title">
<a name="id3351728"></a>Ordering Slot Call Groups (Intermediate)</h4></div></div></div>
+
+<div class="titlepage"><div><div><h4 class="title">
+<a name="id3351728"></a>插槽调用组排序(中级)</h4></div></div></div>
+
 <p>Slots are free to have side effects, and that can mean that some
slots will have to be called before others even if they are not connected in that order. The Boost.Signals2
 library allows slots to be placed into groups that are ordered in
@@ -212,6 +368,25 @@
<code class="computeroutput">connect</code> call that specifies the group. Group values are, by default, <code class="computeroutput">int</code>s, and are ordered by the integer
 &lt; relation. Here's how we construct Hello, World:</p>
+
+<p>插槽可以有副作用,这意味着某些插槽必须在另一些之前调用,即使它们不是按那 个次序连接的。
+
+Boost.Signals2 库允许插槽进行分组,并按某种方式排序编组。
+
+对于我们的 Hello, World 程序,我们要"Hello"在", World!"之前打印,
+所以我们将"Hello"放入一个组,该组将在", World!"所在组之前执行。
+
+为了做到这一点,我们可以在
+<code class="computeroutput">connect</code>
+调用的头部提供一个额外的参数,以指定编组。
+
+编组值默认为
+<code class="computeroutput">int</code>,
+并按整型的 &lt; 关系排序。
+
+我们这样构造 Hello, World:
+</p>
+
 <div class="informaltable"><table class="table">
 <colgroup>
 <col>
@@ -256,9 +431,42 @@
slots connected with <code class="computeroutput">at_back</code> will always succeed all
 grouped slots.
 </p>
+
+<p>调用该信号将正确打印出"Hello, World!",因为
+<code class="computeroutput">Hello</code> 对象在组 0,它在
+<code class="computeroutput">World</code> 对象所在的组 1 之前。
+
+编组参数实际上是可选的。
+在第一个 Hello World 例子中我们省略了它,
+因为当所有的插槽都独立时,编组是不必要的。
+
+那么,如果我们混合调用使用和不使用编组参数的连接会怎样?
+"未命名"插槽(即那些连接时未指定组名的插槽)可置于插槽链表的头部或尾部
+(通过向
+<code class="computeroutput"><a class="link" href="../boost/signals2/signalN.html#id1284885-bb">connect</a></code>
+分别传入
+<code class="computeroutput">boost::signals2::at_front</code> 或
+<code class="computeroutput">boost::signals2::at_back</code>
+作为最后的参数),
+而默认为链表的结尾。
+
+当指定了编组时,最后的参数
+<code class="computeroutput">at_front</code> 或
+<code class="computeroutput">at_back</code>
+描述的是插槽在组内的次序。
+
+以 <code class="computeroutput">at_front</code> 连接的未分组的插槽将总是在 所有分组的插槽之前。 +以 <code class="computeroutput">at_back</code> 连接的未分组的插槽将总是在所 有分组的插槽之后。
+</p>
+
 <p>
   If we add a new slot to our example like this:
 </p>
+
+<p>
+如果在我们的例子中添加新的插槽,如下:
+</p>
+
 <pre class="programlisting"><code class="computeroutput">struct GoodMorning
 {
   void operator()() const
@@ -277,6 +485,9 @@
   sig();
 </code></pre>
 <p>... we will get the result we wanted:</p>
+
+<p>......我们会得到想要的结果:</p>
+
 <pre class="programlisting">
 Hello, World!
 ... and good morning!
@@ -286,21 +497,48 @@
 <div class="section" lang="en">
 <div class="titlepage"><div><div><h3 class="title">
<a name="id3351941"></a>Passing Values to and from Slots</h3></div></div></div>
+
+<div class="titlepage"><div><div><h3 class="title">
+<a name="id3351941"></a>传值到插槽及回传</h3></div></div></div>
+
 <div class="toc"><dl>
<dt><span class="section"><a href="tutorial.html#id3351946">Slot Arguments (Beginner)</a></span></dt> <dt><span class="section"><a href="tutorial.html#id3352101">Signal Return Values (Advanced)</a></span></dt>
 </dl></div>
+
+<div class="toc"><dl>
+<dt><span class="section"><a href="tutorial.html#id3351946">插槽的参数(初 级)</a></span></dt> +<dt><span class="section"><a href="tutorial.html#id3352101">信号的返回值 (高级)</a></span></dt>
+</dl></div>
+
 <div class="section" lang="en">
 <div class="titlepage"><div><div><h4 class="title">
 <a name="id3351946"></a>Slot Arguments (Beginner)</h4></div></div></div>
+
+<div class="titlepage"><div><div><h4 class="title">
+<a name="id3351946"></a>插槽的参数(初级)</h4></div></div></div>
+
 <p>Signals can propagate arguments to each of the slots they call.
 For instance, a signal that propagates mouse motion events might
 want to pass along the new mouse coordinates and whether the mouse
 buttons are pressed.</p>
+
+<p>信号可以向它们调用的每个插槽传递参数。
+
+例如,一个传递鼠标移动事件的信号可能要传入新的鼠标坐标以及是否按了鼠标键。
+</p>
+
 <p>As an example, we'll create a signal that passes two
<code class="computeroutput">float</code> arguments to its slots. Then we'll create a few
 slots that print the results of various arithmetic operations on
 these values.</p>
+
+<p>例如,我们创建一个信号,它将传入两个
+<code class="computeroutput">float</code> 参数到它的插槽。
+
+然后我们再创建几个插槽,打印对这两个参数进行算术运算的各种结果。
+</p>
+
<pre class="programlisting"><code class="computeroutput">void print_args(float x, float y)
 {
std::cout &lt;&lt; "The arguments are " &lt;&lt; x &lt;&lt; " and " &lt;&lt; y &lt;&lt; std::endl;
@@ -362,6 +600,9 @@
 </tr></tbody>
 </table></div>
 <p>This program will print out the following:</p>
+
+<p>该程序将打印输出如下:</p>
+
 <pre class="programlisting">The arguments are 5 and 3
 The sum is 8
 The product is 15
@@ -375,10 +616,31 @@
return value and takes two <code class="computeroutput">float</code> values. Any slot connected to <code class="computeroutput">sig</code> must therefore be able to take two
 <code class="computeroutput">float</code> values.</p>
+
+<p>
+当像函数一样调用 <code class="computeroutput">sig</code> 时,
+输入它的任何值都传给了每一个插槽。
+
+创建信号时,我们必须预先声明这些值的类型。
+
+类型 <code class="computeroutput"><a class="link" href="../boost/signals2/signal.html" title="Class template signal">boost::signals2::signal</a>&lt;void (float,
+float)&gt;</code> 表明信号具有 <code class="computeroutput">void</code>
+返回值并接受两个 <code class="computeroutput">float</code> 值。
+
+因此任何连接到
+<code class="computeroutput">sig</code>
+的插槽都必须能够接受两个
+<code class="computeroutput">float</code> 值。
+</p>
+
 </div>
 <div class="section" lang="en">
 <div class="titlepage"><div><div><h4 class="title">
<a name="id3352101"></a>Signal Return Values (Advanced)</h4></div></div></div>
+
+<div class="titlepage"><div><div><h4 class="title">
+<a name="id3352101"></a>信号返回值(高级)</h4></div></div></div>
+
 <p>Just as slots can receive arguments, they can also return
 values. These values can then be returned back to the caller of the
signal through a <em class="firstterm">combiner</em>. The combiner is a mechanism
@@ -389,10 +651,30 @@
 slot calls: the result of the last slot call, the maximum value
 returned by any slot, or a container of all of the results are some
 possibilities.</p>
+
+<p>正如插槽可以接收参数,它们也可以返回值。
+
+然后这些值可以通过
+<em class="firstterm">合并器(combiner)</em>
+返回给信号的调用者。
+
+合并器是这样一种工具,它接收插槽调用的结果(可能没有结果,也可能有100个结 果;程序运行时才知道),并且把它们合并成单一的结果返回给调用者。
+
+该单一的结果往往是插槽调用结果的一个简单函数,可能是:最后的插槽调用的结 果、所有插槽返回值的最大值,或包含所有结果的容器。
+</p>
+
 <p>We can modify our previous arithmetic operations example
 slightly so that the slots all return the results of computing the
 product, quotient, sum, or difference. Then the signal itself can
 return a value based on these results to be printed:</p>
+
+<p>
+我们可以稍微修改前面的算术运算的例子,
+使插槽分别返回加减乘除的计算结果。
+
+然后信号本身就可以根据这些结果返回一个值,并打印出来。
+</p>
+
<pre class="programlisting"><code class="computeroutput">float product(float x, float y) { return x * y; }
 float quotient(float x, float y) { return x / y; }
 float sum(float x, float y) { return x + y; }
@@ -434,9 +716,24 @@
 the result returned by the last slot called. This
 behavior is admittedly silly for this example, because slots have
 no side effects and the result is the last slot connected.</p>
+
+<p>该例程将输出 <code class="computeroutput">2</code>。
+这是因为具有返回类型(<code class="computeroutput">float</code>,
+即输入 <code class="computeroutput"><a class="link" href="../boost/signals2/signal.html" title="Class template signal">boost::signals2::signal</a></code>
+类模板的第一个模板参数)的信号的默认行为是,
+调用所有的插槽,然后返回最后一个被调用插槽的结果。
+
+对本例来说,该行为确实有点傻,因为这些插槽没有副作用,所以结果就是最后连接 的插槽。
+</p>
+
 <p>A more interesting signal result would be the maximum of the
 values returned by any slot. To do this, we create a custom
 combiner that looks like this:</p>
+
+<p>求所有插槽返回值的最大值,这样的信号结果才有点意思。
+为此,我们创建一个自定义合并器如下:
+</p>
+
<pre class="programlisting"><code class="computeroutput">// combiner which returns the maximum value returned by all slots
 template&lt;typename T&gt;
 struct maximum
@@ -470,9 +767,36 @@
results of calling all of the slots. <code class="computeroutput">maximum</code> uses this
 input iterator sequence to calculate the maximum element, and
 returns that maximum value.</p>
+
+<p>
+<code class="computeroutput">maximum</code> 类模板就像一个函数对象。
+
+它的结果类型由其模板参数给出,
+并且它正是基于该类型计算最大值
+(例如,<code class="computeroutput">maximum&lt;float&gt;</code>
+将在一系列 <code class="computeroutput">float</code>
+中查找最大的 <code class="computeroutput">float</code>)。
+
+当调用
+<code class="computeroutput">maximum</code> 对象时,
+将给出一个输入迭代器序列
+<code class="computeroutput">[first, last)</code>,
+其中包含了所有插槽调用的结果。
+
+<code class="computeroutput">maximum</code>
+利用该输入迭代器序列来计算最大元素,
+并返回那个最大值。
+</p>
+
 <p>We actually use this new function object type by installing it
 as a combiner for our signal. The combiner template argument
 follows the signal's calling signature:</p>
+
+<p>
+我们要把这个新的函数对象作为合并器安装到我们的信号,才能实际使用它。
+合并器模板参数跟在信号的调用签名式之后。
+</p>
+
 <div class="informaltable"><table class="table">
 <colgroup>
 <col>
@@ -499,6 +823,10 @@
 </table></div>
 <p>Now we can connect slots that perform arithmetic functions and
 use the signal:</p>
+
+<p>现在我们可以连接执行算术功能的插槽并使用信号了:
+</p>
+
<pre class="programlisting"><code class="computeroutput"> sig.connect(&amp;product);
   sig.connect(&amp;quotient);
   sig.connect(&amp;sum);
@@ -512,9 +840,21 @@
 regardless of the order in which the slots are connected, the product
 of 5 and 3 will be larger than the quotient, sum, or
 difference.</p>
+
+<p>该程序的输出为 <code class="computeroutput">15</code>,
+因为不管插槽的连接次序如何,
+5 和 3 的乘积将大于商、和,或差。
+</p>
+
 <p>In other cases we might want to return all of the values
 computed by the slots together, in one large data structure. This
 is easily done with a different combiner:</p>
+
+<p>在其他情况下,我们可能需要同时返回插槽计算的所有值,
+如保存在一个大型的数据结构中。
+用一个不同的合并器就可以轻松做到:
+</p>
+
<pre class="programlisting"><code class="computeroutput">// aggregate_values is a combiner which places all the values returned
 // from slots into a container
 template&lt;typename Container&gt;
@@ -538,6 +878,11 @@
 <p>
 Again, we can create a signal with this new combiner:
 </p>
+
+<p>
+我们再次用这个新的合并器创建信号:
+</p>
+
 <div class="informaltable"><table class="table">
 <colgroup>
 <col>
@@ -580,6 +925,23 @@
 to the combiner. The combiner itself is a function object and its
<code class="computeroutput">result_type</code> member type becomes the return type of the
 signal.</p>
+
+<p>该程序的输出将包含 15、8、1.6667,和 2。
+有趣的是,
+<code class="computeroutput">signal</code>
+类的第一个模板参数,
+<code class="computeroutput">float</code>,
+竟然不是信号的返回类型。
+
+相反,该参数是所连接插槽的返回类型,
+并且它也是传入合并器的输入迭代器的
+<code class="computeroutput">value_type</code>。
+
+合并器本身是个函数对象,并且它的
+<code class="computeroutput">result_type</code>
+成员类型将成为信号的返回类型。
+</p>
+
 <p>The input iterators passed to the combiner transform dereference
 operations into slot calls. Combiners therefore have the option to
 invoke only some slots until some particular criterion is met. For
@@ -593,6 +955,27 @@
the first non-NULL pointer to a <code class="computeroutput">FulfilledRequest</code> data
 structure, without asking any later slots to fulfill the
 request:</p>
+
+<p>
+传给合并器的输入迭代器会将解引用操作转换为插槽调用。
+
+因此合并器可选择仅调用某些符合特定条件的插槽。
+
+例如,在分布计算系统中,合并器可能会询问每个远程系统能否处理请求。
+
+对于一个特定请求,仅需一个远程系统进行处理,
+因此当一个远程系统接受该工作后,
+我们将不再要求任何其他远程系统来做同一个任务。
+
+这样一个合并器只需检查迭代器解引用的返回值,
+并当该值可以接受时就返回。
+
+以下的合并器返回第一个指向
+<code class="computeroutput">FulfilledRequest</code>
+数据结构的非空指针,
+而不必要求任何以后的插槽来完成请求:
+</p>
+
 <pre class="programlisting">
 struct DistributeRequest {
   typedef FulfilledRequest* result_type;
@@ -614,6 +997,10 @@
 <div class="section" lang="en">
 <div class="titlepage"><div><div><h3 class="title">
 <a name="id3352571"></a>Connection Management</h3></div></div></div>
+
+<div class="titlepage"><div><div><h3 class="title">
+<a name="id3352571"></a>连接管理</h3></div></div></div>
+
 <div class="toc"><dl>
<dt><span class="section"><a href="tutorial.html#id3352576">Disconnecting Slots (Beginner)</a></span></dt> <dt><span class="section"><a href="tutorial.html#id3352660">Blocking Slots (Beginner)</a></span></dt>
@@ -624,13 +1011,36 @@
<dt><span class="section"><a href="tutorial.html#id3353362">When Can Disconnections Occur? (Intermediate)</a></span></dt> <dt><span class="section"><a href="tutorial.html#id3353436">Passing Slots (Intermediate)</a></span></dt>
 </dl></div>
+
+<div class="toc"><dl>
+<dt><span class="section"><a href="tutorial.html#id3352576">断开插槽(初级 )</a></span></dt> +<dt><span class="section"><a href="tutorial.html#id3352660">阻塞插槽(初级 )</a></span></dt> +<dt><span class="section"><a href="tutorial.html#id3352717">域内连接(中级 )</a></span></dt> +<dt><span class="section"><a href="tutorial.html#id3352816">断开等价的插槽 (中级)</a></span></dt> +<dt><span class="section"><a href="tutorial.html#signals2.tutorial.connection-management">自动连接管理 (中级)</a></span></dt> +<dt><span class="section"><a href="tutorial.html#signals2.tutorial.deconstruct">Postconstructor 和 Predestructor (高级)</a></span></dt> +<dt><span class="section"><a href="tutorial.html#id3353362">何时断开?(中 级)</a></span></dt> +<dt><span class="section"><a href="tutorial.html#id3353436">传递插槽(中级 )</a></span></dt>
+</dl></div>
+
 <div class="section" lang="en">
 <div class="titlepage"><div><div><h4 class="title">
<a name="id3352576"></a>Disconnecting Slots (Beginner)</h4></div></div></div>
+
+<div class="titlepage"><div><div><h4 class="title">
+<a name="id3352576"></a>断开插槽(初级)</h4></div></div></div>
+
 <p>Slots aren't expected to exist indefinitely after they are
 connected. Often slots are only used to receive a few events and
 are then disconnected, and the programmer needs control to decide
 when a slot should no longer be connected.</p>
+
+<p>插槽在连接之后不必无限期地存在。
+插槽往往只是用来接收一些事件然后断开,
+当插槽不再需要保持连接时,
+程序员可以做出决定并控制。
+</p>
+
 <p>The entry point for managing connections explicitly is the
<code class="computeroutput"><a class="link" href="../boost/signals2/connection.html" title="Class connection">boost::signals2::connection</a></code> class. The <code class="computeroutput"><a class="link" href="../boost/signals2/connection.html" title="Class connection">connection</a></code> class uniquely represents the connection
@@ -641,6 +1051,27 @@
called. Each call to the signal's <code class="computeroutput">connect()</code> method
 returns a connection object, which can be used to determine if the
 connection still exists or to disconnect the signal and slot.</p>
+
+<p>
+显式管理连接的入口点是
+<code class="computeroutput"><a class="link" href="../boost/signals2/connection.html" title="Class connection">boost::signals2::connection</a></code> 类。
+
+<code class="computeroutput"><a class="link" href="../boost/signals2/connection.html" title="Class connection">connection</a></code>
+类唯一代表了特定信号与特定插槽之间的连接。
+
+<code class="computeroutput"><a class="link" href="../boost/signals2/connection.html#id1186298-bb">connected</a>()</code>
+方法检查信号与插槽是否仍保持连接,
+
+如果信号与插槽是连接着的,
+<code class="computeroutput"><a class="link" href="../boost/signals2/connection.html#id1278410-bb">disconnect()</a></code>
+方法断开它们的连接。
+
+每次调用信号的 <code class="computeroutput">connect()</code>
+方法,就返回一个连接对象,
+该对象用于确定连接是否仍然存在,
+或者用于断开信号和插槽。
+</p>
+
<pre class="programlisting"><code class="computeroutput"> boost::signals2::connection c = sig.connect(HelloWorld());
   std::cout &lt;&lt; "c is connected\n";
   sig(); // Prints "Hello, World!"
@@ -653,6 +1084,10 @@
 <div class="section" lang="en">
 <div class="titlepage"><div><div><h4 class="title">
 <a name="id3352660"></a>Blocking Slots (Beginner)</h4></div></div></div>
+
+<div class="titlepage"><div><div><h4 class="title">
+<a name="id3352660"></a>阻塞插槽(初级)</h4></div></div></div>
+
 <p>Slots can be temporarily "blocked", meaning that they will be
ignored when the signal is invoked but have not been permanently disconnected.
 This is typically used to prevent infinite recursion in cases where
@@ -666,6 +1101,22 @@
<code class="computeroutput">shared_connection_block</code> objects that reference the connection.
 Here is an example of
 blocking/unblocking slots:</p>
+
+<p>
+插槽可以被临时"阻塞",即当信号被调用时,这些插槽将被忽略,但并没有被永久地 断开。
+这主要用于防止无限递归,
+如有时,要没有阻塞,插槽运行时会再次调用它所连接的信号。
+
+<code class="computeroutput"><a class="link" href="../boost/signals2/shared_connection_block.html" title="Class shared_connection_block">boost::signals2::shared_connection_block</a></code>
+对象会临时阻塞插槽。
+
+要解除阻塞,需要销毁所有引用该连接的
+<code class="computeroutput">shared_connection_block</code>
+对象,或者调用它们的
+<code class="computeroutput"><a class="link" href="../boost/signals2/shared_connection_block.html#id1183652-bb">unblock</a></code>。
+
+以下是阻塞插槽和解除的例子:</p>
+
<pre class="programlisting"><code class="computeroutput"> boost::signals2::connection c = sig.connect(HelloWorld());
   std::cout &lt;&lt; "c is not blocked.\n";
   sig(); // Prints "Hello, World!"
@@ -682,11 +1133,25 @@
 <div class="section" lang="en">
 <div class="titlepage"><div><div><h4 class="title">
<a name="id3352717"></a>Scoped Connections (Intermediate)</h4></div></div></div>
+
+<div class="titlepage"><div><div><h4 class="title">
+<a name="id3352717"></a>域内连接(中级)</h4></div></div></div>
+
<p>The <code class="computeroutput"><a class="link" href="../boost/signals2/scoped_connection.html" title="Class scoped_connection">boost::signals2::scoped_connection</a></code> class
 references a signal/slot connection that will be disconnected when
the <code class="computeroutput">scoped_connection</code> class goes out of scope. This
 ability is useful when a connection need only be temporary,
 e.g.,</p>
+
+<p>
+<code class="computeroutput"><a class="link" href="../boost/signals2/scoped_connection.html" title="Class scoped_connection">boost::signals2::scoped_connection</a></code>
+类引用了一个信号/插槽的连接,当
+<code class="computeroutput">scoped_connection</code>
+类出作用域时,该连接将会被断开。
+
+当仅需临时连接时,该功能很有用,如:
+</p>
+
 <pre class="programlisting"><code class="computeroutput">  {
     boost::signals2::scoped_connection c(sig.connect(ShortLived()));
     sig(); // will call ShortLived function object
@@ -700,6 +1165,16 @@
or default construction followed by assignment from a <code class="computeroutput"><a class="link" href="../boost/signals2/connection.html" title="Class connection">connection</a></code>
   will work:
 </p>
+
+<p>
+  注意,试图用赋值语句初始化 scoped_connection
+  会失败,因为它是不可拷贝的(noncopyable)。
+  应该使用显式初始化,
+  或者缺省构造然后用
+ <code class="computeroutput"><a class="link" href="../boost/signals2/connection.html" title="Class connection">connection</a></code>
+  对它赋值:
+</p>
+
 <pre class="programlisting">
// doesn't compile due to compiler attempting to copy a temporary scoped_connection object // boost::signals2::scoped_connection c0 = sig.<code class="computeroutput"><a class="link" href="../boost/signals2/signalN.html#id1284885-bb">connect</a></code>(ShortLived());
@@ -715,6 +1190,10 @@
 <div class="section" lang="en">
 <div class="titlepage"><div><div><h4 class="title">
<a name="id3352816"></a>Disconnecting Equivalent Slots (Intermediate)</h4></div></div></div>
+
+<div class="titlepage"><div><div><h4 class="title">
+<a name="id3352816"></a>断开等价的插槽(中级)</h4></div></div></div>
+
 <p>One can disconnect slots that are equivalent to a given function
 object using a form of the
<code class="computeroutput"><a class="link" href="../boost/signalN.html#id1242363-bb">signal::disconnect</a></code> method, so long as
@@ -722,6 +1201,15 @@
 operator. For instance:

 </p>
+
+<p>你可以使用
+<code class="computeroutput"><a class="link" href="../boost/signalN.html#id1242363-bb">signal::disconnect</a></code>
+方法断开与给定函数对象等价的多个插槽,
+只要该函数对象的类型具有可访问的
+<code class="computeroutput">==</code>
+运算符。例如:
+</p>
+
<pre class="programlisting"><code class="computeroutput">void foo() { std::cout &lt;&lt; "foo"; }
 void bar() { std::cout &lt;&lt; "bar\n"; }
 </code></pre>
@@ -755,6 +1243,10 @@
 <div class="section" lang="en">
 <div class="titlepage"><div><div><h4 class="title">
<a name="signals2.tutorial.connection-management"></a>Automatic Connection Management (Intermediate)</h4></div></div></div>
+
+<div class="titlepage"><div><div><h4 class="title">
+<a name="signals2.tutorial.connection-management"></a>自动连接管理(中级 )</h4></div></div></div>
+
 <p>Boost.Signals2 can automatically track the lifetime of objects
 involved in signal/slot connections, including automatic
 disconnection of slots when objects involved in the slot call are
@@ -762,6 +1254,17 @@
 where clients connect to a news provider that then sends news to
 all connected clients as information arrives. The news delivery
 service may be constructed like this: </p>
+
+<p>
+Boost.Signals2 能自动跟踪信号/插槽连接中所涉及对象的生命期,
+包括当插槽调用中涉及的对象销毁时自动断开插槽。
+
+例如,考虑一个简单的新闻发送服务,
+其中客户会连接到新闻提供者,
+而新闻提供者一有信息到达,就发送新闻到所有连接的客户。
+该新闻发送服务可能像这样构造:
+</p>
+
 <div class="informaltable"><table class="table">
 <colgroup>
 <col>
@@ -795,6 +1298,14 @@
<code class="computeroutput">deliverNews</code> signal. For instance, we may have a
 special message area in our application specifically for news,
 e.g.,:</p>
+
+<p>
+希望接收新闻更新的客户只需连接一个函数对象,
+该对象可以接收传给
+<code class="computeroutput">deliverNews</code>
+信号的新闻条目,例如:
+</p>
+
 <pre class="programlisting">
 struct NewsMessageArea : public MessageArea
 {
@@ -829,6 +1340,36 @@
<code class="computeroutput"><a class="link" href="../boost/signals2/slotN.html#id1187184-bb">slot::track</a></code>
 method before connecting it,
 e.g.:</p>
+
+<p>不过,如果用户关闭新闻讯息区,
+销毁了 <code class="computeroutput">deliverNews</code>
+所知的 <code class="computeroutput">newsMessageArea</code> 对象,
+那会怎么样?
+
+最有可能的是产生段错误。
+
+然而,在Boost.Signals2中,使用
+<code class="computeroutput"><a class="link" href="../boost/signals2/slotN.html#id1187184-bb">slot::track</a></code>,
+你可以跟踪由 shared_ptr 管理的任何对象,
+
+当插槽的任一个被跟踪对象失效时,插槽会自动断开。
+
+另外,当插槽正在执行时,
+Boost.Signals2 会保证它所关联的被跟踪对象不会失效。
+
+为此,插槽在执行前会创建被跟踪对象的临时 shared_ptr 副本。
+
+为了跟踪 <code class="computeroutput">NewsMessageArea</code>,
+我们用 shared_ptr 管理其生命期,
+并在连接它之前,
+通过其
+<code class="computeroutput"><a class="link" href="../boost/signals2/slotN.html#id1187184-bb">slot::track</a></code>
+方法,
+把 shared_ptr 传给插槽。
+
+例如:
+</p>
+
 <pre class="programlisting">
 // ...
boost::shared_ptr&lt;NewsMessageArea&gt; newsMessageArea(new NewsMessageArea(/* ... */));
@@ -842,6 +1383,17 @@
argument, it will automatically pass all the arguments to <code class="computeroutput">bind</code> and use the
   returned function object.
 </p>
+
+<p>
+  注意上例中不需要显式调用 bind()。
+  如果
+ <code class="computeroutput"><a class="link" href="../boost/signals2/slotN.html" title="Class template slotN">slot</a></code>
+  构造函数传入一个以上的参数,
+  它会自动将所有参数传给
+  <code class="computeroutput">bind</code>,
+  并使用返回的函数对象。
+</p>
+
 <p>Also note, we pass an ordinary pointer as the
second argument to the slot constructor, using <code class="computeroutput">newsMessageArea.get()</code> instead of passing the <code class="computeroutput">shared_ptr</code> itself. If we had passed the
@@ -852,10 +1404,30 @@
   implies we wish to allow the tracked object to expire, and automatically
   disconnect the connection when this occurs.
 </p>
+
+<p>还要注意插槽构造函数的第2个参数,
+  我们使用 <code class="computeroutput">newsMessageArea.get()</code>,
+  传入了一个普通指针,
+  而不是 <code class="computeroutput">shared_ptr</code> 本身。
+
+  如果传入 <code class="computeroutput">newsMessageArea</code> 本身,
+  插槽函数将绑定一个 <code class="computeroutput">shared_ptr</code> 副本,
+  从而妨碍了 <code class="computeroutput">shared_ptr</code> 的失效。
+
+  然而,使用
+ <code class="computeroutput"><a class="link" href="../boost/signals2/slotN.html#id1187184-bb">slot::track</a></code>
+  意味着我们希望允许被跟踪对象失效,
+  并且当它发生时自动断开连接。
+</p>
+
 </div>
 <div class="section" lang="en">
 <div class="titlepage"><div><div><h4 class="title">
<a name="signals2.tutorial.deconstruct"></a>Postconstructors and Predestructors (Advanced)</h4></div></div></div>
+
+<div class="titlepage"><div><div><h4 class="title">
+<a name="signals2.tutorial.deconstruct"></a>Postconstructor 和 Predestructor (高级)</h4></div></div></div>
+
<p>One limitation of using <code class="computeroutput">shared_ptr</code> for tracking is that an object cannot setup tracking of itself in its constructor. However, it is possible to set up tracking in a post-constructor which is called after the
@@ -864,6 +1436,21 @@
       library provides support for post-constructors and pre-destructors
via the <code class="computeroutput"><a class="link" href="../boost/signals2/deconstruct.html" title="Function deconstruct">deconstruct()</a></code> factory function.
     </p>
+
+<p>利用 <code class="computeroutput">shared_ptr</code> 跟踪有一个限制:
+      对象不能在其构造函数中建立对自身的跟踪。
+
+      然而,可以在 post-constructor 中建立跟踪,
+      它会在对象创建并传给
+      <code class="computeroutput">shared_ptr</code>
+      之后被调用。
+
+      Boost.Signals2 库通过
+ <code class="computeroutput"><a class="link" href="../boost/signals2/deconstruct.html" title="Function deconstruct">deconstruct()</a></code>
+      工厂方法,
+      对 post-constructor 和 pre-destructor 提供了支持。
+    </p>
+
 <p>
For most cases, the simplest and most robust way to setup postconstructors for a class is to define an associated <code class="computeroutput">adl_postconstruct</code> function
@@ -874,11 +1461,44 @@
through the <code class="computeroutput"><a class="link" href="../boost/signals2/deconstruct.html" title="Function deconstruct">deconstruct()</a></code> function, and their associated <code class="computeroutput">adl_postconstruct()</code> function will always be called.
     </p>
+
+<p>
+      在多数情况下,
+      为类建立 postconstructor 最简单最可靠的方法是:
+      定义一个相关的
+      <code class="computeroutput">adl_postconstruct</code> 函数,
+      让它可以被
+ <code class="computeroutput"><a class="link" href="../boost/signals2/deconstruct.html" title="Function deconstruct">deconstruct()</a></code>
+      找到,
+      让类的构造函数为私有的,
+      并通过声明
+ <code class="computeroutput"><a class="link" href="../boost/signals2/deconstruct_access.html" title="Class deconstruct_access">deconstruct_access</a></code>
+      为友元,
+ 让 <code class="computeroutput"><a class="link" href="../boost/signals2/deconstruct.html" title="Function deconstruct">deconstruct</a></code>
+      可以访问私有的构造函数。
+
+      这将保证类的对象只能通过
+ <code class="computeroutput"><a class="link" href="../boost/signals2/deconstruct.html" title="Function deconstruct">deconstruct()</a></code>
+      函数创建,
+      而它们相关的
+      <code class="computeroutput">adl_postconstruct()</code>
+      函数总是会被调用。
+    </p>
+
<p>The <a class="link" href="examples.html#signals2.examples.deconstruct" title="Postconstructors and Predestructors with deconstruct()">examples</a> section contains several examples of defining classes with postconstructors and
       predestructors, and creating objects of these classes using
<code class="computeroutput"><a class="link" href="../boost/signals2/deconstruct.html" title="Function deconstruct">deconstruct()</a></code>
     </p>
+
+<p><a class="link" href="examples.html#signals2.examples.deconstruct" title="Postconstructors and Predestructors with deconstruct()">例程</a>
+         一节中有几个例子,
+         它们用 postconstructor 和 predestructor 定义类,
+      并用
+ <code class="computeroutput"><a class="link" href="../boost/signals2/deconstruct.html" title="Function deconstruct">deconstruct()</a></code>
+      创建这些类的对象。
+    </p>
+
 <p>
Be aware that the postconstructor/predestructor support in Boost.Signals2
       is in no way essential to the use of the library.  The use of
@@ -889,20 +1509,65 @@
a <code class="computeroutput">shared_ptr</code>, setup tracking for the object,
       then return the <code class="computeroutput">shared_ptr</code>.
     </p>
+
+<p>
+      注意,Boost.Signals2 中对 postconstructor/predestructor
+      的支持对于库的使用并非是必须的。
+
+ <code class="computeroutput"><a class="link" href="../boost/signals2/deconstruct.html" title="Function deconstruct">deconstruct</a></code>
+      的使用完全是可选的。
+
+      另一选择是为你的类定义静态工厂函数。
+
+      该工厂函数可以创建对象,传递对象所有权到
+      <code class="computeroutput">shared_ptr</code>,
+      为对象建立跟踪,
+      然后返回 <code class="computeroutput">shared_ptr</code>。
+    </p>
+
 </div>
 <div class="section" lang="en">
 <div class="titlepage"><div><div><h4 class="title">
<a name="id3353362"></a>When Can Disconnections Occur? (Intermediate)</h4></div></div></div>
+
+<div class="titlepage"><div><div><h4 class="title">
+<a name="id3353362"></a>何时断开?(中级)</h4></div></div></div>
+
 <p>Signal/slot disconnections occur when any of these conditions
 occur:</p>
+
+<p>
+以下任一条件发生时,信号/插槽将断开:
+</p>
+
 <div class="itemizedlist"><ul type="disc">
 <li><p>The connection is explicitly disconnected via the connection's
<code class="computeroutput">disconnect</code> method directly, or indirectly via the
 signal's <code class="computeroutput">disconnect</code> method, or
-<code class="computeroutput">scoped_connection</code>'s destructor.</p></li>
+<code class="computeroutput">scoped_connection</code>'s destructor.</p>
+
+<p>连接被显式地断开:
+直接通过连接的
+<code class="computeroutput">disconnect</code> 方法,
+或间接地通过信号的
+<code class="computeroutput">disconnect</code> 方法,
+或
+<code class="computeroutput">scoped_connection</code>
+的析构函数。
+</p>
+
+</li>
 <li><p>An object tracked by the slot is
-destroyed.</p></li>
-<li><p>The signal is destroyed.</p></li>
+destroyed.</p>
+
+<P>插槽所跟踪的对象被销毁。</P>
+
+</li>
+<li><p>The signal is destroyed.</p>
+
+<p>信号被销毁。</p>
+
+</li>
 </ul></div>
 <p>These events can occur at any time without disrupting a signal's
 calling sequence. If a signal/slot connection is disconnected at
@@ -911,11 +1576,28 @@
 Additionally, a signal may be destroyed while it is in a calling
 sequence, and which case it will complete its slot call sequence
 but may not be accessed directly.</p>
+
+<p>这些事件可以发生于任何时间,而不会破坏信号的调用序列。
+
+如果信号/插槽的连接在信号调用序列的任意时刻被断开,
+调用序列仍将继续,只是不会调用被断开的插槽。
+
+此外,信号可以在调用序列中间被销毁,这时,它将完成其插槽调用序列,
+只是不可以被直接访问。
+</p>
+
 <p>Signals may be invoked recursively (e.g., a signal A calls a
 slot B that invokes signal A...). The disconnection behavior does
 not change in the recursive case, except that the slot calling
 sequence includes slot calls for all nested invocations of the
 signal.</p>
+
+<p>信号可以被递归调用(例如,信号A调用插槽B,而插槽B又调用信号A......)。
+
+递归情况下,断开的行为不会改变,
+只是插槽调用序列包括所有嵌套的信号调用。
+</p>
+
 <p>
   Note, even after a connection is disconnected, its's associated slot
   may still be in the process of executing.  In other words, disconnection
@@ -924,10 +1606,26 @@
   disconnection occurs concurrently with signal invocation,
   or in a single-threaded environment if a slot disconnects itself.
 </p>
+
+<p>
+  注意,即使在连接断开后,
+  其相关的插槽可能仍处于执行中。
+
+  也就是说,断开连接不会停止等待连接相关的插槽完成执行。
+
+  该情形可以发生在多线程环境下,
+  如断开连接与信号调用并行发生,
+  或者在单线程环境下,如插槽断开自身。
+</p>
+
 </div>
 <div class="section" lang="en">
 <div class="titlepage"><div><div><h4 class="title">
 <a name="id3353436"></a>Passing Slots (Intermediate)</h4></div></div></div>
+
+<div class="titlepage"><div><div><h4 class="title">
+<a name="id3353436"></a>传递插槽(中级)</h4></div></div></div>
+
 <p>Slots in the Boost.Signals2 library are created from arbitrary
 function objects, and therefore have no fixed type. However, it is
 commonplace to require that slots be passed through interfaces that
@@ -935,6 +1633,22 @@
<code class="computeroutput">slot_type</code> for each particular signal type and any
 function object compatible with the signature of the signal can be
passed to a <code class="computeroutput">slot_type</code> parameter. For instance:</p>
+
+<p>Boost.Signals2 库中的插槽可以从任意的函数对象创建,因此没有固定的类型。
+
+不过通常要求通过不可模板化的接口传递插槽。
+
+对于每个特定的信号类型,
+都可以通过
+<code class="computeroutput">slot_type</code>
+传递插槽,
+
+而与信号的签名式兼容的任意函数对象,
+都可以传给 <code class="computeroutput">slot_type</code> 参数。
+
+例如:
+</p>
+
<pre class="programlisting"><code class="computeroutput">// a pretend GUI button
 class Button
 {
@@ -974,17 +1688,40 @@
to the <code class="computeroutput">connect</code> method of the <code class="computeroutput">onClick</code> signal, but the details of the <code class="computeroutput">doOnClick</code> method can be
 hidden in an implementation detail file.</p>
+
+<p><code class="computeroutput">doOnClick</code> 方法现在功能上等效于
+<code class="computeroutput">onClick</code> 信号的
+<code class="computeroutput">connect</code> 方法,
+但是 <code class="computeroutput">doOnClick</code>
+方法的细节可以隐藏于细节实现文件中。
+</p>
+
 </div>
 </div>
 <div class="section" lang="en">
 <div class="titlepage"><div><div><h3 class="title">
<a name="signals2.tutorial.document-view"></a>Example: Document-View</h3></div></div></div>
+
+<div class="titlepage"><div><div><h3 class="title">
+<a name="signals2.tutorial.document-view"></a>例子:文档-视图 </h3></div></div></div>
+
 <p>Signals can be used to implement flexible Document-View
   architectures. The document will contain a signal to which each of
the views can connect. The following <code class="computeroutput">Document</code> class
   defines a simple text document that supports mulitple views. Note
   that it stores a single signal to which all of the views will be
   connected.</p>
+
+<p>信号可用于实现灵活的文档-视图(Document-View)架构。
+
+  文档包含一个信号,而每个视图连接该信号。
+
+  下面的 <code class="computeroutput">Document</code>
+  类定义了一个简单的支持多视图的文本文档。
+
+  注意它保存了一个单一的信号,所有视图都连接到该信号。
+  </p>
+
 <pre class="programlisting"><code class="computeroutput">class Document
 {
 public:
@@ -1022,6 +1759,13 @@
following <code class="computeroutput">TextView</code> class provides a simple view of the
     document text.
   </p>
+
+<p>
+    接下来,我们可以开始定义视图。
+    以下 <code class="computeroutput">TextView</code>
+    类是对文档文本的一个简单视图。
+  </p>
+
 <pre class="programlisting"><code class="computeroutput">class TextView
 {
 public:
@@ -1047,6 +1791,11 @@
 <p>Alternatively, we can provide a view of the document
translated into hex values using the <code class="computeroutput">HexView</code>
     view:</p>
+
+<p>此外,我们可以提供文档翻译成16进制后的视图,
+    如 <code class="computeroutput">HexView</code> 视图:
+    </p>
+
 <pre class="programlisting"><code class="computeroutput">class HexView
 {
 public:
@@ -1081,6 +1830,14 @@
simple <code class="computeroutput">main</code> function that sets up two views and then
     modifies the document:
   </p>
+
+<p>
+    为了把例子串起来,
+    有个简单的
+    <code class="computeroutput">main</code>
+    函数,它建立了两个视图,然后更改文档:
+  </p>
+
<pre class="programlisting"><code class="computeroutput">int main(int argc, char* argv[])
 {
     Document    doc;
@@ -1096,6 +1853,15 @@
We also provide variations on the program which employ automatic connection management
     to disconnect views on their destruction.
   </p>
+
+<p>完整的例程源码,由 Keith MacDonald 提供,在
+ <a class="link" href="examples.html#signals2.examples.document-view" title="Document-View">例程</a>一节中。
+
+    同时我们提供了该程序的更改版,
+    它们使用了自动连接管理,
+    能在视图析构时断开视图。
+  </p>
+
 </div>
 <div class="section" lang="en">
 <div class="titlepage"><div><div><h3 class="title">
@@ -1177,15 +1943,25 @@
 <div class="section" lang="en">
 <div class="titlepage"><div><div><h3 class="title">
<a name="id3353969"></a>Linking against the Signals2 library</h3></div></div></div> -<p>Unlike the original Boost.Signals library, Boost.Signals2 is currently header-only.
+
+<div class="titlepage"><div><div><h3 class="title">
+<a name="id3353969"></a>链接 Signals2 库</h3></div></div></div>
+
+<p>与原 Boost.Signals 库不同,Boost.Signals2 现在是纯头文件的。
     </p>
 </div>
 </div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"; width="100%"><tr> <td align="left"><p><small>Last revised: June 12, 2007 at 14:01:23 -0400</small></p></td> -<td align="right"><div class="copyright-footer">Copyright 2001-2004 Douglas Gregor<br>Copyright 2007-2009 Frank Mori Hess<p>Distributed under the Boost +<td align="right"><div class="copyright-footer">Copyright (c) 2001-2004 Douglas Gregor<br>Copyright (c) 2007-2009 Frank Mori Hess
+
+      <p>翻译:<a href="http://blog.csdn.net/jq0123";>金庆</a></p>
+      <p>译文更新:2009.6.5</p>
+
+    <p>Distributed under the Boost
     Software License, Version 1.0. (See accompanying file
<code class="filename">LICENSE_1_0.txt</code> or copy at <a href="http://www.boost.org/LICENSE_1_0.txt"; target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)</p>
+
 </div></td>
 </tr></table>
 <hr>

Other related posts:

  • » [boost-doc-zh commit] r261 - Signals2教程(还差最后两小节). 同时更新Signal教程. - codesite-noreply