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 typedef FreeCaller<void(), &test0free> Test0FreeCaller;
157 void test1free( A1 ){
159 typedef FreeCaller<void(A1), &test1free> Test1FreeCaller;
160 void test2free( A1, A2 ){
162 typedef Function<void(A1, A2), &test2free> Test2Free;
163 void test3free( A1, A2, A3 ){
165 typedef Function<void(A1, A2, A3), &test3free> Test3Free;
168 void test0( Test& test ){
170 typedef ReferenceCaller<Test, void(), &test0> Test0Caller;
172 void test0const( const Test& test ){
174 typedef ConstReferenceCaller<Test, void(), &test0const> Test0ConstCaller;
176 void test0p( Test* test ){
178 typedef PointerCaller<Test, void(), &test0p> Test0PCaller;
180 void test0constp( const Test* test ){
182 typedef ConstPointerCaller<Test, void(), &test0constp> Test0ConstPCaller;
184 void test1( Test& test, A1 ){
186 typedef ReferenceCaller<Test, void(A1), &test1> Test1Caller;
188 void test1const( const Test& test, A1 ){
190 typedef ConstReferenceCaller<Test, void(A1), &test1const> Test1ConstCaller;
192 void test1p( Test* test, A1 ){
194 typedef PointerCaller<Test, void(A1), &test1p> Test1PCaller;
196 void test1constp( const Test* test, A1 ){
198 typedef ConstPointerCaller<Test, void(A1), &test1constp> Test1ConstPCaller;
200 void test2( Test& test, A1, A2 ){
202 typedef Function<void(Test&, A1, A2), &test2> Test2;
204 void test3( Test& test, A1, A2, A3 ){
206 typedef Function<void(Test&, A1, A2, A3), &test3> Test3;
210 const Test& testconst = test;
212 Callback<void()> a = Test0FreeCaller();
213 Callback<void()> b = Test::Test0Caller( test );
214 b = makeCallback( Test::Test0(), test );
215 Callback<void()> c = Test::Test0ConstCaller( testconst );
216 c = makeCallback( Test::Test0Const(), test );
218 Test0ConstCaller{ testconst };
219 Test0PCaller{ &test };
220 Test0ConstPCaller{ &testconst };
225 typedef Callback<void(A1)> TestCallback1;
226 TestCallback1 a = Test1FreeCaller();
227 TestCallback1 b = Test::Test1Caller( test );
228 b = makeCallback( Test::Test1(), test );
229 TestCallback1 c = Test::Test1ConstCaller( testconst );
230 c = makeCallback( Test::Test1Const(), test );
232 Test1ConstCaller{ testconst };
233 Test1PCaller{ &test };
234 Test1ConstPCaller{ &testconst };
239 typedef Callback<void(A1, A2)> TestCallback2;
240 TestCallback2 a = makeStatelessCallback( Test2Free() );
241 TestCallback2 b = makeCallback( Test2(), test );
242 makeCallback( Test::Test2(), test );
243 makeCallback( Test::Test2Const(), test );
248 typedef Callback<void(A1, A2, A3)> TestCallback3;
249 TestCallback3 a = makeStatelessCallback( Test3Free() );
250 TestCallback3 b = makeCallback( Test3(), test );
251 makeCallback( Test::Test3(), test );
252 makeCallback( Test::Test3Const(), test );
253 a( A1(), A2(), A3() );