ordering_slots.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Ordered slots hello world example for Boost.Signals2
  2. // Copyright Douglas Gregor 2001-2004.
  3. // Copyright Frank Mori Hess 2009.
  4. //
  5. // Use, modification and
  6. // distribution is subject to the Boost Software License, Version
  7. // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt)
  9. // For more information, see http://www.boost.org
  10. #include <iostream>
  11. #include <boost/signals2/signal.hpp>
  12. struct Hello
  13. {
  14. void operator()() const
  15. {
  16. std::cout << "Hello";
  17. }
  18. };
  19. struct World
  20. {
  21. void operator()() const
  22. {
  23. std::cout << ", World!" << std::endl;
  24. }
  25. };
  26. //[ good_morning_def_code_snippet
  27. struct GoodMorning
  28. {
  29. void operator()() const
  30. {
  31. std::cout << "... and good morning!" << std::endl;
  32. }
  33. };
  34. //]
  35. int main()
  36. {
  37. //[ hello_world_ordered_code_snippet
  38. boost::signals2::signal<void ()> sig;
  39. sig.connect(1, World()); // connect with group 1
  40. sig.connect(0, Hello()); // connect with group 0
  41. //]
  42. //[ hello_world_ordered_invoke_code_snippet
  43. // by default slots are connected at the end of the slot list
  44. sig.connect(GoodMorning());
  45. // slots are invoked this order:
  46. // 1) ungrouped slots connected with boost::signals2::at_front
  47. // 2) grouped slots according to ordering of their groups
  48. // 3) ungrouped slots connected with boost::signals2::at_back
  49. sig();
  50. //]
  51. return 0;
  52. }