2 Copyright (C) 2001-2006, William Joseph.
5 This file is part of GtkRadiant.
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.
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.
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
24 #if defined( _DEBUG ) || defined( DOXYGEN )
26 namespace ExampleMemberCaller
28 // MemberCaller example
34 void printValue() const {
35 // print this->value here;
41 // a typedef to make things more readable
42 typedef MemberCaller<Integer, &Integer::setValue> SetValueCaller;
49 Callback bar = ConstMemberCaller<Integer, &Integer::printValue>( foo );
51 // invoke the callback
52 bar(); // foo.printValue()
57 // use the typedef to improve readability
58 Callback bar = Integer::SetValueCaller( foo );
60 // invoke the callback
61 bar(); // foo.setValue()
67 namespace ExampleReferenceCaller
69 // ReferenceCaller example
70 void Int_printValue( const int& value ){
74 void Int_setValue( int& value ){
78 // a typedef to make things more readable
79 typedef ReferenceCaller<int, Int_setValue> IntSetValueCaller;
85 Callback bar = ConstReferenceCaller<int, Int_printValue>( foo );
87 // invoke the callback
88 bar(); // Int_printValue(foo)
93 // use the typedef to improve readability
94 Callback bar = IntSetValueCaller( foo );
96 // invoke the callback
97 bar(); // Int_setValue(foo)
125 typedef Member<Test, void, &Test::test0> Test0;
126 typedef MemberCaller<Test, &Test::test0> Test0Caller;
127 void test0const() const {
129 typedef ConstMember<Test, void, &Test::test0const> Test0Const;
130 typedef ConstMemberCaller<Test, &Test::test0const> Test0ConstCaller;
133 typedef Member1<Test, A1, void, &Test::test1> Test1;
134 typedef MemberCaller1<Test, A1, &Test::test1> Test1Caller;
135 void test1const( A1 ) const {
137 typedef ConstMember1<Test, A1, void, &Test::test1const> Test1Const;
138 typedef ConstMemberCaller1<Test, A1, &Test::test1const> Test1ConstCaller;
139 void test2( A1, A2 ){
141 typedef Member2<Test, A1, A2, void, &Test::test2> Test2;
142 void test2const( A1, A2 ) const {
144 typedef ConstMember2<Test, A1, A2, void, &Test::test2const> Test2Const;
145 void test3( A1, A2, A3 ){
147 typedef Member3<Test, A1, A2, A3, void, &Test::test3> Test3;
148 void test3const( A1, A2, A3 ) const {
150 typedef ConstMember3<Test, A1, A2, A3, void, &Test::test3const> Test3Const;
155 typedef FreeCaller<&test0free> Test0FreeCaller;
156 void test1free( A1 ){
158 typedef FreeCaller1<A1, &test1free> Test1FreeCaller;
159 void test2free( A1, A2 ){
161 typedef Function2<A1, A2, void, &test2free> Test2Free;
162 void test3free( A1, A2, A3 ){
164 typedef Function3<A1, A2, A3, void, &test3free> Test3Free;
167 void test0( Test& test ){
169 typedef ReferenceCaller<Test, &test0> Test0Caller;
171 void test0const( const Test& test ){
173 typedef ConstReferenceCaller<Test, &test0const> Test0ConstCaller;
175 void test0p( Test* test ){
177 typedef PointerCaller<Test, &test0p> Test0PCaller;
179 void test0constp( const Test* test ){
181 typedef ConstPointerCaller<Test, &test0constp> Test0ConstPCaller;
183 void test1( Test& test, A1 ){
185 typedef ReferenceCaller1<Test, A1, &test1> Test1Caller;
187 void test1const( const Test& test, A1 ){
189 typedef ConstReferenceCaller1<Test, A1, &test1const> Test1ConstCaller;
191 void test1p( Test* test, A1 ){
193 typedef PointerCaller1<Test, A1, &test1p> Test1PCaller;
195 void test1constp( const Test* test, A1 ){
197 typedef ConstPointerCaller1<Test, A1, &test1constp> Test1ConstPCaller;
199 void test2( Test& test, A1, A2 ){
201 typedef Function3<Test&, A1, A2, void, &test2> Test2;
203 void test3( Test& test, A1, A2, A3 ){
205 typedef Function4<Test&, A1, A2, A3, void, &test3> Test3;
209 const Test& testconst = test;
211 Callback a = Test0FreeCaller();
212 Callback b = Test::Test0Caller( test );
213 b = makeCallback0( Test::Test0(), test );
214 Callback c = Test::Test0ConstCaller( testconst );
215 c = makeCallback0( Test::Test0Const(), test );
216 Callback d = Test0Caller( test );
217 Callback e = Test0ConstCaller( testconst );
218 Callback f = Test0PCaller( &test );
219 Callback g = Test0ConstPCaller( &testconst );
224 typedef Callback1<A1> TestCallback1;
225 TestCallback1 a = Test1FreeCaller();
226 TestCallback1 b = Test::Test1Caller( test );
227 b = makeCallback1( Test::Test1(), test );
228 TestCallback1 c = Test::Test1ConstCaller( testconst );
229 c = makeCallback1( Test::Test1Const(), test );
230 TestCallback1 d = Test1Caller( test );
231 TestCallback1 e = Test1ConstCaller( testconst );
232 TestCallback1 f = Test1PCaller( &test );
233 TestCallback1 g = Test1ConstPCaller( &testconst );
238 typedef Callback2<A1, A2> TestCallback2;
239 TestCallback2 a = makeStatelessCallback2( Test2Free() );
240 TestCallback2 b = makeCallback2( Test2(), test );
241 TestCallback2 c = makeCallback2( Test::Test2(), test );
242 TestCallback2 d = makeCallback2( Test::Test2Const(), test );
247 typedef Callback3<A1, A2, A3> TestCallback3;
248 TestCallback3 a = makeStatelessCallback3( Test3Free() );
249 TestCallback3 b = makeCallback3( Test3(), test );
250 TestCallback3 c = makeCallback3( Test::Test3(), test );
251 TestCallback3 d = makeCallback3( Test::Test3Const(), test );
252 a( A1(), A2(), A3() );