1// BEGIN_Delegate 10 2/** 3A Delegate is essentially a Signal with only a single target slot. 4*/ 5template < typename R,class A1 = Void, class A2 = Void, class A3 = Void, class A4 = Void, class A5 = Void, class A6 = Void, class A7 = Void, class A8 = Void, class A9 = Void, class A10 = Void> 6class Delegate : public DelegateBase 7 { 8 public: 9 typedef Callable<R,A1,A2,A3,A4,A5,A6,A7,A8,A9,A10> CallableT; 10 11 public: 12 /** Does nothing. */ 13 Delegate() 14 { } 15 16 /** Deeply copies rhs. */ 17 Delegate(const Delegate& rhs) 18 { 19 DelegateBase::operator=(rhs); 20 } 21 22 /** Connects this object to the given slot and returns that Connection. */ 23 Connection connect(const BasicSlot<R,A1,A2,A3,A4,A5,A6,A7,A8,A9,A10>& slot) 24 { 25 return Connection(*this, slot.clone() ); 26 } 27 28 /** 29 Passes on all arguments to the connected slot and returns the return value 30 of that slot. If no slot is connect then an exception is thrown. 31 */ 32 inline R call(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10) const 33 { 34 if( !_target.valid() ) { 35 throw std::logic_error("Delegate<R,A1,A2,A3,A4,A5,A6,A7,A8,A9,A10>::call(): Delegate not connected"); 36 } 37 const CallableT* cb = static_cast<const CallableT*>( _target.slot().callable() ); 38 return cb->call(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10); 39 } 40 41 /** 42 Passes on all arguments to the connected slot and ignores the return value. If 43 No slot is connected, the call is silently ignored. 44 */ 45 inline void invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10) const 46 { 47 if( !_target.valid() ) { 48 return; 49 } 50 const CallableT* cb = static_cast<const CallableT*>( _target.slot().callable() ); 51 cb->call(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10); 52 } 53 54 /** Identical to call(...). */ 55 R operator()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10) const 56 { return this->call(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10); } 57 }; 58/** 59DelegateSlot wraps Deletegate object so that they can behave like Slots. 60*/ 61template < typename R,class A1 = Void, class A2 = Void, class A3 = Void, class A4 = Void, class A5 = Void, class A6 = Void, class A7 = Void, class A8 = Void, class A9 = Void, class A10 = Void> 62class DelegateSlot : public BasicSlot<R, A1,A2,A3,A4,A5,A6,A7,A8,A9,A10> 63{ 64 public: 65 /** Wraps the given Delegate. */ 66 DelegateSlot(Delegate<R, A1,A2,A3,A4,A5,A6,A7,A8,A9,A10>& delegate) 67 : _method( delegate, &Delegate<R,A1,A2,A3,A4,A5,A6,A7,A8,A9,A10>::call ) 68 {} 69 70 /** Creates a copy of this object and returns it. Caller owns the returned object. */ 71 Slot* clone() const 72 { return new DelegateSlot(*this); } 73 74 /** Returns a pointer to this object's internal Callable. */ 75 virtual const void* callable() const 76 { 77 return &_method; 78 } 79 80 virtual void onConnect(const Connection& c) 81 { 82 _method.object().onConnectionOpen(c); 83 } 84 85 virtual void onDisconnect(const Connection& c) 86 { 87 _method.object().onConnectionClose(c); 88 } 89 90 virtual bool equals(const Slot& slot) const 91 { 92 const DelegateSlot* ds = dynamic_cast<const DelegateSlot*>(&slot); 93 return ds ? (_method == ds->_method) : false; 94 } 95 96 private: 97 mutable ConstMethod<R, Delegate<R, A1,A2,A3,A4,A5,A6,A7,A8,A9,A10>, A1,A2,A3,A4,A5,A6,A7,A8,A9,A10 > _method; 98}; 99 100/** Creates and returns a DelegateSlot for the given Delegate. */ 101 template < typename R,class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10> 102 DelegateSlot<R,A1,A2,A3,A4,A5,A6,A7,A8,A9,A10> slot( Delegate<R,A1,A2,A3,A4,A5,A6,A7,A8,A9,A10>& delegate ) 103 { return DelegateSlot<R,A1,A2,A3,A4,A5,A6,A7,A8,A9,A10>( delegate ); } 104 105 /** Connect a Delegate to another Delegate. 106 */ 107 template <typename R,class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10> 108 Connection connect(Delegate<R,A1,A2,A3,A4,A5,A6,A7,A8,A9,A10>& delegate, Delegate<R,A1,A2,A3,A4,A5,A6,A7,A8,A9,A10>& receiver) 109 { 110 return connect( delegate, slot(receiver) ); 111 } 112 113 /** Connect a Delegate to a Slot. 114 */ 115 template <typename R,class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10> 116 Connection connect(Delegate<R,A1,A2,A3,A4,A5,A6,A7,A8,A9,A10>& delegate, const BasicSlot<R,A1,A2,A3,A4,A5,A6,A7,A8,A9,A10>& slot) 117 { 118 return delegate.connect( slot); 119 } 120 121 122 /** Connect a Delegate to a function. 123 */ 124 template <typename R,class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10> 125 Connection connect(Delegate<R,A1,A2,A3,A4,A5,A6,A7,A8,A9,A10>& delegate, R(*func)(A1,A2,A3,A4,A5,A6,A7,A8,A9,A10)) 126 { 127 return connect( delegate, slot(func) ); 128 } 129 130 131 /** Connect a Delegate to a member function. 132 */ 133 template <typename R, class BaseT, class ClassT,class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10> 134 Connection connect(Delegate<R,A1,A2,A3,A4,A5,A6,A7,A8,A9,A10>& delegate, BaseT& object, R(ClassT::*memFunc)(A1,A2,A3,A4,A5,A6,A7,A8,A9,A10)) 135 { 136 return connect( delegate, slot(object, memFunc) ); 137 } 138 139 /** Connect a Delegate to a const member function. 140 */ 141 template <typename R, class BaseT, class ClassT,class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10> 142 Connection connect(Delegate<R>& delegate, BaseT& object, R(ClassT::*memFunc)(A1,A2,A3,A4,A5,A6,A7,A8,A9,A10) const) 143 { 144 return connect( delegate, slot(object, memFunc) ); 145 } 146 147 148// END_Delegate 149// BEGIN_Delegate 9 150template < typename R,class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9> 151class Delegate<R, A1,A2,A3,A4,A5,A6,A7,A8,A9,Void> : public DelegateBase 152 { 153 public: 154 typedef Callable<R,A1,A2,A3,A4,A5,A6,A7,A8,A9> CallableT; 155 156 public: 157 /** Does nothing. */ 158 Delegate() 159 { } 160 161 /** Deeply copies rhs. */ 162 Delegate(const Delegate& rhs) 163 { 164 DelegateBase::operator=(rhs); 165 } 166 167 /** Connects this object to the given slot and returns that Connection. */ 168 Connection connect(const BasicSlot<R,A1,A2,A3,A4,A5,A6,A7,A8,A9>& slot) 169 { 170 return Connection(*this, slot.clone() ); 171 } 172 173 /** 174 Passes on all arguments to the connected slot and returns the return value 175 of that slot. If no slot is connect then an exception is thrown. 176 */ 177 inline R call(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) const 178 { 179 if( !_target.valid() ) { 180 throw std::logic_error("Delegate<R,A1,A2,A3,A4,A5,A6,A7,A8,A9>::call(): Delegate not connected"); 181 } 182 const CallableT* cb = static_cast<const CallableT*>( _target.slot().callable() ); 183 return cb->call(a1,a2,a3,a4,a5,a6,a7,a8,a9); 184 } 185 186 /** 187 Passes on all arguments to the connected slot and ignores the return value. If 188 No slot is connected, the call is silently ignored. 189 */ 190 inline void invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) const 191 { 192 if( !_target.valid() ) { 193 return; 194 } 195 const CallableT* cb = static_cast<const CallableT*>( _target.slot().callable() ); 196 cb->call(a1,a2,a3,a4,a5,a6,a7,a8,a9); 197 } 198 199 /** Identical to call(...). */ 200 R operator()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) const 201 { return this->call(a1,a2,a3,a4,a5,a6,a7,a8,a9); } 202 }; 203 /** Connect a Delegate to another Delegate. 204 */ 205 template <typename R,class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9> 206 Connection connect(Delegate<R,A1,A2,A3,A4,A5,A6,A7,A8,A9>& delegate, Delegate<R,A1,A2,A3,A4,A5,A6,A7,A8,A9>& receiver) 207 { 208 return connect( delegate, slot(receiver) ); 209 } 210 211 /** Connect a Delegate to a Slot. 212 */ 213 template <typename R,class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9> 214 Connection connect(Delegate<R,A1,A2,A3,A4,A5,A6,A7,A8,A9>& delegate, const BasicSlot<R,A1,A2,A3,A4,A5,A6,A7,A8,A9>& slot) 215 { 216 return delegate.connect( slot ); 217 } 218 219 220 /** Connect a Delegate to a function. 221 */ 222 template <typename R,class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9> 223 Connection connect(Delegate<R,A1,A2,A3,A4,A5,A6,A7,A8,A9>& delegate, R(*func)(A1,A2,A3,A4,A5,A6,A7,A8,A9)) 224 { 225 return connect( delegate, slot(func) ); 226 } 227 228 229 /** Connect a Delegate to a member function. 230 */ 231 template <typename R, class BaseT, class ClassT,class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9> 232 Connection connect(Delegate<R,A1,A2,A3,A4,A5,A6,A7,A8,A9>& delegate, BaseT& object, R(ClassT::*memFunc)(A1,A2,A3,A4,A5,A6,A7,A8,A9)) 233 { 234 return connect( delegate, slot(object, memFunc) ); 235 } 236 237 /** Connect a Delegate to a const member function. 238 */ 239 template <typename R, class BaseT, class ClassT,class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9> 240 Connection connect(Delegate<R>& delegate, BaseT& object, R(ClassT::*memFunc)(A1,A2,A3,A4,A5,A6,A7,A8,A9) const) 241 { 242 return connect( delegate, slot(object, memFunc) ); 243 } 244 245 246// END_Delegate 247// BEGIN_Delegate 8 248template < typename R,class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8> 249class Delegate<R, A1,A2,A3,A4,A5,A6,A7,A8,Void,Void> : public DelegateBase 250 { 251 public: 252 typedef Callable<R,A1,A2,A3,A4,A5,A6,A7,A8> CallableT; 253 254 public: 255 /** Does nothing. */ 256 Delegate() 257 { } 258 259 /** Deeply copies rhs. */ 260 Delegate(const Delegate& rhs) 261 { 262 DelegateBase::operator=(rhs); 263 } 264 265 /** Connects this object to the given slot and returns that Connection. */ 266 Connection connect(const BasicSlot<R,A1,A2,A3,A4,A5,A6,A7,A8>& slot) 267 { 268 return Connection(*this, slot.clone() ); 269 } 270 271 /** 272 Passes on all arguments to the connected slot and returns the return value 273 of that slot. If no slot is connect then an exception is thrown. 274 */ 275 inline R call(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) const 276 { 277 if( !_target.valid() ) { 278 throw std::logic_error("Delegate<R,A1,A2,A3,A4,A5,A6,A7,A8>::call(): Delegate not connected"); 279 } 280 const CallableT* cb = static_cast<const CallableT*>( _target.slot().callable() ); 281 return cb->call(a1,a2,a3,a4,a5,a6,a7,a8); 282 } 283 284 /** 285 Passes on all arguments to the connected slot and ignores the return value. If 286 No slot is connected, the call is silently ignored. 287 */ 288 inline void invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) const 289 { 290 if( !_target.valid() ) { 291 return; 292 } 293 const CallableT* cb = static_cast<const CallableT*>( _target.slot().callable() ); 294 cb->call(a1,a2,a3,a4,a5,a6,a7,a8); 295 } 296 297 /** Identical to call(...). */ 298 R operator()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) const 299 { return this->call(a1,a2,a3,a4,a5,a6,a7,a8); } 300 }; 301 /** Connect a Delegate to another Delegate. 302 */ 303 template <typename R,class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8> 304 Connection connect(Delegate<R,A1,A2,A3,A4,A5,A6,A7,A8>& delegate, Delegate<R,A1,A2,A3,A4,A5,A6,A7,A8>& receiver) 305 { 306 return connect( delegate, slot(receiver) ); 307 } 308 309 /** Connect a Delegate to a Slot. 310 */ 311 template <typename R,class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8> 312 Connection connect(Delegate<R,A1,A2,A3,A4,A5,A6,A7,A8>& delegate, const BasicSlot<R,A1,A2,A3,A4,A5,A6,A7,A8>& slot) 313 { 314 return delegate.connect(slot); 315 } 316 317 318 /** Connect a Delegate to a function. 319 */ 320 template <typename R,class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8> 321 Connection connect(Delegate<R,A1,A2,A3,A4,A5,A6,A7,A8>& delegate, R(*func)(A1,A2,A3,A4,A5,A6,A7,A8)) 322 { 323 return connect( delegate, slot(func) ); 324 } 325 326 327 /** Connect a Delegate to a member function. 328 */ 329 template <typename R, class BaseT, class ClassT,class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8> 330 Connection connect(Delegate<R,A1,A2,A3,A4,A5,A6,A7,A8>& delegate, BaseT& object, R(ClassT::*memFunc)(A1,A2,A3,A4,A5,A6,A7,A8)) 331 { 332 return connect( delegate, slot(object, memFunc) ); 333 } 334 335 /** Connect a Delegate to a const member function. 336 */ 337 template <typename R, class BaseT, class ClassT,class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8> 338 Connection connect(Delegate<R>& delegate, BaseT& object, R(ClassT::*memFunc)(A1,A2,A3,A4,A5,A6,A7,A8) const) 339 { 340 return connect( delegate, slot(object, memFunc) ); 341 } 342 343 344// END_Delegate 345// BEGIN_Delegate 7 346template < typename R,class A1, class A2, class A3, class A4, class A5, class A6, class A7> 347class Delegate<R, A1,A2,A3,A4,A5,A6,A7,Void,Void,Void> : public DelegateBase 348 { 349 public: 350 typedef Callable<R,A1,A2,A3,A4,A5,A6,A7> CallableT; 351 352 public: 353 /** Does nothing. */ 354 Delegate() 355 { } 356 357 /** Deeply copies rhs. */ 358 Delegate(const Delegate& rhs) 359 { 360 DelegateBase::operator=(rhs); 361 } 362 363 /** Connects this object to the given slot and returns that Connection. */ 364 Connection connect(const BasicSlot<R,A1,A2,A3,A4,A5,A6,A7>& slot) 365 { 366 return Connection(*this, slot.clone() ); 367 } 368 369 /** 370 Passes on all arguments to the connected slot and returns the return value 371 of that slot. If no slot is connect then an exception is thrown. 372 */ 373 inline R call(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) const 374 { 375 if( !_target.valid() ) { 376 throw std::logic_error("Delegate<R,A1,A2,A3,A4,A5,A6,A7>::call(): Delegate not connected"); 377 } 378 const CallableT* cb = static_cast<const CallableT*>( _target.slot().callable() ); 379 return cb->call(a1,a2,a3,a4,a5,a6,a7); 380 } 381 382 /** 383 Passes on all arguments to the connected slot and ignores the return value. If 384 No slot is connected, the call is silently ignored. 385 */ 386 inline void invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) const 387 { 388 if( !_target.valid() ) { 389 return; 390 } 391 const CallableT* cb = static_cast<const CallableT*>( _target.slot().callable() ); 392 cb->call(a1,a2,a3,a4,a5,a6,a7); 393 } 394 395 /** Identical to call(...). */ 396 R operator()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) const 397 { return this->call(a1,a2,a3,a4,a5,a6,a7); } 398 }; 399 /** Connect a Delegate to another Delegate. 400 */ 401 template <typename R,class A1, class A2, class A3, class A4, class A5, class A6, class A7> 402 Connection connect(Delegate<R,A1,A2,A3,A4,A5,A6,A7>& delegate, Delegate<R,A1,A2,A3,A4,A5,A6,A7>& receiver) 403 { 404 return connect( delegate, slot(receiver) ); 405 } 406 407 /** Connect a Delegate to a Slot. 408 */ 409 template <typename R,class A1, class A2, class A3, class A4, class A5, class A6, class A7> 410 Connection connect(Delegate<R,A1,A2,A3,A4,A5,A6,A7>& delegate, const BasicSlot<R,A1,A2,A3,A4,A5,A6,A7>& slot) 411 { 412 return delegate.connect(slot); 413 } 414 415 416 /** Connect a Delegate to a function. 417 */ 418 template <typename R,class A1, class A2, class A3, class A4, class A5, class A6, class A7> 419 Connection connect(Delegate<R,A1,A2,A3,A4,A5,A6,A7>& delegate, R(*func)(A1,A2,A3,A4,A5,A6,A7)) 420 { 421 return connect( delegate, slot(func) ); 422 } 423 424 425 /** Connect a Delegate to a member function. 426 */ 427 template <typename R, class BaseT, class ClassT,class A1, class A2, class A3, class A4, class A5, class A6, class A7> 428 Connection connect(Delegate<R,A1,A2,A3,A4,A5,A6,A7>& delegate, BaseT& object, R(ClassT::*memFunc)(A1,A2,A3,A4,A5,A6,A7)) 429 { 430 return connect( delegate, slot(object, memFunc) ); 431 } 432 433 /** Connect a Delegate to a const member function. 434 */ 435 template <typename R, class BaseT, class ClassT,class A1, class A2, class A3, class A4, class A5, class A6, class A7> 436 Connection connect(Delegate<R>& delegate, BaseT& object, R(ClassT::*memFunc)(A1,A2,A3,A4,A5,A6,A7) const) 437 { 438 return connect( delegate, slot(object, memFunc) ); 439 } 440 441 442// END_Delegate 443// BEGIN_Delegate 6 444template < typename R,class A1, class A2, class A3, class A4, class A5, class A6> 445class Delegate<R, A1,A2,A3,A4,A5,A6,Void,Void,Void,Void> : public DelegateBase 446 { 447 public: 448 typedef Callable<R,A1,A2,A3,A4,A5,A6> CallableT; 449 450 public: 451 /** Does nothing. */ 452 Delegate() 453 { } 454 455 /** Deeply copies rhs. */ 456 Delegate(const Delegate& rhs) 457 { 458 DelegateBase::operator=(rhs); 459 } 460 461 /** Connects this object to the given slot and returns that Connection. */ 462 Connection connect(const BasicSlot<R,A1,A2,A3,A4,A5,A6>& slot) 463 { 464 return Connection(*this, slot.clone() ); 465 } 466 467 /** 468 Passes on all arguments to the connected slot and returns the return value 469 of that slot. If no slot is connect then an exception is thrown. 470 */ 471 inline R call(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) const 472 { 473 if( !_target.valid() ) { 474 throw std::logic_error("Delegate<R,A1,A2,A3,A4,A5,A6>::call(): Delegate not connected"); 475 } 476 const CallableT* cb = static_cast<const CallableT*>( _target.slot().callable() ); 477 return cb->call(a1,a2,a3,a4,a5,a6); 478 } 479 480 /** 481 Passes on all arguments to the connected slot and ignores the return value. If 482 No slot is connected, the call is silently ignored. 483 */ 484 inline void invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) const 485 { 486 if( !_target.valid() ) { 487 return; 488 } 489 const CallableT* cb = static_cast<const CallableT*>( _target.slot().callable() ); 490 cb->call(a1,a2,a3,a4,a5,a6); 491 } 492 493 /** Identical to call(...). */ 494 R operator()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) const 495 { return this->call(a1,a2,a3,a4,a5,a6); } 496 }; 497 /** Connect a Delegate to another Delegate. 498 */ 499 template <typename R,class A1, class A2, class A3, class A4, class A5, class A6> 500 Connection connect(Delegate<R,A1,A2,A3,A4,A5,A6>& delegate, Delegate<R,A1,A2,A3,A4,A5,A6>& receiver) 501 { 502 return connect( delegate, slot(receiver) ); 503 } 504 505 /** Connect a Delegate to a Slot. 506 */ 507 template <typename R,class A1, class A2, class A3, class A4, class A5, class A6> 508 Connection connect(Delegate<R,A1,A2,A3,A4,A5,A6>& delegate, const BasicSlot<R,A1,A2,A3,A4,A5,A6>& slot) 509 { 510 return delegate.connect(slot); 511 } 512 513 514 /** Connect a Delegate to a function. 515 */ 516 template <typename R,class A1, class A2, class A3, class A4, class A5, class A6> 517 Connection connect(Delegate<R,A1,A2,A3,A4,A5,A6>& delegate, R(*func)(A1,A2,A3,A4,A5,A6)) 518 { 519 return connect( delegate, slot(func) ); 520 } 521 522 523 /** Connect a Delegate to a member function. 524 */ 525 template <typename R, class BaseT, class ClassT,class A1, class A2, class A3, class A4, class A5, class A6> 526 Connection connect(Delegate<R,A1,A2,A3,A4,A5,A6>& delegate, BaseT& object, R(ClassT::*memFunc)(A1,A2,A3,A4,A5,A6)) 527 { 528 return connect( delegate, slot(object, memFunc) ); 529 } 530 531 /** Connect a Delegate to a const member function. 532 */ 533 template <typename R, class BaseT, class ClassT,class A1, class A2, class A3, class A4, class A5, class A6> 534 Connection connect(Delegate<R>& delegate, BaseT& object, R(ClassT::*memFunc)(A1,A2,A3,A4,A5,A6) const) 535 { 536 return connect( delegate, slot(object, memFunc) ); 537 } 538 539 540// END_Delegate 541// BEGIN_Delegate 5 542template < typename R,class A1, class A2, class A3, class A4, class A5> 543class Delegate<R, A1,A2,A3,A4,A5,Void,Void,Void,Void,Void> : public DelegateBase 544 { 545 public: 546 typedef Callable<R,A1,A2,A3,A4,A5> CallableT; 547 548 public: 549 /** Does nothing. */ 550 Delegate() 551 { } 552 553 /** Deeply copies rhs. */ 554 Delegate(const Delegate& rhs) 555 { 556 DelegateBase::operator=(rhs); 557 } 558 559 /** Connects this object to the given slot and returns that Connection. */ 560 Connection connect(const BasicSlot<R,A1,A2,A3,A4,A5>& slot) 561 { 562 return Connection(*this, slot.clone() ); 563 } 564 565 /** 566 Passes on all arguments to the connected slot and returns the return value 567 of that slot. If no slot is connect then an exception is thrown. 568 */ 569 inline R call(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) const 570 { 571 if( !_target.valid() ) { 572 throw std::logic_error("Delegate<R,A1,A2,A3,A4,A5>::call(): Delegate not connected"); 573 } 574 const CallableT* cb = static_cast<const CallableT*>( _target.slot().callable() ); 575 return cb->call(a1,a2,a3,a4,a5); 576 } 577 578 /** 579 Passes on all arguments to the connected slot and ignores the return value. If 580 No slot is connected, the call is silently ignored. 581 */ 582 inline void invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) const 583 { 584 if( !_target.valid() ) { 585 return; 586 } 587 const CallableT* cb = static_cast<const CallableT*>( _target.slot().callable() ); 588 cb->call(a1,a2,a3,a4,a5); 589 } 590 591 /** Identical to call(...). */ 592 R operator()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) const 593 { return this->call(a1,a2,a3,a4,a5); } 594 }; 595 /** Connect a Delegate to another Delegate. 596 */ 597 template <typename R,class A1, class A2, class A3, class A4, class A5> 598 Connection connect(Delegate<R,A1,A2,A3,A4,A5>& delegate, Delegate<R,A1,A2,A3,A4,A5>& receiver) 599 { 600 return connect( delegate, slot(receiver) ); 601 } 602 603 /** Connect a Delegate to a Slot. 604 */ 605 template <typename R,class A1, class A2, class A3, class A4, class A5> 606 Connection connect(Delegate<R,A1,A2,A3,A4,A5>& delegate, const BasicSlot<R,A1,A2,A3,A4,A5>& slot) 607 { 608 return delegate.connect(slot); 609 } 610 611 612 /** Connect a Delegate to a function. 613 */ 614 template <typename R,class A1, class A2, class A3, class A4, class A5> 615 Connection connect(Delegate<R,A1,A2,A3,A4,A5>& delegate, R(*func)(A1,A2,A3,A4,A5)) 616 { 617 return connect( delegate, slot(func) ); 618 } 619 620 621 /** Connect a Delegate to a member function. 622 */ 623 template <typename R, class BaseT, class ClassT,class A1, class A2, class A3, class A4, class A5> 624 Connection connect(Delegate<R,A1,A2,A3,A4,A5>& delegate, BaseT& object, R(ClassT::*memFunc)(A1,A2,A3,A4,A5)) 625 { 626 return connect( delegate, slot(object, memFunc) ); 627 } 628 629 /** Connect a Delegate to a const member function. 630 */ 631 template <typename R, class BaseT, class ClassT,class A1, class A2, class A3, class A4, class A5> 632 Connection connect(Delegate<R>& delegate, BaseT& object, R(ClassT::*memFunc)(A1,A2,A3,A4,A5) const) 633 { 634 return connect( delegate, slot(object, memFunc) ); 635 } 636 637 638// END_Delegate 639// BEGIN_Delegate 4 640template < typename R,class A1, class A2, class A3, class A4> 641class Delegate<R, A1,A2,A3,A4,Void,Void,Void,Void,Void,Void> : public DelegateBase 642 { 643 public: 644 typedef Callable<R,A1,A2,A3,A4> CallableT; 645 646 public: 647 /** Does nothing. */ 648 Delegate() 649 { } 650 651 /** Deeply copies rhs. */ 652 Delegate(const Delegate& rhs) 653 { 654 DelegateBase::operator=(rhs); 655 } 656 657 /** Connects this object to the given slot and returns that Connection. */ 658 Connection connect(const BasicSlot<R,A1,A2,A3,A4>& slot) 659 { 660 return Connection(*this, slot.clone() ); 661 } 662 663 /** 664 Passes on all arguments to the connected slot and returns the return value 665 of that slot. If no slot is connect then an exception is thrown. 666 */ 667 inline R call(A1 a1, A2 a2, A3 a3, A4 a4) const 668 { 669 if( !_target.valid() ) { 670 throw std::logic_error("Delegate<R,A1,A2,A3,A4>::call(): Delegate not connected"); 671 } 672 const CallableT* cb = static_cast<const CallableT*>( _target.slot().callable() ); 673 return cb->call(a1,a2,a3,a4); 674 } 675 676 /** 677 Passes on all arguments to the connected slot and ignores the return value. If 678 No slot is connected, the call is silently ignored. 679 */ 680 inline void invoke(A1 a1, A2 a2, A3 a3, A4 a4) const 681 { 682 if( !_target.valid() ) { 683 return; 684 } 685 const CallableT* cb = static_cast<const CallableT*>( _target.slot().callable() ); 686 cb->call(a1,a2,a3,a4); 687 } 688 689 /** Identical to call(...). */ 690 R operator()(A1 a1, A2 a2, A3 a3, A4 a4) const 691 { return this->call(a1,a2,a3,a4); } 692 }; 693 /** Connect a Delegate to another Delegate. 694 */ 695 template <typename R,class A1, class A2, class A3, class A4> 696 Connection connect(Delegate<R,A1,A2,A3,A4>& delegate, Delegate<R,A1,A2,A3,A4>& receiver) 697 { 698 return connect( delegate, slot(receiver) ); 699 } 700 701 /** Connect a Delegate to a Slot. 702 */ 703 template <typename R,class A1, class A2, class A3, class A4> 704 Connection connect(Delegate<R,A1,A2,A3,A4>& delegate, const BasicSlot<R,A1,A2,A3,A4>& slot) 705 { 706 return delegate.connect(slot); 707 } 708 709 710 /** Connect a Delegate to a function. 711 */ 712 template <typename R,class A1, class A2, class A3, class A4> 713 Connection connect(Delegate<R,A1,A2,A3,A4>& delegate, R(*func)(A1,A2,A3,A4)) 714 { 715 return connect( delegate, slot(func) ); 716 } 717 718 719 /** Connect a Delegate to a member function. 720 */ 721 template <typename R, class BaseT, class ClassT,class A1, class A2, class A3, class A4> 722 Connection connect(Delegate<R,A1,A2,A3,A4>& delegate, BaseT& object, R(ClassT::*memFunc)(A1,A2,A3,A4)) 723 { 724 return connect( delegate, slot(object, memFunc) ); 725 } 726 727 /** Connect a Delegate to a const member function. 728 */ 729 template <typename R, class BaseT, class ClassT,class A1, class A2, class A3, class A4> 730 Connection connect(Delegate<R>& delegate, BaseT& object, R(ClassT::*memFunc)(A1,A2,A3,A4) const) 731 { 732 return connect( delegate, slot(object, memFunc) ); 733 } 734 735 736// END_Delegate 737// BEGIN_Delegate 3 738template < typename R,class A1, class A2, class A3> 739class Delegate<R, A1,A2,A3,Void,Void,Void,Void,Void,Void,Void> : public DelegateBase 740 { 741 public: 742 typedef Callable<R,A1,A2,A3> CallableT; 743 744 public: 745 /** Does nothing. */ 746 Delegate() 747 { } 748 749 /** Deeply copies rhs. */ 750 Delegate(const Delegate& rhs) 751 { 752 DelegateBase::operator=(rhs); 753 } 754 755 /** Connects this object to the given slot and returns that Connection. */ 756 Connection connect(const BasicSlot<R,A1,A2,A3>& slot) 757 { 758 return Connection(*this, slot.clone() ); 759 } 760 761 /** 762 Passes on all arguments to the connected slot and returns the return value 763 of that slot. If no slot is connect then an exception is thrown. 764 */ 765 inline R call(A1 a1, A2 a2, A3 a3) const 766 { 767 if( !_target.valid() ) { 768 throw std::logic_error("Delegate<R,A1,A2,A3>::call(): Delegate not connected"); 769 } 770 const CallableT* cb = static_cast<const CallableT*>( _target.slot().callable() ); 771 return cb->call(a1,a2,a3); 772 } 773 774 /** 775 Passes on all arguments to the connected slot and ignores the return value. If 776 No slot is connected, the call is silently ignored. 777 */ 778 inline void invoke(A1 a1, A2 a2, A3 a3) const 779 { 780 if( !_target.valid() ) { 781 return; 782 } 783 const CallableT* cb = static_cast<const CallableT*>( _target.slot().callable() ); 784 cb->call(a1,a2,a3); 785 } 786 787 /** Identical to call(...). */ 788 R operator()(A1 a1, A2 a2, A3 a3) const 789 { return this->call(a1,a2,a3); } 790 }; 791 /** Connect a Delegate to another Delegate. 792 */ 793 template <typename R,class A1, class A2, class A3> 794 Connection connect(Delegate<R,A1,A2,A3>& delegate, Delegate<R,A1,A2,A3>& receiver) 795 { 796 return connect( delegate, slot(receiver) ); 797 } 798 799 /** Connect a Delegate to a Slot. 800 */ 801 template <typename R,class A1, class A2, class A3> 802 Connection connect(Delegate<R,A1,A2,A3>& delegate, const BasicSlot<R,A1,A2,A3>& slot) 803 { 804 return delegate.connect(slot); 805 } 806 807 808 /** Connect a Delegate to a function. 809 */ 810 template <typename R,class A1, class A2, class A3> 811 Connection connect(Delegate<R,A1,A2,A3>& delegate, R(*func)(A1,A2,A3)) 812 { 813 return connect( delegate, slot(func) ); 814 } 815 816 817 /** Connect a Delegate to a member function. 818 */ 819 template <typename R, class BaseT, class ClassT,class A1, class A2, class A3> 820 Connection connect(Delegate<R,A1,A2,A3>& delegate, BaseT& object, R(ClassT::*memFunc)(A1,A2,A3)) 821 { 822 return connect( delegate, slot(object, memFunc) ); 823 } 824 825 /** Connect a Delegate to a const member function. 826 */ 827 template <typename R, class BaseT, class ClassT,class A1, class A2, class A3> 828 Connection connect(Delegate<R>& delegate, BaseT& object, R(ClassT::*memFunc)(A1,A2,A3) const) 829 { 830 return connect( delegate, slot(object, memFunc) ); 831 } 832 833 834// END_Delegate 835// BEGIN_Delegate 2 836template < typename R,class A1, class A2> 837class Delegate<R, A1,A2,Void,Void,Void,Void,Void,Void,Void,Void> : public DelegateBase 838 { 839 public: 840 typedef Callable<R,A1,A2> CallableT; 841 842 public: 843 /** Does nothing. */ 844 Delegate() 845 { } 846 847 /** Deeply copies rhs. */ 848 Delegate(const Delegate& rhs) 849 { 850 DelegateBase::operator=(rhs); 851 } 852 853 /** Connects this object to the given slot and returns that Connection. */ 854 Connection connect(const BasicSlot<R,A1,A2>& slot) 855 { 856 return Connection(*this, slot.clone() ); 857 } 858 859 /** 860 Passes on all arguments to the connected slot and returns the return value 861 of that slot. If no slot is connect then an exception is thrown. 862 */ 863 inline R call(A1 a1, A2 a2) const 864 { 865 if( !_target.valid() ) { 866 throw std::logic_error("Delegate<R,A1,A2>::call(): Delegate not connected"); 867 } 868 const CallableT* cb = static_cast<const CallableT*>( _target.slot().callable() ); 869 return cb->call(a1,a2); 870 } 871 872 /** 873 Passes on all arguments to the connected slot and ignores the return value. If 874 No slot is connected, the call is silently ignored. 875 */ 876 inline void invoke(A1 a1, A2 a2) const 877 { 878 if( !_target.valid() ) { 879 return; 880 } 881 const CallableT* cb = static_cast<const CallableT*>( _target.slot().callable() ); 882 cb->call(a1,a2); 883 } 884 885 /** Identical to call(...). */ 886 R operator()(A1 a1, A2 a2) const 887 { return this->call(a1,a2); } 888 }; 889 /** Connect a Delegate to another Delegate. 890 */ 891 template <typename R,class A1, class A2> 892 Connection connect(Delegate<R,A1,A2>& delegate, Delegate<R,A1,A2>& receiver) 893 { 894 return connect( delegate, slot(receiver) ); 895 } 896 897 /** Connect a Delegate to a Slot. 898 */ 899 template <typename R,class A1, class A2> 900 Connection connect(Delegate<R,A1,A2>& delegate, const BasicSlot<R,A1,A2>& slot) 901 { 902 return delegate.connect(slot); 903 } 904 905 906 /** Connect a Delegate to a function. 907 */ 908 template <typename R,class A1, class A2> 909 Connection connect(Delegate<R,A1,A2>& delegate, R(*func)(A1,A2)) 910 { 911 return connect( delegate, slot(func) ); 912 } 913 914 915 /** Connect a Delegate to a member function. 916 */ 917 template <typename R, class BaseT, class ClassT,class A1, class A2> 918 Connection connect(Delegate<R,A1,A2>& delegate, BaseT& object, R(ClassT::*memFunc)(A1,A2)) 919 { 920 return connect( delegate, slot(object, memFunc) ); 921 } 922 923 /** Connect a Delegate to a const member function. 924 */ 925 template <typename R, class BaseT, class ClassT,class A1, class A2> 926 Connection connect(Delegate<R>& delegate, BaseT& object, R(ClassT::*memFunc)(A1,A2) const) 927 { 928 return connect( delegate, slot(object, memFunc) ); 929 } 930 931 932// END_Delegate 933// BEGIN_Delegate 1 934template < typename R,class A1> 935class Delegate<R, A1,Void,Void,Void,Void,Void,Void,Void,Void,Void> : public DelegateBase 936 { 937 public: 938 typedef Callable<R,A1> CallableT; 939 940 public: 941 /** Does nothing. */ 942 Delegate() 943 { } 944 945 /** Deeply copies rhs. */ 946 Delegate(const Delegate& rhs) 947 { 948 DelegateBase::operator=(rhs); 949 } 950 951 /** Connects this object to the given slot and returns that Connection. */ 952 Connection connect(const BasicSlot<R,A1>& slot) 953 { 954 return Connection(*this, slot.clone() ); 955 } 956 957 /** 958 Passes on all arguments to the connected slot and returns the return value 959 of that slot. If no slot is connect then an exception is thrown. 960 */ 961 inline R call(A1 a1) const 962 { 963 if( !_target.valid() ) { 964 throw std::logic_error("Delegate<R,A1>::call(): Delegate not connected"); 965 } 966 const CallableT* cb = static_cast<const CallableT*>( _target.slot().callable() ); 967 return cb->call(a1); 968 } 969 970 /** 971 Passes on all arguments to the connected slot and ignores the return value. If 972 No slot is connected, the call is silently ignored. 973 */ 974 inline void invoke(A1 a1) const 975 { 976 if( !_target.valid() ) { 977 return; 978 } 979 const CallableT* cb = static_cast<const CallableT*>( _target.slot().callable() ); 980 cb->call(a1); 981 } 982 983 /** Identical to call(...). */ 984 R operator()(A1 a1) const 985 { return this->call(a1); } 986 }; 987 /** Connect a Delegate to another Delegate. 988 */ 989 template <typename R,class A1> 990 Connection connect(Delegate<R,A1>& delegate, Delegate<R,A1>& receiver) 991 { 992 return connect( delegate, slot(receiver) ); 993 } 994 995 /** Connect a Delegate to a Slot. 996 */ 997 template <typename R,class A1> 998 Connection connect(Delegate<R,A1>& delegate, const BasicSlot<R,A1>& slot) 999 { 1000 return delegate.connect(slot); 1001 } 1002 1003 1004 /** Connect a Delegate to a function. 1005 */ 1006 template <typename R,class A1> 1007 Connection connect(Delegate<R,A1>& delegate, R(*func)(A1)) 1008 { 1009 return connect( delegate, slot(func) ); 1010 } 1011 1012 1013 /** Connect a Delegate to a member function. 1014 */ 1015 template <typename R, class BaseT, class ClassT,class A1> 1016 Connection connect(Delegate<R,A1>& delegate, BaseT& object, R(ClassT::*memFunc)(A1)) 1017 { 1018 return connect( delegate, slot(object, memFunc) ); 1019 } 1020 1021 /** Connect a Delegate to a const member function. 1022 */ 1023 template <typename R, class BaseT, class ClassT,class A1> 1024 Connection connect(Delegate<R>& delegate, BaseT& object, R(ClassT::*memFunc)(A1) const) 1025 { 1026 return connect( delegate, slot(object, memFunc) ); 1027 } 1028 1029 1030// END_Delegate 1031// BEGIN_Delegate 0 1032template < typename R> 1033class Delegate<R, Void,Void,Void,Void,Void,Void,Void,Void,Void,Void> : public DelegateBase 1034 { 1035 public: 1036 typedef Callable<R> CallableT; 1037 1038 public: 1039 /** Does nothing. */ 1040 Delegate() 1041 { } 1042 1043 /** Deeply copies rhs. */ 1044 Delegate(const Delegate& rhs) 1045 { 1046 DelegateBase::operator=(rhs); 1047 } 1048 1049 /** Connects this object to the given slot and returns that Connection. */ 1050 Connection connect(const BasicSlot<R>& slot) 1051 { 1052 return Connection(*this, slot.clone() ); 1053 } 1054 1055 /** 1056 Passes on all arguments to the connected slot and returns the return value 1057 of that slot. If no slot is connect then an exception is thrown. 1058 */ 1059 inline R call() const 1060 { 1061 if( !_target.valid() ) { 1062 throw std::logic_error("Delegate<R>::call(): Delegate not connected"); 1063 } 1064 const CallableT* cb = static_cast<const CallableT*>( _target.slot().callable() ); 1065 return cb->call(); 1066 } 1067 1068 /** 1069 Passes on all arguments to the connected slot and ignores the return value. If 1070 No slot is connected, the call is silently ignored. 1071 */ 1072 inline void invoke() const 1073 { 1074 if( !_target.valid() ) { 1075 return; 1076 } 1077 const CallableT* cb = static_cast<const CallableT*>( _target.slot().callable() ); 1078 cb->call(); 1079 } 1080 1081 /** Identical to call(...). */ 1082 R operator()() const 1083 { return this->call(); } 1084 }; 1085 /** Connect a Delegate to another Delegate. 1086 */ 1087 template <typename R> 1088 Connection connect(Delegate<R>& delegate, Delegate<R>& receiver) 1089 { 1090 return connect( delegate, slot(receiver) ); 1091 } 1092 1093 /** Connect a Delegate to a Slot. 1094 */ 1095 template <typename R> 1096 Connection connect(Delegate<R>& delegate, const BasicSlot<R>& slot) 1097 { 1098 return delegate.connect(slot); 1099 } 1100 1101 1102 /** Connect a Delegate to a function. 1103 */ 1104 template <typename R> 1105 Connection connect(Delegate<R>& delegate, R(*func)()) 1106 { 1107 return connect( delegate, slot(func) ); 1108 } 1109 1110 1111 /** Connect a Delegate to a member function. 1112 */ 1113 template <typename R, class BaseT, class ClassT> 1114 Connection connect(Delegate<R>& delegate, BaseT& object, R(ClassT::*memFunc)()) 1115 { 1116 return connect( delegate, slot(object, memFunc) ); 1117 } 1118 1119 /** Connect a Delegate to a const member function. 1120 */ 1121 template <typename R, class BaseT, class ClassT> 1122 Connection connect(Delegate<R>& delegate, BaseT& object, R(ClassT::*memFunc)() const) 1123 { 1124 return connect( delegate, slot(object, memFunc) ); 1125 } 1126 1127 1128// END_Delegate 1129