1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296
|
dnl Copyright 2002, The libsigc++ Development Team
dnl
dnl This library is free software; you can redistribute it and/or
dnl modify it under the terms of the GNU Lesser General Public
dnl License as published by the Free Software Foundation; either
dnl version 2.1 of the License, or (at your option) any later version.
dnl
dnl This library is distributed in the hope that it will be useful,
dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
dnl Lesser General Public License for more details.
dnl
dnl You should have received a copy of the GNU Lesser General Public
dnl License along with this library; if not, write to the Free Software
dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
dnl
divert(-1)
include(template.macros.m4)
define([SIGNAL_EMIT_N],[dnl
/** Abstracts signal emission.
* This template implements the emit() function of signal$1.
* Template specializations are available to optimize signal
* emission when no accumulator is used, for example when the template
* argument @e T_accumulator is @p nil.
*/
template <LIST(class T_return, LOOP(class T_arg%1, $1), class T_accumulator)>
struct signal_emit$1
{
typedef signal_emit$1<LIST(T_return, LOOP(T_arg%1, $1), T_accumulator)> self_type;
typedef typename T_accumulator::result_type result_type;
typedef slot<T_return(LIST(LOOP(T_arg%1, $1)))> slot_type;
typedef internal::slot_iterator_buf<self_type, T_return> slot_iterator_buf_type;
typedef internal::slot_reverse_iterator_buf<self_type, T_return> slot_reverse_iterator_buf_type;
typedef signal_impl::const_iterator_type iterator_type;
ifelse($1,0,,[dnl
/** Instantiates the class.
* The parameters are stored in member variables. operator()() passes
* the values on to some slot.
*/
])dnl
signal_emit$1(LOOP(type_trait_take_t<T_arg%1> _A_a%1, $1)) ifelse($1,0,,[
: LOOP(_A_a%1_(_A_a%1), $1)]) {}
ifelse($1,0,[dnl
/** Invokes a slot.],[
/** Invokes a slot using the buffered parameter values.])
* @param _A_slot Some slot to invoke.
* @return The slot's return value.
*/
T_return operator()(const slot_type& _A_slot) const
{ return (sigc::internal::function_pointer_cast<typename slot_type::call_type>(_A_slot.rep_->call_))(LIST(_A_slot.rep_, LOOP(_A_a%1_, $1))); }
dnl T_return operator()(const slot_type& _A_slot) const
dnl { return _A_slot(LOOP(_A_a%1_, $1)); }
/** Executes a list of slots using an accumulator of type @e T_accumulator.dnl
ifelse($1,0,,[
* The arguments are buffered in a temporary instance of signal_emit$1.])
FOR(1, $1,[
* @param _A_a%1 Argument to be passed on to the slots.])
* @return The accumulated return values of the slot invocations as processed by the accumulator.
*/
static result_type emit(LIST(signal_impl* impl, LOOP(type_trait_take_t<T_arg%1> _A_a%1, $1)))
{
T_accumulator accumulator;
if (!impl)
return accumulator(slot_iterator_buf_type(), slot_iterator_buf_type());
signal_exec exec(impl);
temp_slot_list slots(impl->slots_);
self_type self ifelse($1,0,,[(LOOP(_A_a%1, $1))]);
return accumulator(slot_iterator_buf_type(slots.begin(), &self),
slot_iterator_buf_type(slots.end(), &self));
}
_DEPRECATE_IFDEF_START
/** Executes a list of slots using an accumulator of type @e T_accumulator in reverse order.dnl
ifelse($1,0,,[
* The arguments are buffered in a temporary instance of signal_emit$1.])
FOR(1, $1,[
* @param _A_a%1 Argument to be passed on to the slots.])
* @return The accumulated return values of the slot invocations as processed by the accumulator.
*
* @deprecated This is apparently not useful, but please let us know if you need it.
*/
static result_type emit_reverse(LIST(signal_impl* impl, LOOP(type_trait_take_t<T_arg%1> _A_a%1, $1)))
{
T_accumulator accumulator;
if (!impl)
return accumulator(slot_iterator_buf_type(), slot_iterator_buf_type());
signal_exec exec(impl);
temp_slot_list slots(impl->slots_);
self_type self ifelse($1,0,,[(LOOP(_A_a%1, $1))]);
return accumulator(slot_reverse_iterator_buf_type(slots.end(), &self),
slot_reverse_iterator_buf_type(slots.begin(), &self));
}
_DEPRECATE_IFDEF_END
dnl
FOR(1, $1,[
type_trait_take_t<T_arg%1> _A_a%1_;])
};
/** Abstracts signal emission.
* This template specialization implements an optimized emit()
* function for the case that no accumulator is used.
*/
template <LIST(class T_return, LOOP(class T_arg%1, $1))>
struct signal_emit$1<LIST(T_return, LOOP(T_arg%1, $1), nil)>
{
typedef signal_emit$1<LIST(T_return, LOOP(T_arg%1, $1), nil) > self_type;
typedef T_return result_type;
typedef slot<T_return(LIST(LOOP(T_arg%1, $1)))> slot_type;
typedef signal_impl::const_iterator_type iterator_type;
typedef typename slot_type::call_type call_type;
/** Executes a list of slots using an accumulator of type @e T_accumulator.dnl
ifelse($1,0,,[
* The arguments are passed directly on to the slots.])
* The return value of the last slot invoked is returned.
* @param first An iterator pointing to the first slot in the list.
* @param last An iterator pointing to the last slot in the list.dnl
FOR(1, $1,[
* @param _A_a%1 Argument to be passed on to the slots.])
* @return The return value of the last slot invoked.
*/
static result_type emit(LIST(signal_impl* impl, LOOP(type_trait_take_t<T_arg%1> _A_a%1, $1)))
{
if (!impl || impl->slots_.empty())
return T_return();
signal_exec exec(impl);
T_return r_ = T_return();
//Use this scope to make sure that "slots" is destroyed before "exec" is destroyed.
//This avoids a leak on MSVC++ - see http://bugzilla.gnome.org/show_bug.cgi?id=306249
{
temp_slot_list slots(impl->slots_);
auto it = slots.begin();
for (; it != slots.end(); ++it)
if (!it->empty() && !it->blocked()) break;
if (it == slots.end())
return T_return(); // note that 'T_return r_();' doesn't work => define 'r_' after this line and initialize as follows:
r_ = (sigc::internal::function_pointer_cast<call_type>(it->rep_->call_))(LIST(it->rep_, LOOP(_A_a%1, $1)));
for (++it; it != slots.end(); ++it)
{
if (it->empty() || it->blocked())
continue;
r_ = (sigc::internal::function_pointer_cast<call_type>(it->rep_->call_))(LIST(it->rep_, LOOP(_A_a%1, $1)));
}
}
return r_;
}
_DEPRECATE_IFDEF_START
/** Executes a list of slots using an accumulator of type @e T_accumulator in reverse order.dnl
ifelse($1,0,,[
* The arguments are passed directly on to the slots.])
* The return value of the last slot invoked is returned.
* @param first An iterator pointing to the first slot in the list.
* @param last An iterator pointing to the last slot in the list.dnl
FOR(1, $1,[
* @param _A_a%1 Argument to be passed on to the slots.])
* @return The return value of the last slot invoked.
*
* @deprecated This is apparently not useful, but please let us know if you need it.
*/
static result_type emit_reverse(LIST(signal_impl* impl, LOOP(type_trait_take_t<T_arg%1> _A_a%1, $1)))
{
if (!impl || impl->slots_.empty())
return T_return();
signal_exec exec(impl);
T_return r_ = T_return();
//Use this scope to make sure that "slots" is destroyed before "exec" is destroyed.
//This avoids a leak on MSVC++ - see http://bugzilla.gnome.org/show_bug.cgi?id=306249
{
#ifndef SIGC_HAVE_SUN_REVERSE_ITERATOR
typedef std::reverse_iterator<signal_impl::iterator_type> reverse_iterator_type;
#else
typedef std::reverse_iterator<signal_impl::iterator_type, std::random_access_iterator_tag,
slot_base, slot_base&, slot_base*, std::ptrdiff_t> reverse_iterator_type;
#endif
temp_slot_list slots(impl->slots_);
reverse_iterator_type it(slots.end());
for (; it != reverse_iterator_type(slots.begin()); ++it)
if (!it->empty() && !it->blocked()) break;
if (it == reverse_iterator_type(slots.begin()))
return T_return(); // note that 'T_return r_();' doesn't work => define 'r_' after this line and initialize as follows:
r_ = (sigc::internal::function_pointer_cast<call_type>(it->rep_->call_))(LIST(it->rep_, LOOP(_A_a%1, $1)));
for (++it; it != reverse_iterator_type(slots.begin()); ++it)
{
if (it->empty() || it->blocked())
continue;
r_ = (sigc::internal::function_pointer_cast<call_type>(it->rep_->call_))(LIST(it->rep_, LOOP(_A_a%1, $1)));
}
}
return r_;
}
_DEPRECATE_IFDEF_END
};
/** Abstracts signal emission.
* This template specialization implements an optimized emit()
* function for the case that no accumulator is used and the
* return type is @p void.
*/
template <LOOP(class T_arg%1, $1)>
struct signal_emit$1<LIST(void, LOOP(T_arg%1, $1), nil)>
{
typedef signal_emit$1<LIST(void, LOOP(T_arg%1, $1), nil)> self_type;
typedef void result_type;
typedef slot<void(LIST(LOOP(T_arg%1, $1)))> slot_type;
typedef signal_impl::const_iterator_type iterator_type;
typedef ifelse($1,0,void (*call_type)(slot_rep*),typename slot_type::call_type call_type);
/** Executes a list of slots using an accumulator of type @e T_accumulator.dnl
ifelse($1,0,,[
* The arguments are passed directly on to the slots.])
* @param first An iterator pointing to the first slot in the list.
* @param last An iterator pointing to the last slot in the list.dnl
FOR(1, $1,[
* @param _A_a%1 Argument to be passed on to the slots.])
*/
static result_type emit(LIST(signal_impl* impl, LOOP(type_trait_take_t<T_arg%1> _A_a%1, $1)))
{
if (!impl || impl->slots_.empty()) return;
signal_exec exec(impl);
temp_slot_list slots(impl->slots_);
for (const auto& slot : slots)
{
if (slot.empty() || slot.blocked())
continue;
(sigc::internal::function_pointer_cast<call_type>(slot.rep_->call_))(LIST(slot.rep_, LOOP(_A_a%1, $1)));
}
}
_DEPRECATE_IFDEF_START
/** Executes a list of slots using an accumulator of type @e T_accumulator in reverse order.dnl
ifelse($1,0,,[
* The arguments are passed directly on to the slots.])
* @param first An iterator pointing to the first slot in the list.
* @param last An iterator pointing to the last slot in the list.dnl
FOR(1, $1,[
* @param _A_a%1 Argument to be passed on to the slots.])
*
* @deprecated This is apparently not useful, but please let us know if you need it.
*/
static result_type emit_reverse(LIST(signal_impl* impl, LOOP(type_trait_take_t<T_arg%1> _A_a%1, $1)))
{
if (!impl || impl->slots_.empty()) return;
signal_exec exec(impl);
temp_slot_list slots(impl->slots_);
#ifndef SIGC_HAVE_SUN_REVERSE_ITERATOR
typedef std::reverse_iterator<signal_impl::iterator_type> reverse_iterator_type;
#else
typedef std::reverse_iterator<signal_impl::iterator_type, std::random_access_iterator_tag,
slot_base, slot_base&, slot_base*, std::ptrdiff_t> reverse_iterator_type;
#endif
for (auto it = reverse_iterator_type(slots.end()); it != reverse_iterator_type(slots.begin()); ++it)
{
if (it->empty() || it->blocked())
continue;
(sigc::internal::function_pointer_cast<call_type>(it->rep_->call_))(LIST(it->rep_, LOOP(_A_a%1, $1)));
}
}
_DEPRECATE_IFDEF_END
};
])
define([SIGNAL_N],[dnl
/** Signal declaration.
* signal$1 can be used to connect() slots that are invoked
* during subsequent calls to emit(). Any functor or slot
* can be passed into connect(). It is converted into a slot
* implicitly.
*
* If you want to connect one signal to another, use make_slot()
* to retrieve a functor that emits the signal when invoked.
*
* Be careful if you directly pass one signal into the connect()
* method of another: a shallow copy of the signal is made and
* the signal's slots are not disconnected until both the signal
* and its clone are destroyed, which is probably not what you want.
*
* The following template arguments are used:
* - @e T_return The desired return type for the emit() function (may be overridden by the accumulator).dnl
FOR(1,$1,[
* - @e T_arg%1 Argument type used in the definition of emit().])
* - @e T_accumulator The accumulator type used for emission. The default
* @p nil means that no accumulator should be used, for example if signal
* emission returns the return value of the last slot invoked.
*
* You should use the more convenient unnumbered sigc::signal template.
*
* @ingroup signal
*/
template <LIST(class T_return, LOOP(class T_arg%1, $1), class T_accumulator=nil)>
class signal$1
: public signal_base
{
public:
typedef internal::signal_emit$1<LIST(T_return, LOOP(T_arg%1, $1), T_accumulator)> emitter_type;
typedef typename emitter_type::result_type result_type;
typedef slot<T_return(LIST(LOOP(T_arg%1, $1)))> slot_type;
typedef slot_list<slot_type> slot_list_type;
typedef typename slot_list_type::iterator iterator;
typedef typename slot_list_type::const_iterator const_iterator;
typedef typename slot_list_type::reverse_iterator reverse_iterator;
typedef typename slot_list_type::const_reverse_iterator const_reverse_iterator;
/** Add a slot to the list of slots.
* Any functor or slot may be passed into connect().
* It will be converted into a slot implicitly.
* The returned iterator may be stored for disconnection
* of the slot at some later point. It stays valid until
* the slot is removed from the list of slots. The iterator
* can also be implicitly converted into a sigc::connection object
* that may be used safely beyond the life time of the slot.
*
* std::function<> and C++11 lambda expressions are functors.
* These are examples of functors that can be connected to a signal.
*
* %std::bind() creates a functor, but this functor typically has an
* %operator()() which is a variadic template.
* Our functor_trait can't deduce the result type
* of such a functor. If you first assign the return value of %std::bind()
* to a std::function, you can connect the std::function to a signal.
*
* @param slot_ The slot to add to the list of slots.
* @return An iterator pointing to the new slot in the list.
*/
iterator connect(const slot_type& slot_)
{ return iterator(signal_base::connect(static_cast<const slot_base&>(slot_))); }
/** Add a slot to the list of slots.
* @see connect(const slot_type& slot_).
*
* @newin{2,8}
*/
iterator connect(slot_type&& slot_)
{ return iterator(signal_base::connect(std::move(static_cast<slot_base&>(slot_)))); }
/** Triggers the emission of the signal.
* During signal emission all slots that have been connected
* to the signal are invoked unless they are manually set into
* a blocking state. The parameters are passed on to the slots.
* If @e T_accumulated is not @p nil, an accumulator of this type
* is used to process the return values of the slot invocations.
* Otherwise, the return value of the last slot invoked is returned.dnl
FOR(1, $1,[
* @param _A_a%1 Argument to be passed on to the slots.])
* @return The accumulated return values of the slot invocations.
*/
result_type emit(LOOP(type_trait_take_t<T_arg%1> _A_a%1, $1)) const
{ return emitter_type::emit(LIST(impl_, LOOP(_A_a%1, $1))); }
_DEPRECATE_IFDEF_START
/** Triggers the emission of the signal in reverse order (see emit()).
*
* @deprecated This is apparently not useful, but please let us know if you need it.
*/
result_type emit_reverse(LOOP(type_trait_take_t<T_arg%1> _A_a%1, $1)) const
{ return emitter_type::emit_reverse(LIST(impl_, LOOP(_A_a%1, $1))); }
_DEPRECATE_IFDEF_END
/** Triggers the emission of the signal (see emit()).
*
* @deprecated This is apparently not useful, but let us know if you need it.
*/
result_type operator()(LOOP(type_trait_take_t<T_arg%1> _A_a%1, $1)) const
{ return emit(LOOP(_A_a%1, $1)); }
/** Creates a functor that calls emit() on this signal.
* @code
* sigc::mem_fun(mysignal, &sigc::signal$1::emit)
* @endcode
* yields the same result.
* @return A functor that calls emit() on this signal.
*/
bound_const_mem_functor$1<LIST(result_type, signal$1, LOOP(type_trait_take_t<T_arg%1>, $1))> make_slot() const
{ return bound_const_mem_functor$1<LIST(result_type, signal$1, LOOP(type_trait_take_t<T_arg%1>, $1))>(*this, &signal$1::emit); }
_DEPRECATE_IFDEF_START
/** Creates an STL-style interface for the signal's list of slots.
* This interface supports iteration, insertion and removal of slots.
* @return An STL-style interface for the signal's list of slots.
*
* @deprecated This is apparently not useful, but please let us know if you need it.
*/
slot_list_type slots()
{ return slot_list_type(impl()); }
/** Creates an STL-style interface for the signal's list of slots.
* This interface supports iteration, insertion and removal of slots.
* @return An STL-style interface for the signal's list of slots.
*
* @deprecated This is apparently not useful, but please let us know if you need it.
*/
const slot_list_type slots() const
{ return slot_list_type(const_cast<signal$1*>(this)->impl()); }
_DEPRECATE_IFDEF_END
signal$1() {}
signal$1(const signal$1& src)
: signal_base(src) {}
signal$1(signal$1&& src)
: signal_base(std::move(src)) {}
signal$1& operator=(const signal$1& src)
{
signal_base::operator=(src);
return *this;
}
signal$1& operator=(signal$1&& src)
{
signal_base::operator=(std::move(src));
return *this;
}
};
])
define([SIGNAL],[dnl
ifelse($1, $2,[dnl
/** Convenience wrapper for the numbered sigc::signal# templates.
* signal can be used to connect() slots that are invoked
* during subsequent calls to emit(). Any functor or slot
* can be passed into connect(). It is converted into a slot
* implicitly.
*
* If you want to connect one signal to another, use make_slot()
* to retrieve a functor that emits the signal when invoked.
*
* Be careful if you directly pass one signal into the connect()
* method of another: a shallow copy of the signal is made and
* the signal's slots are not disconnected until both the signal
* and its clone are destroyed, which is probably not what you want!
*
* The template arguments determine the function signature of
* the emit() function:
* - @e T_return The desired return type of the emit() function.dnl
FOR(1,$1,[
* - @e T_arg%1 Argument type used in the definition of emit(). The default @p nil means no argument.])
*
* To specify an accumulator type the nested class signal::accumulated can be used.
*
* @par Example:
* @code
* void foo(int) {}
* sigc::signal<void, long> sig;
* sig.connect(sigc::ptr_fun(&foo));
* sig.emit(19);
* @endcode
*
* @deprecated Please use the syntax similar to that used by std::function<>:
* @code
* sigc::slot<void(bool, int)> some_slot;
* @endcode
*
* @ingroup signal
*/
template <LIST(class T_return, LOOP(class T_arg%1 = nil, $1))>
class signal],[dnl
/** Convenience wrapper for the numbered sigc::signal$1 template.
* See the base class for useful methods.
* This is the template specialization of the unnumbered sigc::signal
* template for $1 argument(s).
*
* @deprecated Please use the syntax similar to that used by std::function<>:
* @code
* sigc::slot<void(bool, int)> some_slot;
* @endcode
ifelse($1, $2,[dnl
*
* @ingroup signal
])dnl
*/
template <LIST(class T_return, LOOP(class T_arg%1, $1))>
class signal ifelse($1, $2,,[<LIST(T_return, LOOP(T_arg%1,$1), LOOP(nil, CALL_SIZE - $1))>])])
: public signal$1<LIST(T_return, LOOP(T_arg%1, $1),nil)>
{
public:
ifelse($1, $2,[dnl
/** Convenience wrapper for the numbered sigc::signal# templates.
* Like sigc::signal but the additional template parameter @e T_accumulator
* defines the accumulator type that should be used.
*
* An accumulator is a functor that uses a pair of special iterators
* to step through a list of slots and calculate a return value
* from the results of the slot invokations. The iterators' operator*()
* executes the slot. The return value is buffered, so that in an expression
* like @code a = (*i) * (*i); @endcode the slot is executed only once.
* The accumulator must define its return value as @p result_type.
*
* @par Example 1:
* This accumulator calculates the arithmetic mean value:
* @code
* struct arithmetic_mean_accumulator
* {
* typedef double result_type;
* template<typename T_iterator>
* result_type operator()(T_iterator first, T_iterator last) const
* {
* result_type value_ = 0;
* int n_ = 0;
* for (; first != last; ++first, ++n_)
* value_ += *first;
* return value_ / n_;
* }
* };
* @endcode
*
* @par Example 2:
* This accumulator stops signal emission when a slot returns zero:
* @code
* struct interruptable_accumulator
* {
* typedef bool result_type;
* template<typename T_iterator>
* result_type operator()(T_iterator first, T_iterator last) const
* {
* for (; first != last; ++first, ++n_)
* if (!*first) return false;
* return true;
* }
* };
* @endcode
*
* @ingroup signal
],[
/** Convenience wrapper for the numbered sigc::signal$1 template.
* Like sigc::signal but the additional template parameter @e T_accumulator
* defines the accumulator type that should be used.
])dnl
*/
template <class T_accumulator>
class accumulated
: public signal$1<LIST(T_return, LOOP(T_arg%1, $1), T_accumulator)>
{
public:
accumulated() {}
accumulated(const accumulated& src)
: signal$1<LIST(T_return, LOOP(T_arg%1, $1), T_accumulator)>(src) {}
};
signal() {}
signal(const signal& src)
: signal$1<LIST(T_return, LOOP(T_arg%1, $1),nil)>(src) {}
signal(signal&& src)
: signal$1<LIST(T_return, LOOP(T_arg%1, $1),nil)>(std::move(src)) {}
signal& operator=(const signal& src)
{
signal$1<LIST(T_return, LOOP(T_arg%1, $1),nil)>::operator=(src);
return *this;
}
signal& operator=(signal&& src)
{
signal$1<LIST(T_return, LOOP(T_arg%1, $1),nil)>::operator=(std::move(src));
return *this;
}
};
/**
* This specialization allow use of the sigc::signal<R(Args...)> syntax,
*/
template <LIST(class T_return, LOOP(class T_arg%1, $1))>
class signal<T_return(LIST(LOOP(T_arg%1, $1)))>
: public signal$1<LIST(T_return, LOOP(T_arg%1, $1),nil)>
{
public:
ifelse($1, $2,[dnl
/** Convenience wrapper for the numbered sigc::signal# templates.
* Like sigc::signal but the additional template parameter @e T_accumulator
* defines the accumulator type that should be used.
*
* An accumulator is a functor that uses a pair of special iterators
* to step through a list of slots and calculate a return value
* from the results of the slot invokations. The iterators' operator*()
* executes the slot. The return value is buffered, so that in an expression
* like @code a = (*i) * (*i); @endcode the slot is executed only once.
* The accumulator must define its return value as @p result_type.
*
* @par Example 1:
* This accumulator calculates the arithmetic mean value:
* @code
* struct arithmetic_mean_accumulator
* {
* typedef double result_type;
* template<typename T_iterator>
* result_type operator()(T_iterator first, T_iterator last) const
* {
* result_type value_ = 0;
* int n_ = 0;
* for (; first != last; ++first, ++n_)
* value_ += *first;
* return value_ / n_;
* }
* };
* @endcode
*
* @par Example 2:
* This accumulator stops signal emission when a slot returns zero:
* @code
* struct interruptable_accumulator
* {
* typedef bool result_type;
* template<typename T_iterator>
* result_type operator()(T_iterator first, T_iterator last) const
* {
* for (; first != last; ++first, ++n_)
* if (!*first) return false;
* return true;
* }
* };
* @endcode
*
* @ingroup signal
],[
/** Convenience wrapper for the numbered sigc::signal$1 template.
* Like sigc::signal but the additional template parameter @e T_accumulator
* defines the accumulator type that should be used.
])dnl
*/
template <class T_accumulator>
class accumulated
: public signal$1<LIST(T_return, LOOP(T_arg%1, $1), T_accumulator)>
{
public:
accumulated() {}
accumulated(const accumulated& src)
: signal$1<LIST(T_return, LOOP(T_arg%1, $1), T_accumulator)>(src) {}
};
signal() {}
signal(const signal& src)
: signal$1<LIST(T_return, LOOP(T_arg%1, $1),nil)>(src) {}
signal(signal&& src)
: signal$1<LIST(T_return, LOOP(T_arg%1, $1),nil)>(std::move(src)) {}
signal& operator=(const signal& src)
{
signal$1<LIST(T_return, LOOP(T_arg%1, $1),nil)>::operator=(src);
return *this;
}
signal& operator=(signal&& src)
{
signal$1<LIST(T_return, LOOP(T_arg%1, $1),nil)>::operator=(std::move(src));
return *this;
}
};
])
divert(0)
#ifndef _SIGC_SIGNAL_H_
#define _SIGC_SIGNAL_H_
#include <list>
#include <sigc++/signal_base.h>
#include <sigc++/type_traits.h>
#include <sigc++/trackable.h>
#include <sigc++/functors/slot.h>
#include <sigc++/functors/mem_fun.h>
//TODO: See comment in functor_trait.h.
#if defined(nil) && defined(SIGC_PRAGMA_PUSH_POP_MACRO)
#define SIGC_NIL_HAS_BEEN_PUSHED 1
#pragma push_macro("nil")
#undef nil
#endif
//SIGC_TYPEDEF_REDEFINE_ALLOWED:
// TODO: This should have its own test, but I can not create one that gives the error instead of just a warning. murrayc.
// I have just used this because there is a correlation between these two problems.
#ifdef SIGC_TEMPLATE_SPECIALIZATION_OPERATOR_OVERLOAD
//Compilers, such as older versions of SUN Forte C++, that do not allow this also often
//do not allow a typedef to have the same name as a class in the typedef's definition.
//For Sun Forte CC 5.7 (SUN Workshop 10), comment this out to fix the build.
//
// Debian-specific patch: gcc-4.3 does not allow this either, and the
// comments below say this is a backwards-compatibility typedef, so
// just don't enable this feature at all.
//#define SIGC_TYPEDEF_REDEFINE_ALLOWED 1
#endif
namespace sigc {
/** STL-style iterator for slot_list.
*
* @ingroup signal
*/
template <typename T_slot>
struct slot_iterator
{
typedef std::size_t size_type;
typedef std::ptrdiff_t difference_type;
typedef std::bidirectional_iterator_tag iterator_category;
typedef T_slot slot_type;
typedef T_slot value_type;
typedef T_slot* pointer;
typedef T_slot& reference;
typedef typename internal::signal_impl::iterator_type iterator_type;
slot_iterator()
{}
explicit slot_iterator(const iterator_type& i)
: i_(i) {}
reference operator*() const
{ return static_cast<reference>(*i_); }
pointer operator->() const
{ return &(operator*()); }
slot_iterator& operator++()
{
++i_;
return *this;
}
slot_iterator operator++(int)
{
slot_iterator __tmp(*this);
++i_;
return __tmp;
}
slot_iterator& operator--()
{
--i_;
return *this;
}
slot_iterator operator--(int)
{
slot_iterator __tmp(*this);
--i_;
return __tmp;
}
bool operator == (const slot_iterator& other) const
{ return i_ == other.i_; }
bool operator != (const slot_iterator& other) const
{ return i_ != other.i_; }
iterator_type i_;
};
/** STL-style const iterator for slot_list.
*
* @ingroup signal
*/
template <typename T_slot>
struct slot_const_iterator
{
typedef std::size_t size_type;
typedef std::ptrdiff_t difference_type;
typedef std::bidirectional_iterator_tag iterator_category;
typedef T_slot slot_type;
typedef T_slot value_type;
typedef const T_slot* pointer;
typedef const T_slot& reference;
typedef typename internal::signal_impl::const_iterator_type iterator_type;
slot_const_iterator()
{}
explicit slot_const_iterator(const iterator_type& i)
: i_(i) {}
reference operator*() const
{ return static_cast<reference>(*i_); }
pointer operator->() const
{ return &(operator*()); }
slot_const_iterator& operator++()
{
++i_;
return *this;
}
slot_const_iterator operator++(int)
{
slot_const_iterator __tmp(*this);
++i_;
return __tmp;
}
slot_const_iterator& operator--()
{
--i_;
return *this;
}
slot_const_iterator operator--(int)
{
slot_const_iterator __tmp(*this);
--i_;
return __tmp;
}
bool operator == (const slot_const_iterator& other) const
{ return i_ == other.i_; }
bool operator != (const slot_const_iterator& other) const
{ return i_ != other.i_; }
iterator_type i_;
};
/** STL-style list interface for sigc::signal#.
* slot_list can be used to iterate over the list of slots that
* is managed by a signal. Slots can be added or removed from
* the list while existing iterators stay valid.
*
* @ingroup signal
*/
template <class T_slot>
struct slot_list
{
typedef T_slot slot_type;
typedef slot_type& reference;
typedef const slot_type& const_reference;
typedef slot_iterator<slot_type> iterator;
typedef slot_const_iterator<slot_type> const_iterator;
#ifndef SIGC_HAVE_SUN_REVERSE_ITERATOR
typedef std::reverse_iterator<iterator> reverse_iterator;
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
#else
typedef std::reverse_iterator<iterator, std::random_access_iterator_tag,
int, int&, int*, std::ptrdiff_t> reverse_iterator;
typedef std::reverse_iterator<const_iterator, std::random_access_iterator_tag,
int, const int&, const int*, std::ptrdiff_t> const_reverse_iterator;
#endif /* SIGC_HAVE_SUN_REVERSE_ITERATOR */
slot_list()
: list_(nullptr) {}
explicit slot_list(internal::signal_impl* __list)
: list_(__list) {}
iterator begin()
{ return iterator(list_->slots_.begin()); }
const_iterator begin() const
{ return const_iterator(list_->slots_.begin()); }
iterator end()
{ return iterator(list_->slots_.end()); }
const_iterator end() const
{ return const_iterator(list_->slots_.end()); }
reverse_iterator rbegin()
{ return reverse_iterator(end()); }
const_reverse_iterator rbegin() const
{ return const_reverse_iterator(end()); }
reverse_iterator rend()
{ return reverse_iterator(begin()); }
const_reverse_iterator rend() const
{ return const_reverse_iterator(begin()); }
reference front()
{ return *begin(); }
const_reference front() const
{ return *begin(); }
reference back()
{ return *(--end()); }
const_reference back() const
{ return *(--end()); }
iterator insert(iterator i, const slot_type& slot_)
{ return iterator(list_->insert(i.i_, static_cast<const slot_base&>(slot_))); }
iterator insert(iterator i, slot_type&& slot_)
{ return iterator(list_->insert(i.i_, std::move(static_cast<slot_base&>(slot_)))); }
void push_front(const slot_type& c)
{ insert(begin(), c); }
void push_front(slot_type&& c)
{ insert(begin(), std::move(c)); }
void push_back(const slot_type& c)
{ insert(end(), c); }
void push_back(slot_type&& c)
{ insert(end(), std::move(c)); }
iterator erase(iterator i)
{ return iterator(list_->erase(i.i_)); }
iterator erase(iterator first_, iterator last_)
{
while (first_ != last_)
first_ = erase(first_);
return last_;
}
void pop_front()
{ erase(begin()); }
void pop_back()
{
auto tmp_ = end();
erase(--tmp_);
}
protected:
internal::signal_impl* list_;
};
namespace internal {
/** Special iterator over sigc::internal::signal_impl's slot list that holds extra data.
* This iterators is for use in accumulators. operator*() executes
* the slot. The return value is buffered, so that in an expression
* like @code a = (*i) * (*i); @endcode the slot is executed only once.
*/
template <class T_emitter, class T_result = typename T_emitter::result_type>
struct slot_iterator_buf
{
typedef std::size_t size_type;
typedef std::ptrdiff_t difference_type;
typedef std::bidirectional_iterator_tag iterator_category;
//These are needed just to make this a proper C++ iterator,
//that can be used with standard C++ algorithms.
typedef T_result value_type;
typedef T_result& reference;
typedef T_result* pointer;
typedef T_emitter emitter_type;
typedef T_result result_type;
typedef typename T_emitter::slot_type slot_type;
typedef signal_impl::const_iterator_type iterator_type;
slot_iterator_buf()
: c_(nullptr), invoked_(false) {}
slot_iterator_buf(const iterator_type& i, const emitter_type* c)
: i_(i), c_(c), invoked_(false) {}
result_type operator*() const
{
if (!i_->empty() && !i_->blocked() && !invoked_)
{
r_ = (*c_)(static_cast<const slot_type&>(*i_));
invoked_ = true;
}
return r_;
}
slot_iterator_buf& operator++()
{
++i_;
invoked_ = false;
return *this;
}
slot_iterator_buf operator++(int)
{
slot_iterator_buf __tmp(*this);
++i_;
invoked_ = false;
return __tmp;
}
slot_iterator_buf& operator--()
{
--i_;
invoked_ = false;
return *this;
}
slot_iterator_buf operator--(int)
{
slot_iterator_buf __tmp(*this);
--i_;
invoked_ = false;
return __tmp;
}
bool operator == (const slot_iterator_buf& other) const
{ return (!c_ || (i_ == other.i_)); } /* If '!c_' the iterators are empty.
* Unfortunately, empty stl iterators are not equal.
* We are forcing equality so that 'first==last'
* in the accumulator's emit function yields true. */
bool operator != (const slot_iterator_buf& other) const
{ return (c_ && (i_ != other.i_)); }
private:
iterator_type i_;
const emitter_type* c_;
mutable result_type r_;
mutable bool invoked_;
};
/** Template specialization of slot_iterator_buf for void return signals.
*/
template <class T_emitter>
struct slot_iterator_buf<T_emitter, void>
{
typedef std::size_t size_type;
typedef std::ptrdiff_t difference_type;
typedef std::bidirectional_iterator_tag iterator_category;
typedef T_emitter emitter_type;
typedef void result_type;
typedef typename T_emitter::slot_type slot_type;
typedef signal_impl::const_iterator_type iterator_type;
slot_iterator_buf()
: c_(nullptr), invoked_(false) {}
slot_iterator_buf(const iterator_type& i, const emitter_type* c)
: i_(i), c_(c), invoked_(false) {}
void operator*() const
{
if (!i_->empty() && !i_->blocked() && !invoked_)
{
(*c_)(static_cast<const slot_type&>(*i_));
invoked_ = true;
}
}
slot_iterator_buf& operator++()
{
++i_;
invoked_ = false;
return *this;
}
slot_iterator_buf operator++(int)
{
slot_iterator_buf __tmp(*this);
++i_;
invoked_ = false;
return __tmp;
}
slot_iterator_buf& operator--()
{
--i_;
invoked_ = false;
return *this;
}
slot_iterator_buf operator--(int)
{
slot_iterator_buf __tmp(*this);
--i_;
invoked_ = false;
return __tmp;
}
bool operator == (const slot_iterator_buf& other) const
{ return i_ == other.i_; }
bool operator != (const slot_iterator_buf& other) const
{ return i_ != other.i_; }
private:
iterator_type i_;
const emitter_type* c_;
mutable bool invoked_;
};
/** Reverse version of sigc::internal::slot_iterator_buf. */
template <class T_emitter, class T_result = typename T_emitter::result_type>
struct slot_reverse_iterator_buf
{
typedef std::size_t size_type;
typedef std::ptrdiff_t difference_type;
typedef std::bidirectional_iterator_tag iterator_category;
//These are needed just to make this a proper C++ iterator,
//that can be used with standard C++ algorithms.
typedef T_result value_type;
typedef T_result& reference;
typedef T_result* pointer;
typedef T_emitter emitter_type;
typedef T_result result_type;
typedef typename T_emitter::slot_type slot_type;
typedef signal_impl::const_iterator_type iterator_type;
slot_reverse_iterator_buf()
: c_(nullptr), invoked_(false) {}
slot_reverse_iterator_buf(const iterator_type& i, const emitter_type* c)
: i_(i), c_(c), invoked_(false) {}
result_type operator*() const
{
auto __tmp(i_);
--__tmp;
if (!__tmp->empty() && !__tmp->blocked() && !invoked_)
{
r_ = (*c_)(static_cast<const slot_type&>(*__tmp));
invoked_ = true;
}
return r_;
}
slot_reverse_iterator_buf& operator++()
{
--i_;
invoked_ = false;
return *this;
}
slot_reverse_iterator_buf operator++(int)
{
slot_reverse_iterator_buf __tmp(*this);
--i_;
invoked_ = false;
return __tmp;
}
slot_reverse_iterator_buf& operator--()
{
++i_;
invoked_ = false;
return *this;
}
slot_reverse_iterator_buf operator--(int)
{
slot_reverse_iterator_buf __tmp(*this);
++i_;
invoked_ = false;
return __tmp;
}
bool operator == (const slot_reverse_iterator_buf& other) const
{ return (!c_ || (i_ == other.i_)); } /* If '!c_' the iterators are empty.
* Unfortunately, empty stl iterators are not equal.
* We are forcing equality so that 'first==last'
* in the accumulator's emit function yields true. */
bool operator != (const slot_reverse_iterator_buf& other) const
{ return (c_ && (i_ != other.i_)); }
private:
iterator_type i_;
const emitter_type* c_;
mutable result_type r_;
mutable bool invoked_;
};
/** Template specialization of slot_reverse_iterator_buf for void return signals.
*/
template <class T_emitter>
struct slot_reverse_iterator_buf<T_emitter, void>
{
typedef std::size_t size_type;
typedef std::ptrdiff_t difference_type;
typedef std::bidirectional_iterator_tag iterator_category;
typedef T_emitter emitter_type;
typedef void result_type;
typedef typename T_emitter::slot_type slot_type;
typedef signal_impl::const_iterator_type iterator_type;
slot_reverse_iterator_buf()
: c_(nullptr), invoked_(false) {}
slot_reverse_iterator_buf(const iterator_type& i, const emitter_type* c)
: i_(i), c_(c), invoked_(false) {}
void operator*() const
{
auto __tmp(i_);
--__tmp;
if (!__tmp->empty() && !__tmp->blocked() && !invoked_)
{
(*c_)(static_cast<const slot_type&>(*__tmp));
invoked_ = true;
}
}
slot_reverse_iterator_buf& operator++()
{
--i_;
invoked_ = false;
return *this;
}
slot_reverse_iterator_buf operator++(int)
{
slot_reverse_iterator_buf __tmp(*this);
--i_;
invoked_ = false;
return __tmp;
}
slot_reverse_iterator_buf& operator--()
{
++i_;
invoked_ = false;
return *this;
}
slot_reverse_iterator_buf operator--(int)
{
slot_reverse_iterator_buf __tmp(*this);
++i_;
invoked_ = false;
return __tmp;
}
bool operator == (const slot_reverse_iterator_buf& other) const
{ return i_ == other.i_; }
bool operator != (const slot_reverse_iterator_buf& other) const
{ return i_ != other.i_; }
private:
iterator_type i_;
const emitter_type* c_;
mutable bool invoked_;
};
FOR(0,CALL_SIZE,[[SIGNAL_EMIT_N(%1)]])
} /* namespace internal */
FOR(0,CALL_SIZE,[[SIGNAL_N(%1)]])
SIGNAL(CALL_SIZE,CALL_SIZE)
FOR(0,eval(CALL_SIZE-1),[[SIGNAL(%1)]])
} /* namespace sigc */
#ifdef SIGC_NIL_HAS_BEEN_PUSHED
#undef SIGC_NIL_HAS_BEEN_PUSHED
#pragma pop_macro("nil")
#endif
#endif /* _SIGC_SIGNAL_H_ */
|