]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - libs/generic/callback.cpp
6152b9dcd8ea4dc32621f0b71151247736ba30aa
[xonotic/netradiant.git] / libs / generic / callback.cpp
1 /*
2 Copyright (C) 2001-2006, William Joseph.
3 All Rights Reserved.
4
5 This file is part of GtkRadiant.
6
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20 */
21
22 #include "callback.h"
23
24 #if defined(_DEBUG) || defined(DOXYGEN)
25
26 namespace ExampleMemberCaller
27 {
28   // MemberCaller example
29   class Integer
30   {
31   public:
32     int value;
33
34     void printValue() const
35     {
36       // print this->value here;
37     }
38
39     void setValue()
40     {
41       value = 3;
42     }
43     // a typedef to make things more readable
44     typedef MemberCaller<Integer, &Integer::setValue> SetValueCaller;
45   };
46
47   void example()
48   {
49     Integer foo = { 0 };
50
51     {
52       Callback bar = ConstMemberCaller<Integer, &Integer::printValue>(foo);
53
54       // invoke the callback
55       bar(); // foo.printValue()
56     }
57
58
59     {
60       // use the typedef to improve readability
61       Callback bar = Integer::SetValueCaller(foo);
62
63       // invoke the callback
64       bar(); // foo.setValue()
65     }
66   }
67   // end example
68 }
69
70 namespace ExampleReferenceCaller
71 {
72   // ReferenceCaller example
73   void Int_printValue(const int& value)
74   {
75     // print value here;
76   }
77
78   void Int_setValue(int& value)
79   {
80     value = 3;
81   }
82
83   // a typedef to make things more readable
84   typedef ReferenceCaller<int, Int_setValue> IntSetValueCaller;
85
86   void example()
87   {
88     int foo = 0;
89
90     {
91       Callback bar = ConstReferenceCaller<int, Int_printValue>(foo);
92
93       // invoke the callback
94       bar(); // Int_printValue(foo)
95     }
96
97
98     {
99       // use the typedef to improve readability
100       Callback bar = IntSetValueCaller(foo);
101
102       // invoke the callback
103       bar(); // Int_setValue(foo)
104     }
105   }
106   // end example
107 }
108
109 #endif