slot.xml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!DOCTYPE header PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
  3. "http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
  4. <!--
  5. Copyright Douglas Gregor 2001-2004
  6. Copyright Frank Mori Hess 2007-2009
  7. Distributed under the Boost Software License, Version 1.0. (See accompanying
  8. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. -->
  10. <header name="boost/signals2/slot.hpp" last-revision="$Date: 2007-03-06 16:51:55 -0500 (Tue, 06 Mar 2007) $">
  11. <using-namespace name="boost::signals2"/>
  12. <using-namespace name="boost"/>
  13. <using-class name="boost::signals2::signal"/>
  14. <using-class name="boost::signals2::slot_base"/>
  15. <namespace name="boost">
  16. <namespace name="signals2">
  17. <class name="slot">
  18. <template>
  19. <template-type-parameter name="Signature">
  20. <purpose>Function type R (T1, T2, ..., TN)</purpose>
  21. </template-type-parameter>
  22. <template-type-parameter name="SlotFunction">
  23. <default><classname>boost::function</classname>&lt;R (T1, T2, ..., TN)&gt;</default>
  24. </template-type-parameter>
  25. </template>
  26. <inherit access="public">
  27. <type><classname>boost::signals2::slot_base</classname></type>
  28. </inherit>
  29. <purpose>Pass slots as function arguments, and associate tracked objects with a slot.</purpose>
  30. <description>
  31. <para>A slot consists of a polymorphic function wrapper (<classname>boost::function</classname> by default)
  32. plus a container of <code>weak_ptr</code>s which identify the slot's "tracked objects". If any of the
  33. tracked objects expire, the slot will automatically disable itself. That is, the slot's function
  34. call operator will throw an exception instead of forwarding the function call to the slot's
  35. polymorphic function wrapper. Additionally, a slot will automatically lock all the tracked objects
  36. as <code>shared_ptr</code> during invocation, to prevent any of them from expiring while
  37. the polymorphic function wrapper is being run.
  38. </para>
  39. <para>
  40. The slot constructor will search for <classname>signals2::signal</classname> and
  41. <classname>signals2::trackable</classname> inside incoming function objects and
  42. automatically track them. It does so by applying a visitor
  43. to the incoming functors with <functionname>boost::visit_each</functionname>.
  44. </para>
  45. </description>
  46. <typedef name="result_type">
  47. <type>R</type>
  48. </typedef>
  49. <typedef name="argument_type">
  50. <type>T1</type>
  51. <purpose>Exists iff arity == 1</purpose>
  52. </typedef>
  53. <typedef name="first_argument_type">
  54. <type>T1</type>
  55. <purpose>Exists iff arity == 2</purpose>
  56. </typedef>
  57. <typedef name="second_argument_type">
  58. <type>T2</type>
  59. <purpose>Exists iff arity == 2</purpose>
  60. </typedef>
  61. <typedef name="signature_type">
  62. <type>Signature</type>
  63. </typedef>
  64. <typedef name="slot_function_type">
  65. <type>SlotFunction</type>
  66. </typedef>
  67. <class name="arg">
  68. <template>
  69. <template-nontype-parameter name="n">
  70. <type>unsigned</type>
  71. </template-nontype-parameter>
  72. </template>
  73. <typedef name="type">
  74. <type>Tn</type>
  75. <purpose>The type of the <classname alt="signals2::slot">slot</classname>'s (n+1)th argument</purpose>
  76. </typedef>
  77. </class>
  78. <static-constant name="arity">
  79. <type>int</type>
  80. <default>N</default>
  81. <purpose>The number of arguments taken by the slot.</purpose>
  82. </static-constant>
  83. <constructor>
  84. <template>
  85. <template-type-parameter name="Slot"/>
  86. </template>
  87. <parameter name="target">
  88. <paramtype>const Slot &amp;</paramtype>
  89. </parameter>
  90. <effects>
  91. <para>Initializes the <code>SlotFunction</code> object in <code>this</code>
  92. with <code>target</code>, which may be any
  93. function object with which a
  94. <code>SlotFunction</code> can be
  95. constructed.
  96. </para>
  97. <para>In this special case where the template type parameter <code>Slot</code> is
  98. a compatible <classname>signals2::signal</classname> type,
  99. the signal will automatically be added to the slot's tracked object list.
  100. Otherwise, the slot's tracked object list is initially empty.
  101. </para>
  102. </effects>
  103. </constructor>
  104. <constructor>
  105. <template>
  106. <template-type-parameter name="OtherSignature"/>
  107. <template-type-parameter name="OtherSlotFunction"/>
  108. </template>
  109. <parameter name="other_slot">
  110. <paramtype>const slot&lt;OtherSignature, OtherSlotFunction&gt; &amp;</paramtype>
  111. </parameter>
  112. <effects>
  113. <para>Initializes <code>this</code> with a copy of
  114. <code>other_slot</code>'s <code>OtherSlotFunction</code> object and tracked object list.
  115. </para></effects>
  116. </constructor>
  117. <constructor>
  118. <template>
  119. <template-type-parameter name="Func"/>
  120. <template-type-parameter name="Arg1"/>
  121. <template-type-parameter name="Arg2"/>
  122. <template-varargs/>
  123. <template-type-parameter name="ArgN"/>
  124. </template>
  125. <parameter name="f">
  126. <paramtype>const Func &amp;</paramtype>
  127. </parameter>
  128. <parameter name="a1">
  129. <paramtype>const Arg1 &amp;</paramtype>
  130. </parameter>
  131. <parameter name="a2">
  132. <paramtype>const Arg2 &amp;</paramtype>
  133. </parameter>
  134. <parameter>
  135. <paramtype>...</paramtype>
  136. </parameter>
  137. <parameter name="aN">
  138. <paramtype>const ArgN &amp;</paramtype>
  139. </parameter>
  140. <effects>
  141. <para>Syntactic sugar for <code>bind()</code> when the constructor is passed more than
  142. one argument. As if:
  143. <code>slot(boost::bind(f, a1, a2, ..., aN))</code>
  144. </para></effects>
  145. </constructor>
  146. <method-group name="invocation">
  147. <overloaded-method name="operator()">
  148. <signature>
  149. <type>result_type</type>
  150. <parameter name="a1"><paramtype>arg&lt;0&gt;::type</paramtype></parameter>
  151. <parameter name="a2"><paramtype>arg&lt;1&gt;::_type</paramtype></parameter>
  152. <parameter><paramtype>...</paramtype></parameter>
  153. <parameter name="aN"><paramtype>arg&lt;N-1&gt;::type</paramtype></parameter>
  154. </signature>
  155. <signature cv="const">
  156. <type>result_type</type>
  157. <parameter name="a1"><paramtype>arg&lt;0&gt;::type</paramtype></parameter>
  158. <parameter name="a2"><paramtype>arg&lt;1&gt;::_type</paramtype></parameter>
  159. <parameter><paramtype>...</paramtype></parameter>
  160. <parameter name="aN"><paramtype>arg&lt;N-1&gt;::type</paramtype></parameter>
  161. </signature>
  162. <effects><para>Calls the slot's <code>SlotFunction</code> object.
  163. </para></effects>
  164. <returns><para>The result returned by the slot's <code>SlotFunction</code> object.</para></returns>
  165. <throws><para>Any exceptions thrown by the slot's <code>SlotFunction</code> object.
  166. <classname>boost::signals2::expired_slot</classname> if any object in the tracked object list
  167. has expired.</para></throws>
  168. <notes><para>If you have already used <methodname>lock</methodname> to insure the
  169. tracked objects are valid, it is slightly more efficient to use the
  170. <methodname>slot_function</methodname>() method
  171. and call the slot's <code>SlotFunction</code> directly.</para>
  172. </notes>
  173. </overloaded-method>
  174. </method-group>
  175. <method-group name="tracking">
  176. <overloaded-method name="track">
  177. <signature>
  178. <type>slot &amp;</type>
  179. <parameter name="tracked_object">
  180. <paramtype>const weak_ptr&lt;void&gt; &amp;</paramtype>
  181. </parameter>
  182. </signature>
  183. <signature>
  184. <type>slot &amp;</type>
  185. <parameter name="tracked_signal">
  186. <paramtype>const <classname>signals2::signal_base</classname> &amp;</paramtype>
  187. </parameter>
  188. </signature>
  189. <signature>
  190. <type>slot &amp;</type>
  191. <parameter name="tracked_slot">
  192. <paramtype>const <classname>signals2::slot_base</classname> &amp;</paramtype>
  193. </parameter>
  194. </signature>
  195. <effects>
  196. <para>
  197. Adds object(s) to the slot's tracked object list. Should any of the
  198. tracked objects expire, then subsequent attempts to call the slot's <code>operator()</code>
  199. or <code>lock()</code> methods will throw an <classname>signals2::expired_slot</classname> exception.
  200. </para>
  201. <para>When tracking a signal, a <classname>shared_ptr</classname>
  202. internal to the signal class is used for tracking. The signal does not
  203. need to be owned by an external <code>shared_ptr</code>.
  204. </para>
  205. <para>
  206. In the case of passing another slot as the argument to <code>track()</code>,
  207. only the objects currently in the other slot's tracked object list are added
  208. to the tracked object list of <code>this</code>. The other slot object itself
  209. is not tracked.
  210. </para>
  211. </effects>
  212. <returns><para><code>*this</code></para></returns>
  213. </overloaded-method>
  214. <overloaded-method name="track_foreign">
  215. <signature>
  216. <template>
  217. <template-type-parameter name="ForeignWeakPtr"/>
  218. </template>
  219. <type>slot &amp;</type>
  220. <parameter name="tracked_object">
  221. <paramtype>const ForeignWeakPtr &amp;</paramtype>
  222. </parameter>
  223. <parameter name="SFINAE">
  224. <paramtype>typename weak_ptr_traits&lt;ForeignWeakPtr&gt;::shared_type *</paramtype>
  225. <default>0</default>
  226. </parameter>
  227. </signature>
  228. <signature>
  229. <template>
  230. <template-type-parameter name="ForeignSharedPtr"/>
  231. </template>
  232. <type>slot &amp;</type>
  233. <parameter name="tracked_object">
  234. <paramtype>const ForeignSharedPtr &amp;</paramtype>
  235. </parameter>
  236. <parameter name="SFINAE">
  237. <paramtype>typename shared_ptr_traits&lt;ForeignSharedPtr&gt;::weak_type *</paramtype>
  238. <default>0</default>
  239. </parameter>
  240. </signature>
  241. <effects>
  242. <para>
  243. The <code>track_foreign</code>() method behaves similarly to calling the <methodname>track</methodname>() method
  244. with a <classname>boost::shared_ptr</classname> or <classname>boost::weak_ptr</classname> argument.
  245. However, <code>track_foreign</code> is more flexible in that it will accept <code>shared_ptr</code>
  246. or <code>weak_ptr</code> classes from outside of boost (most significantly <code>std::shared_ptr</code>
  247. or <code>std::weak_ptr</code>).
  248. </para>
  249. <para>
  250. In order to use a particular <code>shared_ptr</code> class with this function, a specialization of
  251. <classname>boost::signals2::shared_ptr_traits</classname> must exist for it.
  252. Also, a specialization of <classname>boost::signals2::weak_ptr_traits</classname> must
  253. be provided for its corresponding <code>weak_ptr</code> class.
  254. The <code>shared_ptr_traits</code> specialization must include a <code>weak_type</code>
  255. member typedef which specifies the
  256. corresponding <code>weak_ptr</code> type of the <code>shared_ptr</code> class.
  257. Similarly, the <code>weak_ptr_traits</code> specialization must include a <code>shared_type</code>
  258. member typedef which specifies the corresponding <code>shared_ptr</code> type of the
  259. <code>weak_ptr</code> class. Specializations
  260. for <code>std::shared_ptr</code> and <code>std::weak_ptr</code> are already provided by the signals2 library.
  261. For other <code>shared_ptr</code> classes, you must provide the specializations.
  262. </para>
  263. <para>The second argument "SFINAE" may be ignored, it is used to resolve the overload between
  264. either <code>shared_ptr</code> or <code>weak_ptr</code> objects passed in as the first argument.
  265. </para>
  266. </effects>
  267. <returns><para><code>*this</code></para></returns>
  268. </overloaded-method>
  269. </method-group>
  270. <method-group name="slot function access">
  271. <overloaded-method name="slot_function">
  272. <signature>
  273. <type>slot_function_type &amp;</type>
  274. </signature>
  275. <signature cv="const">
  276. <type>const slot_function_type &amp;</type>
  277. </signature>
  278. <returns><para>A reference to the slot's underlying SlotFunction object.</para></returns>
  279. </overloaded-method>
  280. </method-group>
  281. </class>
  282. </namespace>
  283. </namespace>
  284. </header>