tSignal.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _TSIGNAL_H_
  23. #define _TSIGNAL_H_
  24. #ifndef _UTIL_DELEGATE_H_
  25. #include "core/util/delegate.h"
  26. #endif
  27. #ifndef _TVECTOR_H_
  28. #include "core/util/tVector.h"
  29. #endif
  30. /// Signals (Multi-cast Delegates)
  31. ///
  32. /// Signals are used throughout this engine to allow subscribers to listen
  33. /// for generated events for various things.
  34. ///
  35. /// Signals are called according to their order parameter (lower
  36. /// numbers first).
  37. ///
  38. /// Signal functions can return bool or void. If bool then returning false
  39. /// from a signal function will cause entries in the ordered signal list after
  40. /// that one to not be called.
  41. ///
  42. /// This allows handlers of a given event to say to the signal generator, "I handled this message, and
  43. /// it is no longer appropriate for other listeners to handle it"
  44. class SignalBase
  45. {
  46. public:
  47. SignalBase()
  48. {
  49. mList.next = mList.prev = &mList;
  50. mList.mOrder = 0.5f;
  51. }
  52. ~SignalBase();
  53. /// Removes all the delegates from the signal.
  54. void removeAll();
  55. /// Returns true if the delegate list is empty.
  56. bool isEmpty() const
  57. {
  58. return mList.next == &mList;
  59. }
  60. protected:
  61. struct DelegateLink
  62. {
  63. DelegateLink *next,*prev;
  64. F32 mOrder;
  65. void insert(DelegateLink* node, F32 order);
  66. void unlink();
  67. DelegateLink() :next(NULL), prev(NULL), mOrder(0) {}
  68. virtual ~DelegateLink() {}
  69. };
  70. DelegateLink mList;
  71. /// We need to protect the delegate list against removal of the currently
  72. /// triggering node as well removal of the next node in the list. When not
  73. /// handling these two cases correctly, removing delegates from a signal
  74. /// while it is triggering will lead to crashes.
  75. ///
  76. /// So this field stores the next node of each active traversal so that when
  77. /// we unlink a node, we can check it against this field and move the traversal
  78. /// along if needed.
  79. Vector<DelegateLink*> mTriggerNext;
  80. };
  81. template<typename Signature> class SignalBaseT;
  82. /// Class for handle automatic diconnect form Signal when destroyed
  83. template< typename Signature >
  84. class SignalSlot
  85. {
  86. public:
  87. typedef Delegate< Signature > DelegateSig;
  88. typedef SignalBaseT< Signature > SignalSig;
  89. SignalSlot() : mSignal(NULL)
  90. {
  91. }
  92. ~SignalSlot()
  93. {
  94. disconnect();
  95. }
  96. const DelegateSig& getDelegate() { return mDlg; }
  97. /// setDelegate disconect form Signal old delegate and connect new delegate
  98. template<typename X>
  99. void setDelegate( const X &fn ) { setDelegate( DelegateSig( fn ) ); }
  100. template<typename X, typename Y>
  101. void setDelegate( const X &ptr, const Y &fn ) { setDelegate( DelegateSig( ptr, fn ) ); }
  102. void setDelegate( const DelegateSig &dlg)
  103. {
  104. SignalSig* signal = mSignal;
  105. if( isConnected() )
  106. disconnect();
  107. mDlg = dlg;
  108. if( signal && mDlg )
  109. signal->notify( mDlg );
  110. }
  111. /// is connected to Signal
  112. bool isConnected() const { return mSignal; }
  113. /// disconnect from Signal
  114. void disconnect()
  115. {
  116. if( mSignal )
  117. {
  118. SignalSig *oldSignal = mSignal;
  119. mSignal = NULL;
  120. oldSignal->remove( mDlg );
  121. }
  122. }
  123. protected:
  124. friend class SignalBaseT< Signature >;
  125. void _setSignal(SignalSig *sig)
  126. {
  127. mSignal = sig;
  128. }
  129. SignalSig* _getSignal() const { return mSignal; }
  130. DelegateSig mDlg;
  131. SignalSig *mSignal;
  132. private:
  133. SignalSlot( const SignalSlot&);
  134. SignalSlot& operator=( const SignalSlot&);
  135. };
  136. template<typename Signature> class SignalBaseT : public SignalBase
  137. {
  138. public:
  139. /// The delegate signature for this signal.
  140. typedef Delegate<Signature> DelegateSig;
  141. SignalBaseT() {}
  142. SignalBaseT( const SignalBaseT &base )
  143. {
  144. mList.next = mList.prev = &mList;
  145. merge( base );
  146. }
  147. void operator =( const SignalBaseT &base )
  148. {
  149. removeAll();
  150. merge( base );
  151. }
  152. void merge( const SignalBaseT &base )
  153. {
  154. for ( DelegateLink *ptr = base.mList.next; ptr != &base.mList; ptr = ptr->next )
  155. {
  156. DelegateLinkImpl *del = static_cast<DelegateLinkImpl*>( ptr );
  157. notify( del->mDelegate, del->mOrder );
  158. }
  159. }
  160. void notify( const DelegateSig &dlg, F32 order = 0.5f)
  161. {
  162. mList.insert(new DelegateLinkImpl(dlg), order);
  163. }
  164. void remove( DelegateSig dlg )
  165. {
  166. for( DelegateLink* ptr = mList.next;ptr != &mList; ptr = ptr->next )
  167. {
  168. if( DelegateLinkImpl* del = static_cast< DelegateLinkImpl* >( ptr ) )
  169. {
  170. if( del->mDelegate == dlg )
  171. {
  172. for ( S32 i = 0; i < mTriggerNext.size(); i++ )
  173. {
  174. if( mTriggerNext[i] == ptr )
  175. mTriggerNext[i] = ptr->next;
  176. }
  177. del->unlink();
  178. delete del;
  179. return;
  180. }
  181. }
  182. }
  183. }
  184. template <class T,class U>
  185. void notify(T obj,U func, F32 order = 0.5f)
  186. {
  187. DelegateSig dlg(obj, func);
  188. notify(dlg, order);
  189. }
  190. template <class T>
  191. void notify(T func, F32 order = 0.5f)
  192. {
  193. DelegateSig dlg(func);
  194. notify(dlg, order);
  195. }
  196. void notify( SignalSlot<Signature> &slot, F32 order = 0.5f)
  197. {
  198. if( !slot.getDelegate() )
  199. return;
  200. if( slot.isConnected() )
  201. slot.disconnect();
  202. slot._setSignal( this );
  203. mList.insert( new SlotLinkImpl(slot), order );
  204. }
  205. template <class T,class U>
  206. void remove(T obj,U func)
  207. {
  208. DelegateSig compDelegate(obj, func);
  209. remove(compDelegate);
  210. }
  211. template <class T>
  212. void remove(T func)
  213. {
  214. DelegateSig compDelegate(func);
  215. remove(compDelegate);
  216. }
  217. /// Returns true if the signal already contains this delegate.
  218. bool contains( const DelegateSig &dlg ) const
  219. {
  220. for ( DelegateLink *ptr = mList.next; ptr != &mList; ptr = ptr->next )
  221. {
  222. DelegateLinkImpl *del = static_cast<DelegateLinkImpl*>( ptr );
  223. if ( del->mDelegate == dlg )
  224. return true;
  225. }
  226. return false;
  227. }
  228. protected:
  229. struct DelegateLinkImpl : public SignalBase::DelegateLink
  230. {
  231. DelegateSig mDelegate;
  232. DelegateLinkImpl(DelegateSig dlg) : mDelegate(dlg) {}
  233. };
  234. struct SlotLinkImpl : public DelegateLinkImpl
  235. {
  236. SlotLinkImpl(SignalSlot<Signature>& slot) : mSlot( &slot ), DelegateLinkImpl( slot.getDelegate() )
  237. {
  238. }
  239. ~SlotLinkImpl()
  240. {
  241. if( mSlot )
  242. mSlot->_setSignal( NULL );
  243. }
  244. protected:
  245. SignalSlot<Signature> *mSlot;
  246. };
  247. DelegateSig & getDelegate(SignalBase::DelegateLink * link)
  248. {
  249. return ((DelegateLinkImpl*)link)->mDelegate;
  250. }
  251. };
  252. //-----------------------------------------------------------------------------
  253. template<typename Signature> class Signal;
  254. // Short-circuit signal implementations
  255. template<>
  256. class Signal<bool()> : public SignalBaseT<bool()>
  257. {
  258. public:
  259. bool trigger()
  260. {
  261. this->mTriggerNext.push_back(NULL);
  262. for( SignalBase::DelegateLink* ptr = this->mList.next; ptr != &this->mList; )
  263. {
  264. this->mTriggerNext.last() = ptr->next;
  265. if( !this->getDelegate( ptr )() )
  266. {
  267. this->mTriggerNext.pop_back();
  268. return false;
  269. }
  270. ptr = this->mTriggerNext.last();
  271. }
  272. this->mTriggerNext.pop_back();
  273. return true;
  274. }
  275. };
  276. template<class A>
  277. class Signal<bool(A)> : public SignalBaseT<bool(A)>
  278. {
  279. public:
  280. bool trigger( A a )
  281. {
  282. this->mTriggerNext.push_back(NULL);
  283. for( SignalBase::DelegateLink* ptr = this->mList.next; ptr != &this->mList; )
  284. {
  285. this->mTriggerNext.last() = ptr->next;
  286. if( !this->getDelegate( ptr )( a ) )
  287. {
  288. this->mTriggerNext.pop_back();
  289. return false;
  290. }
  291. ptr = this->mTriggerNext.last();
  292. }
  293. this->mTriggerNext.pop_back();
  294. return true;
  295. }
  296. };
  297. template<class A, class B>
  298. class Signal<bool(A,B)> : public SignalBaseT<bool(A,B)>
  299. {
  300. public:
  301. bool trigger( A a, B b )
  302. {
  303. this->mTriggerNext.push_back(NULL);
  304. for( SignalBase::DelegateLink* ptr = this->mList.next; ptr != &this->mList; )
  305. {
  306. this->mTriggerNext.last() = ptr->next;
  307. if( !this->getDelegate( ptr )( a, b ) )
  308. {
  309. this->mTriggerNext.pop_back();
  310. return false;
  311. }
  312. ptr = this->mTriggerNext.last();
  313. }
  314. this->mTriggerNext.pop_back();
  315. return true;
  316. }
  317. };
  318. template<class A, class B, class C>
  319. class Signal<bool(A,B,C)> : public SignalBaseT<bool(A,B,C)>
  320. {
  321. public:
  322. bool trigger( A a, B b, C c )
  323. {
  324. this->mTriggerNext.push_back(NULL);
  325. for( SignalBase::DelegateLink* ptr = this->mList.next; ptr != &this->mList; )
  326. {
  327. this->mTriggerNext.last() = ptr->next;
  328. if( !this->getDelegate( ptr )( a, b, c ) )
  329. {
  330. this->mTriggerNext.pop_back();
  331. return false;
  332. }
  333. ptr = this->mTriggerNext.last();
  334. }
  335. this->mTriggerNext.pop_back();
  336. return true;
  337. }
  338. };
  339. template<class A, class B, class C, class D>
  340. class Signal<bool(A,B,C,D)> : public SignalBaseT<bool(A,B,C,D)>
  341. {
  342. public:
  343. bool trigger( A a, B b, C c, D d )
  344. {
  345. this->mTriggerNext.push_back(NULL);
  346. for( SignalBase::DelegateLink* ptr = this->mList.next; ptr != &this->mList; )
  347. {
  348. this->mTriggerNext.last() = ptr->next;
  349. if( !this->getDelegate( ptr )( a, b, c, d ) )
  350. {
  351. this->mTriggerNext.pop_back();
  352. return false;
  353. }
  354. ptr = this->mTriggerNext.last();
  355. }
  356. this->mTriggerNext.pop_back();
  357. return true;
  358. }
  359. };
  360. template<class A, class B, class C, class D, class E>
  361. class Signal<bool(A,B,C,D,E)> : public SignalBaseT<bool(A,B,C,D,E)>
  362. {
  363. public:
  364. bool trigger( A a, B b, C c, D d, E e )
  365. {
  366. this->mTriggerNext.push_back(NULL);
  367. for( SignalBase::DelegateLink* ptr = this->mList.next; ptr != &this->mList; )
  368. {
  369. this->mTriggerNext.last() = ptr->next;
  370. if( !this->getDelegate( ptr )( a, b, c, d, e ) )
  371. {
  372. this->mTriggerNext.pop_back();
  373. return false;
  374. }
  375. ptr = this->mTriggerNext.last();
  376. }
  377. this->mTriggerNext.pop_back();
  378. return true;
  379. }
  380. };
  381. template<class A, class B, class C, class D, class E, class F>
  382. class Signal<bool(A,B,C,D,E,F)> : public SignalBaseT<bool(A,B,C,D,E,F)>
  383. {
  384. public:
  385. bool trigger( A a, B b, C c, D d, E e, F f )
  386. {
  387. this->mTriggerNext.push_back(NULL);
  388. for( SignalBase::DelegateLink* ptr = this->mList.next; ptr != &this->mList; )
  389. {
  390. this->mTriggerNext.last() = ptr->next;
  391. if( !this->getDelegate( ptr )( a, b, c, d, e, f ) )
  392. {
  393. this->mTriggerNext.pop_back();
  394. return false;
  395. }
  396. ptr = this->mTriggerNext.last();
  397. }
  398. this->mTriggerNext.pop_back();
  399. return true;
  400. }
  401. };
  402. template<class A, class B, class C, class D, class E, class F, class G>
  403. class Signal<bool(A,B,C,D,E,F,G)> : public SignalBaseT<bool(A,B,C,D,E,F,G)>
  404. {
  405. public:
  406. bool trigger( A a, B b, C c, D d, E e, F f, G g )
  407. {
  408. this->mTriggerNext.push_back(NULL);
  409. for( SignalBase::DelegateLink* ptr = this->mList.next; ptr != &this->mList; )
  410. {
  411. this->mTriggerNext.last() = ptr->next;
  412. if( !this->getDelegate( ptr )( a, b, c, d, e, f, g ) )
  413. {
  414. this->mTriggerNext.pop_back();
  415. return false;
  416. }
  417. ptr = this->mTriggerNext.last();
  418. }
  419. this->mTriggerNext.pop_back();
  420. return true;
  421. }
  422. };
  423. template<class A, class B, class C, class D, class E, class F, class G, class H>
  424. class Signal<bool(A,B,C,D,E,F,G,H)> : public SignalBaseT<bool(A,B,C,D,E,F,G,H)>
  425. {
  426. public:
  427. bool trigger( A a, B b, C c, D d, E e, F f, G g, H h )
  428. {
  429. this->mTriggerNext.push_back(NULL);
  430. for( SignalBase::DelegateLink* ptr = this->mList.next; ptr != &this->mList; )
  431. {
  432. this->mTriggerNext.last() = ptr->next;
  433. if( !this->getDelegate( ptr )( a, b, c, d, e, f, g, h ) )
  434. {
  435. this->mTriggerNext.pop_back();
  436. return false;
  437. }
  438. ptr = this->mTriggerNext.last();
  439. }
  440. this->mTriggerNext.pop_back();
  441. return true;
  442. }
  443. };
  444. template<class A, class B, class C, class D, class E, class F, class G, class H, class I>
  445. class Signal<bool(A,B,C,D,E,F,G,H,I)> : public SignalBaseT<bool(A,B,C,D,E,F,G,H,I)>
  446. {
  447. public:
  448. bool trigger( A a, B b, C c, D d, E e, F f, G g, H h, I i )
  449. {
  450. this->mTriggerNext.push_back(NULL);
  451. for( SignalBase::DelegateLink* ptr = this->mList.next; ptr != &this->mList; )
  452. {
  453. this->mTriggerNext.last() = ptr->next;
  454. if( !this->getDelegate( ptr )( a, b, c, d, e, f, g, h, i ) )
  455. {
  456. this->mTriggerNext.pop_back();
  457. return false;
  458. }
  459. ptr = this->mTriggerNext.last();
  460. }
  461. this->mTriggerNext.pop_back();
  462. return true;
  463. }
  464. };
  465. template<class A, class B, class C, class D, class E, class F, class G, class H, class I, class J>
  466. class Signal<bool(A,B,C,D,E,F,G,H,I,J)> : public SignalBaseT<bool(A,B,C,D,E,F,G,H,I,J)>
  467. {
  468. public:
  469. bool trigger( A a, B b, C c, D d, E e, F f, G g, H h, I i, J j )
  470. {
  471. this->mTriggerNext.push_back(NULL);
  472. for( SignalBase::DelegateLink* ptr = this->mList.next; ptr != &this->mList; )
  473. {
  474. this->mTriggerNext.last() = ptr->next;
  475. if( !this->getDelegate( ptr )( a, b, c, d, e, f, g, h, i, j ) )
  476. {
  477. this->mTriggerNext.pop_back();
  478. return false;
  479. }
  480. ptr = this->mTriggerNext.last();
  481. }
  482. this->mTriggerNext.pop_back();
  483. return true;
  484. }
  485. };
  486. template<class A, class B, class C, class D, class E, class F, class G, class H, class I, class J, class K>
  487. class Signal<bool(A,B,C,D,E,F,G,H,I,J,K)> : public SignalBaseT<bool(A,B,C,D,E,F,G,H,I,J,K)>
  488. {
  489. public:
  490. bool trigger( A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k )
  491. {
  492. this->mTriggerNext.push_back(NULL);
  493. for( SignalBase::DelegateLink* ptr = this->mList.next; ptr != &this->mList; )
  494. {
  495. this->mTriggerNext.last() = ptr->next;
  496. if( !this->getDelegate( ptr )( a, b, c, d, e, f, g, h, i, j, k ) )
  497. {
  498. this->mTriggerNext.pop_back();
  499. return false;
  500. }
  501. ptr = this->mTriggerNext.last();
  502. }
  503. this->mTriggerNext.pop_back();
  504. return true;
  505. }
  506. };
  507. template<class A, class B, class C, class D, class E, class F, class G, class H, class I, class J, class K, class L>
  508. class Signal<bool(A,B,C,D,E,F,G,H,I,J,K,L)> : public SignalBaseT<bool(A,B,C,D,E,F,G,H,I,J,K,L)>
  509. {
  510. public:
  511. bool trigger( A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l )
  512. {
  513. this->mTriggerNext.push_back(NULL);
  514. for( SignalBase::DelegateLink* ptr = this->mList.next; ptr != &this->mList; )
  515. {
  516. this->mTriggerNext.last() = ptr->next;
  517. if( !this->getDelegate( ptr )( a, b, c, d, e, f, g, h, i, j, k, l ) )
  518. {
  519. this->mTriggerNext.pop_back();
  520. return false;
  521. }
  522. ptr = this->mTriggerNext.last();
  523. }
  524. this->mTriggerNext.pop_back();
  525. return true;
  526. }
  527. };
  528. template<class A, class B, class C, class D, class E, class F, class G, class H, class I, class J, class K, class L, class M>
  529. class Signal<bool(A,B,C,D,E,F,G,H,I,J,K,L,M)> : public SignalBaseT<bool(A,B,C,D,E,F,G,H,I,J,K,L,M)>
  530. {
  531. public:
  532. bool trigger( A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l, M m )
  533. {
  534. this->mTriggerNext.push_back(NULL);
  535. for( SignalBase::DelegateLink* ptr = this->mList.next; ptr != &this->mList; )
  536. {
  537. this->mTriggerNext.last() = ptr->next;
  538. if( !this->getDelegate( ptr )( a, b, c, d, e, f, g, h, i, j, k, l, m ) )
  539. {
  540. this->mTriggerNext.pop_back();
  541. return false;
  542. }
  543. ptr = this->mTriggerNext.last();
  544. }
  545. this->mTriggerNext.pop_back();
  546. return true;
  547. }
  548. };
  549. // Non short-circuit signal implementations
  550. template<>
  551. class Signal<void()> : public SignalBaseT<void()>
  552. {
  553. public:
  554. void trigger()
  555. {
  556. this->mTriggerNext.push_back(NULL);
  557. for( SignalBase::DelegateLink* ptr = this->mList.next; ptr != &this->mList; )
  558. {
  559. this->mTriggerNext.last() = ptr->next;
  560. this->getDelegate( ptr )();
  561. ptr = this->mTriggerNext.last();
  562. }
  563. this->mTriggerNext.pop_back();
  564. }
  565. };
  566. template<class A>
  567. class Signal<void(A)> : public SignalBaseT<void(A)>
  568. {
  569. public:
  570. void trigger( A a )
  571. {
  572. this->mTriggerNext.push_back(NULL);
  573. for( SignalBase::DelegateLink* ptr = this->mList.next; ptr != &this->mList; )
  574. {
  575. this->mTriggerNext.last() = ptr->next;
  576. this->getDelegate( ptr )( a );
  577. ptr = this->mTriggerNext.last();
  578. }
  579. this->mTriggerNext.pop_back();
  580. }
  581. };
  582. template<class A, class B>
  583. class Signal<void(A,B)> : public SignalBaseT<void(A,B)>
  584. {
  585. public:
  586. void trigger( A a, B b )
  587. {
  588. this->mTriggerNext.push_back(NULL);
  589. for( SignalBase::DelegateLink* ptr = this->mList.next; ptr != &this->mList; )
  590. {
  591. this->mTriggerNext.last() = ptr->next;
  592. this->getDelegate( ptr )( a, b );
  593. ptr = this->mTriggerNext.last();
  594. }
  595. this->mTriggerNext.pop_back();
  596. }
  597. };
  598. template<class A, class B, class C>
  599. class Signal<void(A,B,C)> : public SignalBaseT<void(A,B,C)>
  600. {
  601. public:
  602. void trigger( A a, B b, C c )
  603. {
  604. this->mTriggerNext.push_back(NULL);
  605. for( SignalBase::DelegateLink* ptr = this->mList.next; ptr != &this->mList; )
  606. {
  607. this->mTriggerNext.last() = ptr->next;
  608. this->getDelegate( ptr )( a, b, c );
  609. ptr = this->mTriggerNext.last();
  610. }
  611. this->mTriggerNext.pop_back();
  612. }
  613. };
  614. template<class A, class B, class C, class D>
  615. class Signal<void(A,B,C,D)> : public SignalBaseT<void(A,B,C,D)>
  616. {
  617. public:
  618. void trigger( A a, B b, C c, D d )
  619. {
  620. this->mTriggerNext.push_back(NULL);
  621. for( SignalBase::DelegateLink* ptr = this->mList.next; ptr != &this->mList; )
  622. {
  623. this->mTriggerNext.last() = ptr->next;
  624. this->getDelegate( ptr )( a, b, c, d );
  625. ptr = this->mTriggerNext.last();
  626. }
  627. this->mTriggerNext.pop_back();
  628. }
  629. };
  630. template<class A, class B, class C, class D, class E>
  631. class Signal<void(A,B,C,D,E)> : public SignalBaseT<void(A,B,C,D,E)>
  632. {
  633. public:
  634. void trigger( A a, B b, C c, D d, E e )
  635. {
  636. this->mTriggerNext.push_back(NULL);
  637. for( SignalBase::DelegateLink* ptr = this->mList.next; ptr != &this->mList; )
  638. {
  639. this->mTriggerNext.last() = ptr->next;
  640. this->getDelegate( ptr )( a, b, c, d, e );
  641. ptr = this->mTriggerNext.last();
  642. }
  643. this->mTriggerNext.pop_back();
  644. }
  645. };
  646. template<class A, class B, class C, class D, class E, class F>
  647. class Signal<void(A,B,C,D,E,F)> : public SignalBaseT<void(A,B,C,D,E,F)>
  648. {
  649. public:
  650. void trigger( A a, B b, C c, D d, E e, F f )
  651. {
  652. this->mTriggerNext.push_back(NULL);
  653. for( SignalBase::DelegateLink* ptr = this->mList.next; ptr != &this->mList; )
  654. {
  655. this->mTriggerNext.last() = ptr->next;
  656. this->getDelegate( ptr )( a, b, c, d, e, f );
  657. ptr = this->mTriggerNext.last();
  658. }
  659. this->mTriggerNext.pop_back();
  660. }
  661. };
  662. template<class A, class B, class C, class D, class E, class F, class G>
  663. class Signal<void(A,B,C,D,E,F,G)> : public SignalBaseT<void(A,B,C,D,E,F,G)>
  664. {
  665. public:
  666. void trigger( A a, B b, C c, D d, E e, F f, G g )
  667. {
  668. this->mTriggerNext.push_back(NULL);
  669. for( SignalBase::DelegateLink* ptr = this->mList.next; ptr != &this->mList; )
  670. {
  671. this->mTriggerNext.last() = ptr->next;
  672. this->getDelegate( ptr )( a, b, c, d, e, f, g );
  673. ptr = this->mTriggerNext.last();
  674. }
  675. this->mTriggerNext.pop_back();
  676. }
  677. };
  678. template<class A, class B, class C, class D, class E, class F, class G, class H>
  679. class Signal<void(A,B,C,D,E,F,G,H)> : public SignalBaseT<void(A,B,C,D,E,F,G,H)>
  680. {
  681. public:
  682. void trigger( A a, B b, C c, D d, E e, F f, G g, H h )
  683. {
  684. this->mTriggerNext.push_back(NULL);
  685. for( SignalBase::DelegateLink* ptr = this->mList.next; ptr != &this->mList; )
  686. {
  687. this->mTriggerNext.last() = ptr->next;
  688. this->getDelegate( ptr )( a, b, c, d, e, f, g, h );
  689. ptr = this->mTriggerNext.last();
  690. }
  691. this->mTriggerNext.pop_back();
  692. }
  693. };
  694. template<class A, class B, class C, class D, class E, class F, class G, class H, class I>
  695. class Signal<void(A,B,C,D,E,F,G,H,I)> : public SignalBaseT<void(A,B,C,D,E,F,G,H,I)>
  696. {
  697. public:
  698. void trigger( A a, B b, C c, D d, E e, F f, G g, H h, I i )
  699. {
  700. this->mTriggerNext.push_back(NULL);
  701. for( SignalBase::DelegateLink* ptr = this->mList.next; ptr != &this->mList; )
  702. {
  703. this->mTriggerNext.last() = ptr->next;
  704. this->getDelegate( ptr )( a, b, c, d, e, f, g, h, i );
  705. ptr = this->mTriggerNext.last();
  706. }
  707. this->mTriggerNext.pop_back();
  708. }
  709. };
  710. template<class A, class B, class C, class D, class E, class F, class G, class H, class I, class J>
  711. class Signal<void(A,B,C,D,E,F,G,H,I,J)> : public SignalBaseT<void(A,B,C,D,E,F,G,H,I,J)>
  712. {
  713. public:
  714. void trigger( A a, B b, C c, D d, E e, F f, G g, H h, I i, J j )
  715. {
  716. this->mTriggerNext.push_back(NULL);
  717. for( SignalBase::DelegateLink* ptr = this->mList.next; ptr != &this->mList; )
  718. {
  719. this->mTriggerNext.last() = ptr->next;
  720. this->getDelegate( ptr )( a, b, c, d, e, f, g, h, i, j );
  721. ptr = this->mTriggerNext.last();
  722. }
  723. this->mTriggerNext.pop_back();
  724. }
  725. };
  726. template<class A, class B, class C, class D, class E, class F, class G, class H, class I, class J, class K>
  727. class Signal<void(A,B,C,D,E,F,G,H,I,J,K)> : public SignalBaseT<void(A,B,C,D,E,F,G,H,I,J,K)>
  728. {
  729. public:
  730. void trigger( A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k )
  731. {
  732. this->mTriggerNext.push_back(NULL);
  733. for( SignalBase::DelegateLink* ptr = this->mList.next; ptr != &this->mList; )
  734. {
  735. this->mTriggerNext.last() = ptr->next;
  736. this->getDelegate( ptr )( a, b, c, d, e, f, g, h, i, j, k );
  737. ptr = this->mTriggerNext.last();
  738. }
  739. this->mTriggerNext.pop_back();
  740. }
  741. };
  742. template<class A, class B, class C, class D, class E, class F, class G, class H, class I, class J, class K, class L>
  743. class Signal<void(A,B,C,D,E,F,G,H,I,J,K,L)> : public SignalBaseT<void(A,B,C,D,E,F,G,H,I,J,K,L)>
  744. {
  745. public:
  746. void trigger( A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l )
  747. {
  748. this->mTriggerNext.push_back(NULL);
  749. for( SignalBase::DelegateLink* ptr = this->mList.next; ptr != &this->mList; )
  750. {
  751. this->mTriggerNext.last() = ptr->next;
  752. this->getDelegate( ptr )( a, b, c, d, e, f, g, h, i, j, k, l );
  753. ptr = this->mTriggerNext.last();
  754. }
  755. this->mTriggerNext.pop_back();
  756. }
  757. };
  758. template<class A, class B, class C, class D, class E, class F, class G, class H, class I, class J, class K, class L, class M>
  759. class Signal<void(A,B,C,D,E,F,G,H,I,J,K,L,M)> : public SignalBaseT<void(A,B,C,D,E,F,G,H,I,J,K,L,M)>
  760. {
  761. public:
  762. void trigger( A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l, M m )
  763. {
  764. this->mTriggerNext.push_back(NULL);
  765. for( SignalBase::DelegateLink* ptr = this->mList.next; ptr != &this->mList; )
  766. {
  767. this->mTriggerNext.last() = ptr->next;
  768. this->getDelegate( ptr )( a, b, c, d, e, f, g, h, i, j, k, l, m );
  769. ptr = this->mTriggerNext.last();
  770. }
  771. this->mTriggerNext.pop_back();
  772. }
  773. };
  774. #endif // _TSIGNAL_H_