• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
11 #include <iostream>
12 #include <boost/signals2/signal.hpp>
13 
14 struct Hello
15 {
operator ()Hello16   void operator()() const
17   {
18     std::cout << "Hello";
19   }
20 };
21 
22 struct World
23 {
operator ()World24   void operator()() const
25   {
26     std::cout << ", World!" << std::endl;
27   }
28 };
29 
30 //[ good_morning_def_code_snippet
31 struct GoodMorning
32 {
operator ()GoodMorning33   void operator()() const
34   {
35     std::cout << "... and good morning!" << std::endl;
36   }
37 };
38 //]
39 
main()40 int main()
41 {
42 //[ hello_world_ordered_code_snippet
43   boost::signals2::signal<void ()> sig;
44 
45   sig.connect(1, World());  // connect with group 1
46   sig.connect(0, Hello());  // connect with group 0
47 //]
48 
49 //[ hello_world_ordered_invoke_code_snippet
50   // by default slots are connected at the end of the slot list
51   sig.connect(GoodMorning());
52 
53   // slots are invoked this order:
54   // 1) ungrouped slots connected with boost::signals2::at_front
55   // 2) grouped slots according to ordering of their groups
56   // 3) ungrouped slots connected with boost::signals2::at_back
57   sig();
58 //]
59 
60   return 0;
61 }
62 
63