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
23 #include "globaldefs.h"
25 #if GDEF_DEBUG || defined( DOXYGEN )
27 namespace ExampleMemberCaller
29 // MemberCaller example
35 void printValue() const {
36 // print this->value here;
42 // a typedef to make things more readable
43 typedef MemberCaller<Integer, void(), &Integer::setValue> SetValueCaller;
50 Callback<void()> bar = ConstMemberCaller<Integer, void(), &Integer::printValue>( foo );
52 // invoke the callback
53 bar(); // foo.printValue()
58 // use the typedef to improve readability
59 Callback<void()> bar = Integer::SetValueCaller( foo );
61 // invoke the callback
62 bar(); // foo.setValue()
68 namespace ExampleReferenceCaller
70 // ReferenceCaller example
71 void Int_printValue( const int& value ){
75 void Int_setValue( int& value ){
79 // a typedef to make things more readable
80 typedef ReferenceCaller<int, void(), Int_setValue> IntSetValueCaller;
86 Callback<void()> bar = ConstReferenceCaller<int, void(), Int_printValue>( foo );
88 // invoke the callback
89 bar(); // Int_printValue(foo)
94 // use the typedef to improve readability
95 Callback<void()> bar = IntSetValueCaller( foo );
97 // invoke the callback
98 bar(); // Int_setValue(foo)
126 typedef Member<Test, void(), &Test::test0> Test0;
127 typedef MemberCaller<Test, void(), &Test::test0> Test0Caller;
128 void test0const() const {
130 typedef ConstMember<Test, void(), &Test::test0const> Test0Const;
131 typedef ConstMemberCaller<Test, void(), &Test::test0const> Test0ConstCaller;
134 typedef Member<Test, void(A1), &Test::test1> Test1;
135 typedef MemberCaller<Test, void(A1), &Test::test1> Test1Caller;
136 void test1const( A1 ) const {
138 typedef ConstMember<Test, void(A1), &Test::test1const> Test1Const;
139 typedef ConstMemberCaller<Test, void(A1), &Test::test1const> Test1ConstCaller;
140 void test2( A1, A2 ){
142 typedef Member<Test, void(A1, A2), &Test::test2> Test2;
143 void test2const( A1, A2 ) const {
145 typedef ConstMember<Test, void(A1, A2), &Test::test2const> Test2Const;
146 void test3( A1, A2, A3 ){
148 typedef Member<Test, void(A1, A2, A3), &Test::test3> Test3;
149 void test3const( A1, A2, A3 ) const {
151 typedef ConstMember<Test, void(A1, A2, A3), &Test::test3const> Test3Const;
156 void test1free( A1 ){
158 void test2free( A1, A2 ){
160 typedef Function<void(A1, A2), &test2free> Test2Free;
161 void test3free( A1, A2, A3 ){
163 typedef Function<void(A1, A2, A3), &test3free> Test3Free;
166 void test0( Test& test ){
168 typedef ReferenceCaller<Test, void(), &test0> Test0Caller;
170 void test0const( const Test& test ){
172 typedef ConstReferenceCaller<Test, void(), &test0const> Test0ConstCaller;
174 void test0p( Test* test ){
176 typedef PointerCaller<Test, void(), &test0p> Test0PCaller;
178 void test0constp( const Test* test ){
180 typedef ConstPointerCaller<Test, void(), &test0constp> Test0ConstPCaller;
182 void test1( Test& test, A1 ){
184 typedef ReferenceCaller<Test, void(A1), &test1> Test1Caller;
186 void test1const( const Test& test, A1 ){
188 typedef ConstReferenceCaller<Test, void(A1), &test1const> Test1ConstCaller;
190 void test1p( Test* test, A1 ){
192 typedef PointerCaller<Test, void(A1), &test1p> Test1PCaller;
194 void test1constp( const Test* test, A1 ){
196 typedef ConstPointerCaller<Test, void(A1), &test1constp> Test1ConstPCaller;
198 void test2( Test& test, A1, A2 ){
200 typedef Function<void(Test&, A1, A2), &test2> Test2;
202 void test3( Test& test, A1, A2, A3 ){
204 typedef Function<void(Test&, A1, A2, A3), &test3> Test3;
208 const Test& testconst = test;
210 Callback<void()> a = makeCallbackF(&test0free);
211 Callback<void()> b = Test::Test0Caller( test );
212 b = makeCallback( Test::Test0(), test );
213 Callback<void()> c = Test::Test0ConstCaller( testconst );
214 c = makeCallback( Test::Test0Const(), test );
216 Test0ConstCaller{ testconst };
217 Test0PCaller{ &test };
218 Test0ConstPCaller{ &testconst };
223 typedef Callback<void(A1)> TestCallback1;
224 TestCallback1 a = makeCallbackF(&test1free);
225 TestCallback1 b = Test::Test1Caller( test );
226 b = makeCallback( Test::Test1(), test );
227 TestCallback1 c = Test::Test1ConstCaller( testconst );
228 c = makeCallback( Test::Test1Const(), test );
230 Test1ConstCaller{ testconst };
231 Test1PCaller{ &test };
232 Test1ConstPCaller{ &testconst };
237 typedef Callback<void(A1, A2)> TestCallback2;
238 TestCallback2 a = makeStatelessCallback( Test2Free() );
239 TestCallback2 b = makeCallback( Test2(), test );
240 makeCallback( Test::Test2(), test );
241 makeCallback( Test::Test2Const(), test );
246 typedef Callback<void(A1, A2, A3)> TestCallback3;
247 TestCallback3 a = makeStatelessCallback( Test3Free() );
248 TestCallback3 b = makeCallback( Test3(), test );
249 makeCallback( Test::Test3(), test );
250 makeCallback( Test::Test3Const(), test );
251 a( A1(), A2(), A3() );