[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
G++ 3 and typename warnings
From: |
Shane Walton |
Subject: |
G++ 3 and typename warnings |
Date: |
14 Sep 2004 12:54:43 -0700 |
I have been trying to compile this piece of code without warnings for
days with no resolution. Could someone please show me the problem? I
apologize for the length of this post, the license requires that it be
passed on in its entirety. I would like to stop the typename warnings
described at the very bottom. I appreciate any help that can be
provided. Thanks.
1 //**************** callback.hpp **********************
2 // Copyright 1994 Rich Hickey
3 /* Permission to use, copy, modify, distribute and sell this
software
4 * for any purpose is hereby granted without fee,
5 * provided that the above copyright notice appear in all
copies and
6 * that both that copyright notice and this permission notice
appear
7 * in supporting documentation. Rich Hickey makes no
8 * representations about the suitability of this software for
any
9 * purpose. It is provided "as is" without express or implied
warranty.
10 */
11
12 // 08/31/96 Rich Hickey
13 // Added ==, != and <
14 // They are not inline, source is in file callback.cpp
15 // Note: You must compile and link in callback.obj if you use
them
16 // C++ doesn't allow ptr-to-func to void * anymore -> changed
to void (*)(void)
17 // Added compiler workarounds for MS VC++ 4.2
18 // Prefixed all macros with RHCB
19 // Note: derivation from CBFunctorBase is now public, and
access functions
20 // (for func, callee etc) are provided >>for implementation use
only<<
21
22 // 06/12/94 Rich Hickey
23 // 3rd major revision
24 // Now functors are concrete classes, and should be held by
value
25 // Virtual function mechanism removed
26 // Generic makeFunctor() mechanism added for building functors
27 // from both stand-alone functions and object/ptr-to-mem-func
pairs
28
29 #ifndef _CALLBACK_HH
30 #define _CALLBACK_HH
31
32 /*
33 To use:
34
35 If you wish to build a component that provides/needs a
callback, simply
36 specify and hold a CBFunctor of the type corresponding to the
args
37 you wish to pass and the return value you need. There are 10
Functors
38 from which to choose:
39
40 CBFunctor0
41 CBFunctor1<P1>
42 CBFunctor2<P1,P2>
43 CBFunctor3<P1,P2,P3>
44 CBFunctor4<P1,P2,P3,P4>
45 CBFunctor0wRet<RT>
46 CBFunctor1wRet<P1,RT>
47 CBFunctor2wRet<P1,P2,RT>
48 CBFunctor3wRet<P1,P2,P3,RT>
49 CBFunctor4wRet<P1,P2,P3,P4,RT>
50
51 These are parameterized by their args and return value if any.
Each has
52 a default ctor and an operator() with the corresponding
signature.
53
54 They can be treated and used just like ptr-to-functions.
55
56 If you want to be a client of a component that uses callbacks,
you
57 create a CBFunctor by calling makeFunctor().
58
59 There are three flavors of makeFunctor - you can create a
functor from:
60
61 a ptr-to-stand-alone function
62 an object and a pointer-to-member function.
63 a pointer-to-member function (which will be called on first arg
of functor)
64
65 Note: this last was not covered in the article - see
CBEXAM3.CPP
66
67 The current iteration of this library requires you pass
makeFunctor()
68 a dummy first argument of type
ptr-to-the-Functor-type-you-want-to-create.
69 Simply cast 0 to provide this argument:
70
71 makeFunctor((target-functor*)0,ptr-to-function)
72
makeFunctor((target-functor*)0,reference-to-object,ptr-to-member-function)
73 makeFunctor((target-functor*)0,ptr-to-member-function)
74
75 Future versions will drop this requirement once member
templates are
76 available.
77
78 The functor system is 100% type safe. It is also type flexible.
You can
79 build a functor out of a function that is 'type compatible'
with the
80 target functor - it need not have an exactly matching
signature. By
81 type compatible I mean a function with the same number of
arguments, of
82 types reachable from the functor's argument types by implicit
conversion.
83 The return type of the function must be implicitly convertible
to the
84 return type of the functor. A functor with no return can be
built from a
85 function with a return - the return value is simply ignored.
86 (See ethel example below)
87
88 All the correct virtual function behavior is preserved. (see
ricky
89 example below).
90
91 If you somehow try to create something in violation
92 of the type system you will get a compile-time or
template-instantiation-
93 time error.
94
95 The CBFunctor base class and translator
96 classes are artifacts of this implementation. You should not
write
97 code that relies upon their existence. Nor should you rely on
the return
98 value of makeFunctor being anything in particular.
99
100 All that is guaranteed is that the Functor classes have a
default ctor,
101 a ctor that can accept 0 as an initializer,
102 an operator() with the requested argument types and return
type, an
103 operator that will allow it to be evaluated in a conditional
(with
104 'true' meaning the functor is set, 'false' meaning it is not),
and that
105 Functors can be constructed from the result of makeFunctor(),
given
106 you've passed something compatible to makeFunctor(). In
addition you
107 can compare 2 functors with ==, !=, and <. 2 functors with the
same
108 'callee' (function, object and/or ptr-to-mem-func) shall
compare
109 equal. op < forms an ordering relation across all callee types
-> the
110 actual order is not meaningful or to be depended upon.
111
112 /////////////////////// BEGIN Example 1
//////////////////////////
113 #include <iostream.h>
114 #include "callback.hpp"
115
116 //do5Times() is a function that takes a functor and invokes it
5 times
117
118 void do5Times(const CBFunctor1<int> &doIt)
119 {
120 for(int i=0;i<5;i++)
121 doIt(i);
122 }
123
124 //Here are some standalone functions
125
126 void fred(int i){cout << "fred: " << i<<endl;}
127 int ethel(long l){cout << "ethel: " << l<<endl;return l;}
128
129 //Here is a class with a virtual function, and a derived class
130
131 class B{
132 public:
133 virtual void ricky(int i)
134 {cout << "B::ricky: " << i<<endl;}
135 };
136
137 class D:public B{
138 public:
139 void ricky(int i)
140 {cout << "D::ricky: " << i<<endl;}
141 };
142
143 void main()
144 {
145 //create a typedef of the functor type to simplify dummy
argument
146 typedef CBFunctor1<int> *FtorType;
147
148 CBFunctor1<int> ftor; //a functor variable
149 //make a functor from ptr-to-function
150 ftor = makeFunctor((FtorType)0,fred);
151 do5Times(ftor);
152 //note ethel is not an exact match - ok, is compatible
153 ftor = makeFunctor((FtorType)0,ethel);
154 do5Times(ftor);
155
156 //create a D object to be a callback target
157 D myD;
158 //make functor from object and ptr-to-member-func
159 ftor = makeFunctor((FtorType)0,myD,&B::ricky);
160 do5Times(ftor);
161 }
162 /////////////////////// END of example 1
//////////////////////////
163
164 /////////////////////// BEGIN Example 2
//////////////////////////
165 #include <iostream.h>
166 #include "callback.hpp"
167
168 //Button is a component that provides a functor-based
169 //callback mechanism, so you can wire it up to whatever you
wish
170
171 class Button{
172 public:
173 //ctor takes a functor and stores it away in a member
174
175 Button(const CBFunctor0
&uponClickDoThis):notify(uponClickDoThis)
176 {}
177 void click()
178 {
179 //invoke the functor, thus calling back client
180 notify();
181 }
182 private:
183 //note this is a data member with a verb for a name - matches
its
184 //function-like usage
185 CBFunctor0 notify;
186 };
187
188 class CDPlayer{
189 public:
190 void play()
191 {cout << "Playing"<<endl;}
192 void stop()
193 {cout << "Stopped"<<endl;}
194 };
195
196 void main()
197 {
198 CDPlayer myCD;
199 Button
playButton(makeFunctor((CBFunctor0*)0,myCD,&CDPlayer::play));
200 Button
stopButton(makeFunctor((CBFunctor0*)0,myCD,&CDPlayer::stop));
201 playButton.click(); //calls myCD.play()
202 stopButton.click(); //calls myCD.stop()
203 }
204 /////////////////////// END of example 2
//////////////////////////
205
206 */
207
208 //******************************************************************
209 ///////////////////////////////////////////////////////////////////*
210 //WARNING - no need to read past this point, lest confusion
ensue. *
211 //Only the curious need explore further - but remember
*
212 //about that cat!
*
213 ///////////////////////////////////////////////////////////////////*
214 //******************************************************************
215
216 //////////////////////////////
217 // COMPILER BUG WORKAROUNDS:
218 // As of version 4.02 Borland has a code generation bug
219 // returning the result of a call via a ptr-to-function in a
template
220
221 #ifdef __BORLANDC__
222 #define RHCB_BC4_RET_BUG(x) RT(x)
223 #else
224 #define RHCB_BC4_RET_BUG(x) x
225 #endif
226
227 // MS VC++ 4.2 still has many bugs relating to templates
228 // This version works around them as best I can - however note
that
229 // MS will allow 'void (T::*)()const' to bind to a non-const
member function
230 // of T. In addition, they do not support overloading template
functions
231 // based on constness of ptr-to-mem-funcs.
232 // When _MSC_VER is defined I provide only the const
versions,however it is on
233 // the user's head, when calling makeFunctor with a const T, to
make sure
234 // that the pointed-to member function is also const since MS
won't enforce it!
235
236 // Other than that the port is completely functional under VC++
4.2
237
238 // One MS bug you may encounter during _use_ of the callbacks:
239 // If you pass them by reference you can't call op() on the
reference
240 // Workaround is to pass by value.
241
242 /*
243 // MS unable to call operator() on template class reference
244 template <class T>
245 class Functor{
246 public:
247 void operator()(T t)const{};
248 };
249
250 void foo(const Functor<int> &f)
251 {
252 f(1); //error C2064: term does not evaluate to a function
253
254 //works when f is passed by value
255 }
256 */
257
258 // Note: if you are porting to another compiler that is having
trouble you
259 // can try defining some of these flags as well:
260
261
262 #if defined(_MSC_VER)
263 #define RHCB_CANT_PASS_MEMFUNC_BY_REFERENCE //like it says
264 #define RHCB_CANT_OVERLOAD_ON_CONSTNESS //of mem funcs
265 #define RHCB_CANT_INIT_REFERENCE_CTOR_STYLE //int i;int &ir(i);
//MS falls down
266 #define RHCB_WONT_PERFORM_PTR_CONVERSION //of 0 to
ptr-to-any-type
267 #endif
268
269
270 // Don't touch this stuff
271 #if defined(RHCB_CANT_PASS_MEMFUNC_BY_REFERENCE)
272 #define RHCB_CONST_REF
273 #else
274 #define RHCB_CONST_REF const &
275 #endif
276
277 #if defined(RHCB_CANT_INIT_REFERENCE_CTOR_STYLE)
278 #define RHCB_CTOR_STYLE_INIT =
279 #else
280 #define RHCB_CTOR_STYLE_INIT
281 #endif
282
283 #if defined(RHCB_WONT_PERFORM_PTR_CONVERSION)
284 #define RHCB_DUMMY_INIT int
285 #else
286 #define RHCB_DUMMY_INIT DummyInit *
287 #endif
288
289 ////////////////////////////// THE CODE
//////////////////////////
290
291 //change these when your compiler gets bool
292 typedef int RHCB_BOOL;
293 enum {RHCB_FALSE ,RHCB_TRUE};
294
295 #include <string.h> //for memstuff
296 #include <stddef.h> //for size_t
297
298 //typeless representation of a function and optional object
299
300 class CBFunctorBase{
301 public:
302 //Note: ctors are protected
303
304 //for evaluation in conditionals - can the functor be called?
305 operator RHCB_BOOL()const{return callee||func;}
306
307 //Now you can put them in containers _and_ remove them!
308 //Source for these 3 is in callback.cpp
309 friend RHCB_BOOL
310 operator==(const CBFunctorBase &lhs,const CBFunctorBase
&rhs);
311 friend RHCB_BOOL
312 operator!=(const CBFunctorBase &lhs,const CBFunctorBase
&rhs);
313 friend RHCB_BOOL
314 operator<(const CBFunctorBase &lhs,const CBFunctorBase
&rhs);
315
316 //The rest below for implementation use only !
317
318 class DummyInit{
319 };
320
321 typedef void (CBFunctorBase::*PMemFunc)();
322 typedef void (*PFunc)();
323 enum {MEM_FUNC_SIZE = sizeof(PMemFunc)};
324
325 PFunc getFunc() const {return func;}
326 void *getCallee() const {return callee;}
327 const char *getMemFunc() const {return memFunc;}
328
329 protected:
330 ////////////////////////////////////////////////////////////////
331 // Note: this code depends on all ptr-to-mem-funcs being same
size
332 // If that is not the case then make memFunc as large as
largest
333 ////////////////////////////////////////////////////////////////
334 union{
335 PFunc func;
336 char memFunc[MEM_FUNC_SIZE];
337 };
338 void *callee;
339
340 CBFunctorBase():callee(0),func(0){}
341 CBFunctorBase(const void *c,PFunc f, const void *mf,size_t
sz):
342 callee((void *)c)
343 {
344 if(c) //must be callee/memfunc
345 {
346 memcpy(memFunc,mf,sz);
347 if(sz<MEM_FUNC_SIZE) //zero-out the rest, if
any, so
comparisons work
348 {
349 memset(memFunc+sz,0,MEM_FUNC_SIZE-sz);
350 }
351 }
352 else //must be ptr-to-func
353 {
354 func = f;
355 }
356 }
357 };
358
359
360 /************************* no arg - no return
*******************/
361 class CBFunctor0:public CBFunctorBase{
362 public:
363 CBFunctor0(RHCB_DUMMY_INIT = 0){}
364 void operator()()const
365 {
366 thunk(*this);
367 }
368 protected:
369 typedef void (*Thunk)(const CBFunctorBase &);
370 CBFunctor0(Thunk t,const void *c,PFunc f,const void *mf,size_t
sz):
371 CBFunctorBase(c,f,mf,sz),thunk(t){}
372 private:
373 Thunk thunk;
374 };
375
376 template <class Callee, class MemFunc>
377 class CBMemberTranslator0:public CBFunctor0{
378 public:
379 CBMemberTranslator0(Callee &c,const MemFunc &m):
380 CBFunctor0(thunk,&c,0,&m,sizeof(MemFunc)){}
381 static void thunk(const CBFunctorBase &ftor)
382 {
383 Callee *callee = (Callee *)ftor.getCallee();
384 MemFunc &memFunc RHCB_CTOR_STYLE_INIT
385 (*(MemFunc*)(void *)(ftor.getMemFunc()));
386 (callee->*memFunc)();
387 }
388 };
389
390 template <class Func>
391 class CBFunctionTranslator0:public CBFunctor0{
392 public:
393 CBFunctionTranslator0(Func
f):CBFunctor0(thunk,0,(PFunc)f,0,0){}
394 static void thunk(const CBFunctorBase &ftor)
395 {
396 (Func(ftor.getFunc()))();
397 }
398 };
399
400 #if !defined(RHCB_CANT_OVERLOAD_ON_CONSTNESS)
401 template <class Callee,class TRT,class CallType>
402 inline CBMemberTranslator0<Callee,TRT (CallType::*)()>
403 makeFunctor(CBFunctor0 *,Callee &c,TRT (CallType::*
RHCB_CONST_REF f)())
404 {
405 typedef TRT (CallType::*MemFunc)();
406 return CBMemberTranslator0<Callee,MemFunc>(c,f);
407 }
408 #endif
409
410 template <class Callee,class TRT,class CallType>
411 inline CBMemberTranslator0<const Callee,TRT
(CallType::*)()const>
412 makeFunctor(CBFunctor0 *,const Callee &c,
413 TRT (CallType::* RHCB_CONST_REF f)()const)
414 {
415 typedef TRT (CallType::*MemFunc)()const;
416 return CBMemberTranslator0<const Callee,MemFunc>(c,f);
417 }
418
419 template <class TRT>
420 inline CBFunctionTranslator0<TRT (*)()>
421 makeFunctor(CBFunctor0 *,TRT (*f)())
422 {
423 return CBFunctionTranslator0<TRT (*)()>(f);
424 }
425
426 /************************* no arg - with return
*******************/
427 template <class RT>
428 class CBFunctor0wRet:public CBFunctorBase{
429 public:
430 CBFunctor0wRet(RHCB_DUMMY_INIT = 0){}
431 RT operator()()const
432 {
433 return RHCB_BC4_RET_BUG(thunk(*this));
434 }
435 protected:
436 typedef RT (*Thunk)(const CBFunctorBase &);
437 CBFunctor0wRet(Thunk t,const void *c,PFunc f,const void
*mf,size_t sz):
438 CBFunctorBase(c,f,mf,sz),thunk(t){}
439 private:
440 Thunk thunk;
441 };
442
443 template <class RT,class Callee, class MemFunc>
444 class CBMemberTranslator0wRet:public CBFunctor0wRet<RT>{
445 public:
446 CBMemberTranslator0wRet(Callee &c,const MemFunc &m):
447 CBFunctor0wRet<RT>(thunk,&c,0,&m,sizeof(MemFunc)){}
448 static RT thunk(const CBFunctorBase &ftor)
449 {
450 Callee *callee = (Callee *)ftor.getCallee();
451 MemFunc &memFunc RHCB_CTOR_STYLE_INIT
452 (*(MemFunc*)(void *)(ftor.getMemFunc()));
453 return RHCB_BC4_RET_BUG((callee->*memFunc)());
454 }
455 };
456
457 template <class RT,class Func>
458 class CBFunctionTranslator0wRet:public CBFunctor0wRet<RT>{
459 public:
460 CBFunctionTranslator0wRet(Func
f):CBFunctor0wRet<RT>(thunk,0,(PFunc)f,0,0){}
461 static RT thunk(const CBFunctorBase &ftor)
462 {
463 return (Func(ftor.getFunc()))();
464 }
465 };
466
467 #if !defined(RHCB_CANT_OVERLOAD_ON_CONSTNESS)
468 template <class RT,class Callee,class TRT,class CallType>
469 inline CBMemberTranslator0wRet<RT,Callee,TRT (CallType::*)()>
470 makeFunctor(CBFunctor0wRet<RT>*,Callee &c,TRT (CallType::*
RHCB_CONST_REF f)())
471 {
472 typedef TRT (CallType::*MemFunc)();
473 return CBMemberTranslator0wRet<RT,Callee,MemFunc>(c,f);
474 }
475 #endif
476
477 template <class RT,class Callee,class TRT,class CallType>
478 inline CBMemberTranslator0wRet<RT,const Callee,TRT
(CallType::*)()const>
479 makeFunctor(CBFunctor0wRet<RT>*,const Callee &c,
480 TRT (CallType::* RHCB_CONST_REF f)()const)
481 {
482 typedef TRT (CallType::*MemFunc)()const;
483 return CBMemberTranslator0wRet<RT,const Callee,MemFunc>(c,f);
484 }
485
486 template <class RT,class TRT>
487 inline CBFunctionTranslator0wRet<RT,TRT (*)()>
488 makeFunctor(CBFunctor0wRet<RT>*,TRT (*f)())
489 {
490 return CBFunctionTranslator0wRet<RT,TRT (*)()>(f);
491 }
492
493 /************************* one arg - no return
*******************/
494 template <class P1>
495 class CBFunctor1:public CBFunctorBase{
496 public:
497 CBFunctor1(RHCB_DUMMY_INIT = 0){}
498 void operator()(P1 p1)const
499 {
500 thunk(*this,p1);
501 }
502 //for STL
503 typedef P1 argument_type;
504 typedef void result_type;
505 protected:
506 typedef void (*Thunk)(const CBFunctorBase &,P1);
507 CBFunctor1(Thunk t,const void *c,PFunc f,const void *mf,size_t
sz):
508 CBFunctorBase(c,f,mf,sz),thunk(t){}
509 private:
510 Thunk thunk;
511 };
512
513 template <class P1,class Callee, class MemFunc>
514 class CBMemberTranslator1:public CBFunctor1<P1>{
515 public:
516 CBMemberTranslator1(Callee &c,const MemFunc &m):
517 CBFunctor1<P1>(thunk,&c,0,&m,sizeof(MemFunc)){}
518 static void thunk(const CBFunctorBase &ftor,P1 p1)
519 {
520 Callee *callee = (Callee *)ftor.getCallee();
521 MemFunc &memFunc RHCB_CTOR_STYLE_INIT
522 (*(MemFunc*)(void *)(ftor.getMemFunc()));
523 (callee->*memFunc)(p1);
524 }
525 };
526
527 template <class P1,class Func>
528 class CBFunctionTranslator1:public CBFunctor1<P1>{
529 public:
530 CBFunctionTranslator1(Func
f):CBFunctor1<P1>(thunk,0,(PFunc)f,0,0){}
531 static void thunk(const CBFunctorBase &ftor,P1 p1)
532 {
533 (Func(ftor.getFunc()))(p1);
534 }
535 };
536
537 #if !defined(RHCB_CANT_OVERLOAD_ON_CONSTNESS)
538 template <class P1,class Callee,class TRT,class CallType,class
TP1>
539 inline CBMemberTranslator1<P1,Callee,TRT (CallType::*)(TP1)>
540 makeFunctor(CBFunctor1<P1>*,Callee &c,TRT (CallType::*
RHCB_CONST_REF f)(TP1))
541 {
542 typedef TRT (CallType::*MemFunc)(TP1);
543 return CBMemberTranslator1<P1,Callee,MemFunc>(c,f);
544 }
545 #endif
546
547 template <class P1,class Callee,class TRT,class CallType,class
TP1>
548 inline CBMemberTranslator1<P1,const Callee,TRT
(CallType::*)(TP1)const>
549 makeFunctor(CBFunctor1<P1>*,const Callee &c,
550 TRT (CallType::* RHCB_CONST_REF f)(TP1)const)
551 {
552 typedef TRT (CallType::*MemFunc)(TP1)const;
553 return CBMemberTranslator1<P1,const Callee,MemFunc>(c,f);
554 }
555
556 template <class P1,class TRT,class TP1>
557 inline CBFunctionTranslator1<P1,TRT (*)(TP1)>
558 makeFunctor(CBFunctor1<P1>*,TRT (*f)(TP1))
559 {
560 return CBFunctionTranslator1<P1,TRT (*)(TP1)>(f);
561 }
562
563 template <class P1,class MemFunc>
564 class CBMemberOf1stArgTranslator1:public CBFunctor1<P1>{
565 public:
566 CBMemberOf1stArgTranslator1(const MemFunc &m):
567 CBFunctor1<P1>(thunk,(void *)1,0,&m,sizeof(MemFunc)){}
568 static void thunk(const CBFunctorBase &ftor,P1 p1)
569 {
570 MemFunc &memFunc RHCB_CTOR_STYLE_INIT
571 (*(MemFunc*)(void *)(ftor.getMemFunc()));
572 (p1.*memFunc)();
573 }
574 };
575
576 #if !defined(RHCB_CANT_OVERLOAD_ON_CONSTNESS)
577 template <class P1,class TRT,class CallType>
578 inline CBMemberOf1stArgTranslator1<P1,TRT (CallType::*)()>
579 makeFunctor(CBFunctor1<P1>*,TRT (CallType::* RHCB_CONST_REF
f)())
580 {
581 typedef TRT (CallType::*MemFunc)();
582 return CBMemberOf1stArgTranslator1<P1,MemFunc>(f);
583 }
584 #endif
585
586 template <class P1,class TRT,class CallType>
587 inline CBMemberOf1stArgTranslator1<P1,TRT (CallType::*)()const>
588 makeFunctor(CBFunctor1<P1>*,TRT (CallType::* RHCB_CONST_REF
f)()const)
589 {
590 typedef TRT (CallType::*MemFunc)()const;
591 return CBMemberOf1stArgTranslator1<P1,MemFunc>(f);
592 }
593
594 /************************* one arg - with return
*******************/
595 template <class P1,class RT>
596 class CBFunctor1wRet:public CBFunctorBase{
597 public:
598 CBFunctor1wRet(RHCB_DUMMY_INIT = 0){}
599 RT operator()(P1 p1)const
600 {
601 return RHCB_BC4_RET_BUG(thunk(*this,p1));
602 }
603 //for STL
604 typedef P1 argument_type;
605 typedef RT result_type;
606 protected:
607 typedef RT (*Thunk)(const CBFunctorBase &,P1);
608 CBFunctor1wRet(Thunk t,const void *c,PFunc f,const void
*mf,size_t sz):
609 CBFunctorBase(c,f,mf,sz),thunk(t){}
610 private:
611 Thunk thunk;
612 };
613
614 template <class P1,class RT,class Callee, class MemFunc>
615 class CBMemberTranslator1wRet:public CBFunctor1wRet<P1,RT>{
616 public:
617 CBMemberTranslator1wRet(Callee &c,const MemFunc &m):
618 CBFunctor1wRet<P1,RT>(thunk,&c,0,&m,sizeof(MemFunc)){}
619 static RT thunk(const CBFunctorBase &ftor,P1 p1)
620 {
621 Callee *callee = (Callee *)ftor.getCallee();
622 MemFunc &memFunc RHCB_CTOR_STYLE_INIT
623 (*(MemFunc*)(void *)(ftor.getMemFunc()));
624 return RHCB_BC4_RET_BUG((callee->*memFunc)(p1));
625 }
626 };
627
628 template <class P1,class RT,class Func>
629 class CBFunctionTranslator1wRet:public CBFunctor1wRet<P1,RT>{
630 public:
631 CBFunctionTranslator1wRet(Func f):
632 CBFunctor1wRet<P1,RT>(thunk,0,(PFunc)f,0,0){}
633 static RT thunk(const CBFunctorBase &ftor,P1 p1)
634 {
635 return (Func(ftor.getFunc()))(p1);
636 }
637 };
638
639 #if !defined(RHCB_CANT_OVERLOAD_ON_CONSTNESS)
640 template <class P1,class RT,
641 class Callee,class TRT,class CallType,class TP1>
642 inline CBMemberTranslator1wRet<P1,RT,Callee,TRT
(CallType::*)(TP1)>
643 makeFunctor(CBFunctor1wRet<P1,RT>*,Callee &c,
644 TRT (CallType::* RHCB_CONST_REF f)(TP1))
645 {
646 typedef TRT (CallType::*MemFunc)(TP1);
647 return CBMemberTranslator1wRet<P1,RT,Callee,MemFunc>(c,f);
648 }
649 #endif
650
651 template <class P1,class RT,
652 class Callee,class TRT,class CallType,class TP1>
653 inline CBMemberTranslator1wRet<P1,RT,
654 const Callee,TRT (CallType::*)(TP1)const>
655 makeFunctor(CBFunctor1wRet<P1,RT>*,
656 const Callee &c,TRT (CallType::* RHCB_CONST_REF f)(TP1)const)
657 {
658 typedef TRT (CallType::*MemFunc)(TP1)const;
659 return CBMemberTranslator1wRet<P1,RT,const
Callee,MemFunc>(c,f);
660 }
661
662 template <class P1,class RT,class TRT,class TP1>
663 inline CBFunctionTranslator1wRet<P1,RT,TRT (*)(TP1)>
664 makeFunctor(CBFunctor1wRet<P1,RT>*,TRT (*f)(TP1))
665 {
666 return CBFunctionTranslator1wRet<P1,RT,TRT (*)(TP1)>(f);
667 }
668
669 template <class P1,class RT,class MemFunc>
670 class CBMemberOf1stArgTranslator1wRet:public
CBFunctor1wRet<P1,RT>{
671 public:
672 CBMemberOf1stArgTranslator1wRet(const MemFunc &m):
673 CBFunctor1wRet<P1,RT>(thunk,(void
*)1,0,&m,sizeof(MemFunc)){}
674 static RT thunk(const CBFunctorBase &ftor,P1 p1)
675 {
676 MemFunc &memFunc RHCB_CTOR_STYLE_INIT
677 (*(MemFunc*)(void *)(ftor.getMemFunc()));
678 return RHCB_BC4_RET_BUG((p1.*memFunc)());
679 }
680 };
681
682 #if !defined(RHCB_CANT_OVERLOAD_ON_CONSTNESS)
683 template <class P1,class RT,class TRT,class CallType>
684 inline CBMemberOf1stArgTranslator1wRet<P1,RT,TRT
(CallType::*)()>
685 makeFunctor(CBFunctor1wRet<P1,RT>*,TRT (CallType::*
RHCB_CONST_REF f)())
686 {
687 typedef TRT (CallType::*MemFunc)();
688 return CBMemberOf1stArgTranslator1wRet<P1,RT,MemFunc>(f);
689 }
690 #endif
691
692 template <class P1,class RT,class TRT,class CallType>
693 inline CBMemberOf1stArgTranslator1wRet<P1,RT,TRT
(CallType::*)()const>
694 makeFunctor(CBFunctor1wRet<P1,RT>*,TRT (CallType::*
RHCB_CONST_REF f)()const)
695 {
696 typedef TRT (CallType::*MemFunc)()const;
697 return CBMemberOf1stArgTranslator1wRet<P1,RT,MemFunc>(f);
698 }
699
700
701 /************************* two args - no return
*******************/
702 template <class P1,class P2>
703 class CBFunctor2:public CBFunctorBase{
704 public:
705 CBFunctor2(RHCB_DUMMY_INIT = 0){}
706 void operator()(P1 p1,P2 p2)const
707 {
708 thunk(*this,p1,p2);
709 }
710 //for STL
711 typedef P1 first_argument_type;
712 typedef P2 second_argument_type;
713 typedef void result_type;
714 protected:
715 typedef void (*Thunk)(const CBFunctorBase &,P1,P2);
716 CBFunctor2(Thunk t,const void *c,PFunc f,const void *mf,size_t
sz):
717 CBFunctorBase(c,f,mf,sz),thunk(t){}
718 private:
719 Thunk thunk;
720 };
721
722 template <class P1,class P2,class Callee, class MemFunc>
723 class CBMemberTranslator2:public CBFunctor2<P1,P2>{
724 public:
725 CBMemberTranslator2(Callee &c,const MemFunc &m):
726 CBFunctor2<P1,P2>(thunk,&c,0,&m,sizeof(MemFunc)){}
727 static void thunk(const CBFunctorBase &ftor,P1 p1,P2 p2)
728 {
729 Callee *callee = (Callee *)ftor.getCallee();
730 MemFunc &memFunc RHCB_CTOR_STYLE_INIT
731 (*(MemFunc*)(void *)(ftor.getMemFunc()));
732 (callee->*memFunc)(p1,p2);
733 }
734 };
735
736 template <class P1,class P2,class Func>
737 class CBFunctionTranslator2:public CBFunctor2<P1,P2>{
738 public:
739 CBFunctionTranslator2(Func
f):CBFunctor2<P1,P2>(thunk,0,(PFunc)f,0,0){}
740 static void thunk(const CBFunctorBase &ftor,P1 p1,P2 p2)
741 {
742 (Func(ftor.getFunc()))(p1,p2);
743 }
744 };
745
746 #if !defined(RHCB_CANT_OVERLOAD_ON_CONSTNESS)
747 template <class P1,class P2,class Callee,
748 class TRT,class CallType,class TP1,class TP2>
749 inline CBMemberTranslator2<P1,P2,Callee,TRT
(CallType::*)(TP1,TP2)>
750 makeFunctor(CBFunctor2<P1,P2>*,Callee &c,
751 TRT (CallType::* RHCB_CONST_REF f)(TP1,TP2))
752 {
753 typedef TRT (CallType::*MemFunc)(TP1,TP2);
754 return CBMemberTranslator2<P1,P2,Callee,MemFunc>(c,f);
755 }
756 #endif
757
758 template <class P1,class P2,class Callee,
759 class TRT,class CallType,class TP1,class TP2>
760 inline CBMemberTranslator2<P1,P2,const Callee,
761 TRT (CallType::*)(TP1,TP2)const>
762 makeFunctor(CBFunctor2<P1,P2>*,const Callee &c,
763 TRT (CallType::* RHCB_CONST_REF f)(TP1,TP2)const)
764 {
765 typedef TRT (CallType::*MemFunc)(TP1,TP2)const;
766 return CBMemberTranslator2<P1,P2,const Callee,MemFunc>(c,f);
767 }
768
769 template <class P1,class P2,class TRT,class TP1,class TP2>
770 inline CBFunctionTranslator2<P1,P2,TRT (*)(TP1,TP2)>
771 makeFunctor(CBFunctor2<P1,P2>*,TRT (*f)(TP1,TP2))
772 {
773 return CBFunctionTranslator2<P1,P2,TRT (*)(TP1,TP2)>(f);
774 }
775
776 template <class P1,class P2,class MemFunc>
777 class CBMemberOf1stArgTranslator2:public CBFunctor2<P1,P2>{
778 public:
779 CBMemberOf1stArgTranslator2(const MemFunc &m):
780 CBFunctor2<P1,P2>(thunk,(void
*)1,0,&m,sizeof(MemFunc)){}
781 static void thunk(const CBFunctorBase &ftor,P1 p1,P2 p2)
782 {
783 MemFunc &memFunc RHCB_CTOR_STYLE_INIT
784 (*(MemFunc*)(void *)(ftor.getMemFunc()));
785 (p1.*memFunc)(p2);
786 }
787 };
788
789 #if !defined(RHCB_CANT_OVERLOAD_ON_CONSTNESS)
790 template <class P1,class P2,class TRT,class CallType,class TP1>
791 inline CBMemberOf1stArgTranslator2<P1,P2,TRT
(CallType::*)(TP1)>
792 makeFunctor(CBFunctor2<P1,P2>*,TRT (CallType::* RHCB_CONST_REF
f)(TP1))
793 {
794 typedef TRT (CallType::*MemFunc)(TP1);
795 return CBMemberOf1stArgTranslator2<P1,P2,MemFunc>(f);
796 }
797 #endif
798
799 template <class P1,class P2,class TRT,class CallType,class TP1>
800 inline CBMemberOf1stArgTranslator2<P1,P2,TRT
(CallType::*)(TP1)const>
801 makeFunctor(CBFunctor2<P1,P2>*,TRT (CallType::* RHCB_CONST_REF
f)(TP1)const)
802 {
803 typedef TRT (CallType::*MemFunc)(TP1)const;
804 return CBMemberOf1stArgTranslator2<P1,P2,MemFunc>(f);
805 }
806
807
808 /************************* two args - with return
*******************/
809 template <class P1,class P2,class RT>
810 class CBFunctor2wRet:public CBFunctorBase{
811 public:
812 CBFunctor2wRet(RHCB_DUMMY_INIT = 0){}
813 RT operator()(P1 p1,P2 p2)const
814 {
815 return RHCB_BC4_RET_BUG(thunk(*this,p1,p2));
816 }
817 //for STL
818 typedef P1 first_argument_type;
819 typedef P2 second_argument_type;
820 typedef RT result_type;
821 protected:
822 typedef RT (*Thunk)(const CBFunctorBase &,P1,P2);
823 CBFunctor2wRet(Thunk t,const void *c,PFunc f,const void
*mf,size_t sz):
824 CBFunctorBase(c,f,mf,sz),thunk(t){}
825 private:
826 Thunk thunk;
827 };
828
829 template <class P1,class P2,class RT,class Callee, class
MemFunc>
830 class CBMemberTranslator2wRet:public CBFunctor2wRet<P1,P2,RT>{
831 public:
832 CBMemberTranslator2wRet(Callee &c,const MemFunc &m):
833
CBFunctor2wRet<P1,P2,RT>(thunk,&c,0,&m,sizeof(MemFunc)){}
834 static RT thunk(const CBFunctorBase &ftor,P1 p1,P2 p2)
835 {
836 Callee *callee = (Callee *)ftor.getCallee();
837 MemFunc &memFunc RHCB_CTOR_STYLE_INIT
838 (*(MemFunc*)(void *)(ftor.getMemFunc()));
839 return RHCB_BC4_RET_BUG((callee->*memFunc)(p1,p2));
840 }
841 };
842
843 template <class P1,class P2,class RT,class Func>
844 class CBFunctionTranslator2wRet:public
CBFunctor2wRet<P1,P2,RT>{
845 public:
846 CBFunctionTranslator2wRet(Func f):
847 CBFunctor2wRet<P1,P2,RT>(thunk,0,(PFunc)f,0,0){}
848 static RT thunk(const CBFunctorBase &ftor,P1 p1,P2 p2)
849 {
850 return (Func(ftor.getFunc()))(p1,p2);
851 }
852 };
853
854 #if !defined(RHCB_CANT_OVERLOAD_ON_CONSTNESS)
855 template <class P1,class P2,class RT,class Callee,
856 class TRT,class CallType,class TP1,class TP2>
857 inline CBMemberTranslator2wRet<P1,P2,RT,Callee,
858 TRT (CallType::*)(TP1,TP2)>
859 makeFunctor(CBFunctor2wRet<P1,P2,RT>*,Callee &c,
860 TRT (CallType::* RHCB_CONST_REF f)(TP1,TP2))
861 {
862 typedef TRT (CallType::*MemFunc)(TP1,TP2);
863 return CBMemberTranslator2wRet<P1,P2,RT,Callee,MemFunc>(c,f);
864 }
865 #endif
866
867 template <class P1,class P2,class RT,class Callee,
868 class TRT,class CallType,class TP1,class TP2>
869 inline CBMemberTranslator2wRet<P1,P2,RT,const Callee,
870 TRT (CallType::*)(TP1,TP2)const>
871 makeFunctor(CBFunctor2wRet<P1,P2,RT>*,const Callee &c,
872 TRT (CallType::* RHCB_CONST_REF f)(TP1,TP2)const)
873 {
874 typedef TRT (CallType::*MemFunc)(TP1,TP2)const;
875 return CBMemberTranslator2wRet<P1,P2,RT,const
Callee,MemFunc>(c,f);
876 }
877
878 template <class P1,class P2,class RT,class TRT,class TP1,class
TP2>
879 inline CBFunctionTranslator2wRet<P1,P2,RT,TRT (*)(TP1,TP2)>
880 makeFunctor(CBFunctor2wRet<P1,P2,RT>*,TRT (*f)(TP1,TP2))
881 {
882 return CBFunctionTranslator2wRet<P1,P2,RT,TRT
(*)(TP1,TP2)>(f);
883 }
884
885 template <class P1,class P2,class RT,class MemFunc>
886 class CBMemberOf1stArgTranslator2wRet:public
CBFunctor2wRet<P1,P2,RT>{
887 public:
888 CBMemberOf1stArgTranslator2wRet(const MemFunc &m):
889 CBFunctor2wRet<P1,P2,RT>(thunk,(void
*)1,0,&m,sizeof(MemFunc)){}
890 static RT thunk(const CBFunctorBase &ftor,P1 p1,P2 p2)
891 {
892 MemFunc &memFunc RHCB_CTOR_STYLE_INIT
893 (*(MemFunc*)(void *)(ftor.getMemFunc()));
894 return RHCB_BC4_RET_BUG((p1.*memFunc)(p2));
895 }
896 };
897
898 #if !defined(RHCB_CANT_OVERLOAD_ON_CONSTNESS)
899 template <class P1,class P2,class RT,class TRT,class
CallType,class TP1>
900 inline CBMemberOf1stArgTranslator2wRet<P1,P2,RT,TRT
(CallType::*)(TP1)>
901 makeFunctor(CBFunctor2wRet<P1,P2,RT>*,TRT (CallType::*
RHCB_CONST_REF f)(TP1))
902 {
903 typedef TRT (CallType::*MemFunc)(TP1);
904 return CBMemberOf1stArgTranslator2wRet<P1,P2,RT,MemFunc>(f);
905 }
906 #endif
907
908 template <class P1,class P2,class RT,class TRT,class
CallType,class TP1>
909 inline CBMemberOf1stArgTranslator2wRet<P1,P2,RT,TRT
(CallType::*)(TP1)const>
910 makeFunctor(CBFunctor2wRet<P1,P2,RT>*,
911 TRT (CallType::* RHCB_CONST_REF f)(TP1)const)
912 {
913 typedef TRT (CallType::*MemFunc)(TP1)const;
914 return CBMemberOf1stArgTranslator2wRet<P1,P2,RT,MemFunc>(f);
915 }
916
917
918 /************************* three args - no return
*******************/
919 template <class P1,class P2,class P3>
920 class CBFunctor3:public CBFunctorBase{
921 public:
922 CBFunctor3(RHCB_DUMMY_INIT = 0){}
923 void operator()(P1 p1,P2 p2,P3 p3)const
924 {
925 thunk(*this,p1,p2,p3);
926 }
927 protected:
928 typedef void (*Thunk)(const CBFunctorBase &,P1,P2,P3);
929 CBFunctor3(Thunk t,const void *c,PFunc f,const void *mf,size_t
sz):
930 CBFunctorBase(c,f,mf,sz),thunk(t){}
931 private:
932 Thunk thunk;
933 };
934
935 template <class P1,class P2,class P3,class Callee, class
MemFunc>
936 class CBMemberTranslator3:public CBFunctor3<P1,P2,P3>{
937 public:
938 CBMemberTranslator3(Callee &c,const MemFunc &m):
939 CBFunctor3<P1,P2,P3>(thunk,&c,0,&m,sizeof(MemFunc)){}
940 static void thunk(const CBFunctorBase &ftor,P1 p1,P2 p2,P3 p3)
941 {
942 Callee *callee = (Callee *)ftor.getCallee();
943 MemFunc &memFunc RHCB_CTOR_STYLE_INIT
944 (*(MemFunc*)(void *)(ftor.getMemFunc()));
945 (callee->*memFunc)(p1,p2,p3);
946 }
947 };
948
949 template <class P1,class P2,class P3,class Func>
950 class CBFunctionTranslator3:public CBFunctor3<P1,P2,P3>{
951 public:
952 CBFunctionTranslator3(Func
f):CBFunctor3<P1,P2,P3>(thunk,0,(PFunc)f,0,0){}
953 static void thunk(const CBFunctorBase &ftor,P1 p1,P2 p2,P3 p3)
954 {
955 (Func(ftor.getFunc()))(p1,p2,p3);
956 }
957 };
958
959 #if !defined(RHCB_CANT_OVERLOAD_ON_CONSTNESS)
960 template <class P1,class P2,class P3,class Callee,
961 class TRT,class CallType,class TP1,class TP2,class TP3>
962 inline CBMemberTranslator3<P1,P2,P3,Callee,
963 TRT (CallType::*)(TP1,TP2,TP3)>
964 makeFunctor(CBFunctor3<P1,P2,P3>*,Callee &c,
965 TRT (CallType::* RHCB_CONST_REF f)(TP1,TP2,TP3))
966 {
967 typedef TRT (CallType::*MemFunc)(TP1,TP2,TP3);
968 return CBMemberTranslator3<P1,P2,P3,Callee,MemFunc>(c,f);
969 }
970 #endif
971
972 template <class P1,class P2,class P3,class Callee,
973 class TRT,class CallType,class TP1,class TP2,class TP3>
974 inline CBMemberTranslator3<P1,P2,P3,const Callee,
975 TRT (CallType::*)(TP1,TP2,TP3)const>
976 makeFunctor(CBFunctor3<P1,P2,P3>*,const Callee &c,
977 TRT (CallType::* RHCB_CONST_REF f)(TP1,TP2,TP3)const)
978 {
979 typedef TRT (CallType::*MemFunc)(TP1,TP2,TP3)const;
980 return CBMemberTranslator3<P1,P2,P3,const
Callee,MemFunc>(c,f);
981 }
982
983 template <class P1,class P2,class P3,
984 class TRT,class TP1,class TP2,class TP3>
985 inline CBFunctionTranslator3<P1,P2,P3,TRT (*)(TP1,TP2,TP3)>
986 makeFunctor(CBFunctor3<P1,P2,P3>*,TRT (*f)(TP1,TP2,TP3))
987 {
988 return CBFunctionTranslator3<P1,P2,P3,TRT
(*)(TP1,TP2,TP3)>(f);
989 }
990
991 template <class P1,class P2,class P3,class MemFunc>
992 class CBMemberOf1stArgTranslator3:public CBFunctor3<P1,P2,P3>{
993 public:
994 CBMemberOf1stArgTranslator3(const MemFunc &m):
995 CBFunctor3<P1,P2,P3>(thunk,(void
*)1,0,&m,sizeof(MemFunc)){}
996 static void thunk(const CBFunctorBase &ftor,P1 p1,P2 p2,P3 p3)
997 {
998 MemFunc &memFunc RHCB_CTOR_STYLE_INIT
999 (*(MemFunc*)(void *)(ftor.getMemFunc()));
1000 (p1.*memFunc)(p2,p3);
1001 }
1002 };
1003
1004 #if !defined(RHCB_CANT_OVERLOAD_ON_CONSTNESS)
1005 template <class P1,class P2,class P3,class TRT,class CallType,
1006 class TP1,class TP2>
1007 inline CBMemberOf1stArgTranslator3<P1,P2,P3,TRT
(CallType::*)(TP1,TP2)>
1008 makeFunctor(CBFunctor3<P1,P2,P3>*,TRT (CallType::*
RHCB_CONST_REF f)(TP1,TP2))
1009 {
1010 typedef TRT (CallType::*MemFunc)(TP1,TP2);
1011 return CBMemberOf1stArgTranslator3<P1,P2,P3,MemFunc>(f);
1012 }
1013 #endif
1014
1015 template <class P1,class P2,class P3,class TRT,class CallType,
1016 class TP1,class TP2>
1017 inline CBMemberOf1stArgTranslator3<P1,P2,P3,TRT
(CallType::*)(TP1,TP2)const>
1018 makeFunctor(CBFunctor3<P1,P2,P3>*,
1019 TRT (CallType::* RHCB_CONST_REF f)(TP1,TP2)const)
1020 {
1021 typedef TRT (CallType::*MemFunc)(TP1,TP2)const;
1022 return CBMemberOf1stArgTranslator3<P1,P2,P3,MemFunc>(f);
1023 }
1024
1025
1026 /************************* three args - with return
*******************/
1027 template <class P1,class P2,class P3,class RT>
1028 class CBFunctor3wRet:public CBFunctorBase{
1029 public:
1030 CBFunctor3wRet(RHCB_DUMMY_INIT = 0){}
1031 RT operator()(P1 p1,P2 p2,P3 p3)const
1032 {
1033 return RHCB_BC4_RET_BUG(thunk(*this,p1,p2,p3));
1034 }
1035 protected:
1036 typedef RT (*Thunk)(const CBFunctorBase &,P1,P2,P3);
1037 CBFunctor3wRet(Thunk t,const void *c,PFunc f,const void
*mf,size_t sz):
1038 CBFunctorBase(c,f,mf,sz),thunk(t){}
1039 private:
1040 Thunk thunk;
1041 };
1042
1043 template <class P1,class P2,class P3,
1044 class RT,class Callee, class MemFunc>
1045 class CBMemberTranslator3wRet:public
CBFunctor3wRet<P1,P2,P3,RT>{
1046 public:
1047 CBMemberTranslator3wRet(Callee &c,const MemFunc &m):
1048
CBFunctor3wRet<P1,P2,P3,RT>(thunk,&c,0,&m,sizeof(MemFunc)){}
1049 static RT thunk(const CBFunctorBase &ftor,P1 p1,P2 p2,P3 p3)
1050 {
1051 Callee *callee = (Callee *)ftor.getCallee();
1052 MemFunc &memFunc RHCB_CTOR_STYLE_INIT
1053 (*(MemFunc*)(void *)(ftor.getMemFunc()));
1054 return RHCB_BC4_RET_BUG((callee->*memFunc)(p1,p2,p3));
1055 }
1056 };
1057
1058 template <class P1,class P2,class P3,class RT,class Func>
1059 class CBFunctionTranslator3wRet:public
CBFunctor3wRet<P1,P2,P3,RT>{
1060 public:
1061 CBFunctionTranslator3wRet(Func f):
1062 CBFunctor3wRet<P1,P2,P3,RT>(thunk,0,(PFunc)f,0,0){}
1063 static RT thunk(const CBFunctorBase &ftor,P1 p1,P2 p2,P3 p3)
1064 {
1065 return (Func(ftor.getFunc()))(p1,p2,p3);
1066 }
1067 };
1068
1069 #if !defined(RHCB_CANT_OVERLOAD_ON_CONSTNESS)
1070 template <class P1,class P2,class P3,class RT,class Callee,
1071 class TRT,class CallType,class TP1,class TP2,class TP3>
1072 inline CBMemberTranslator3wRet<P1,P2,P3,RT,Callee,
1073 TRT (CallType::*)(TP1,TP2,TP3)>
1074 makeFunctor(CBFunctor3wRet<P1,P2,P3,RT>*,Callee &c,
1075 TRT (CallType::* RHCB_CONST_REF f)(TP1,TP2,TP3))
1076 {
1077 typedef TRT (CallType::*MemFunc)(TP1,TP2,TP3);
1078 return CBMemberTranslator3wRet<P1,P2,P3,RT,Callee,MemFunc>(c,f);
1079 }
1080 #endif
1081
1082 template <class P1,class P2,class P3,class RT,class Callee,
1083 class TRT,class CallType,class TP1,class TP2,class TP3>
1084 inline CBMemberTranslator3wRet<P1,P2,P3,RT,const Callee,
1085 TRT (CallType::*)(TP1,TP2,TP3)const>
1086 makeFunctor(CBFunctor3wRet<P1,P2,P3,RT>*,const Callee &c,
1087 TRT (CallType::* RHCB_CONST_REF f)(TP1,TP2,TP3)const)
1088 {
1089 typedef TRT (CallType::*MemFunc)(TP1,TP2,TP3)const;
1090 return CBMemberTranslator3wRet<P1,P2,P3,RT,const
Callee,MemFunc>(c,f);
1091 }
1092
1093 template <class P1,class P2,class P3,class RT,
1094 class TRT,class TP1,class TP2,class TP3>
1095 inline CBFunctionTranslator3wRet<P1,P2,P3,RT,TRT
(*)(TP1,TP2,TP3)>
1096 makeFunctor(CBFunctor3wRet<P1,P2,P3,RT>*,TRT (*f)(TP1,TP2,TP3))
1097 {
1098 return CBFunctionTranslator3wRet<P1,P2,P3,RT,TRT
(*)(TP1,TP2,TP3)>(f);
1099 }
1100
1101 template <class P1,class P2,class P3,class RT,class MemFunc>
1102 class CBMemberOf1stArgTranslator3wRet:public
CBFunctor3wRet<P1,P2,P3,RT>{
1103 public:
1104 CBMemberOf1stArgTranslator3wRet(const MemFunc &m):
1105 CBFunctor3wRet<P1,P2,P3,RT>(thunk,(void
*)1,0,&m,sizeof(MemFunc)){}
1106 static RT thunk(const CBFunctorBase &ftor,P1 p1,P2 p2,P3 p3)
1107 {
1108 MemFunc &memFunc RHCB_CTOR_STYLE_INIT
1109 (*(MemFunc*)(void *)(ftor.getMemFunc()));
1110 return RHCB_BC4_RET_BUG((p1.*memFunc)(p2,p3));
1111 }
1112 };
1113
1114 #if !defined(RHCB_CANT_OVERLOAD_ON_CONSTNESS)
1115 template <class P1,class P2,class P3,class RT,class TRT,class
CallType,
1116 class TP1,class TP2>
1117 inline CBMemberOf1stArgTranslator3wRet<P1,P2,P3,RT,TRT
(CallType::*)(TP1,TP2)>
1118 makeFunctor(CBFunctor3wRet<P1,P2,P3,RT>*,
1119 TRT (CallType::* RHCB_CONST_REF f)(TP1,TP2))
1120 {
1121 typedef TRT (CallType::*MemFunc)(TP1,TP2);
1122 return CBMemberOf1stArgTranslator3wRet<P1,P2,P3,RT,MemFunc>(f);
1123 }
1124 #endif
1125
1126 template <class P1,class P2,class P3,class RT,class TRT,class
CallType,
1127 class TP1,class TP2>
1128 inline CBMemberOf1stArgTranslator3wRet<P1,P2,P3,RT,
1129 TRT (CallType::*)(TP1,TP2)const>
1130 makeFunctor(CBFunctor3wRet<P1,P2,P3,RT>*,
1131 TRT (CallType::* RHCB_CONST_REF f)(TP1,TP2)const)
1132 {
1133 typedef TRT (CallType::*MemFunc)(TP1,TP2)const;
1134 return CBMemberOf1stArgTranslator3wRet<P1,P2,P3,RT,MemFunc>(f);
1135 }
1136
1137
1138 /************************* four args - no return
*******************/
1139 template <class P1,class P2,class P3,class P4>
1140 class CBFunctor4:public CBFunctorBase{
1141 public:
1142 CBFunctor4(RHCB_DUMMY_INIT = 0){}
1143 void operator()(P1 p1,P2 p2,P3 p3,P4 p4)const
1144 {
1145 thunk(*this,p1,p2,p3,p4);
1146 }
1147 protected:
1148 typedef void (*Thunk)(const CBFunctorBase &,P1,P2,P3,P4);
1149 CBFunctor4(Thunk t,const void *c,PFunc f,const void *mf,size_t
sz):
1150 CBFunctorBase(c,f,mf,sz),thunk(t){}
1151 private:
1152 Thunk thunk;
1153 };
1154
1155 template <class P1,class P2,class P3,class P4,
1156 class Callee, class MemFunc>
1157 class CBMemberTranslator4:public CBFunctor4<P1,P2,P3,P4>{
1158 public:
1159 CBMemberTranslator4(Callee &c,const MemFunc &m):
1160 CBFunctor4<P1,P2,P3,P4>(thunk,&c,0,&m,sizeof(MemFunc)){}
1161 static void thunk(const CBFunctorBase &ftor,P1 p1,P2 p2,P3
p3,P4 p4)
1162 {
1163 Callee *callee = (Callee *)ftor.getCallee();
1164 MemFunc &memFunc RHCB_CTOR_STYLE_INIT
1165 (*(MemFunc*)(void *)(ftor.getMemFunc()));
1166 (callee->*memFunc)(p1,p2,p3,p4);
1167 }
1168 };
1169
1170 template <class P1,class P2,class P3,class P4,class Func>
1171 class CBFunctionTranslator4:public CBFunctor4<P1,P2,P3,P4>{
1172 public:
1173 CBFunctionTranslator4(Func f):
1174 CBFunctor4<P1,P2,P3,P4>(thunk,0,(PFunc)f,0,0){}
1175 static void thunk(const CBFunctorBase &ftor,P1 p1,P2 p2,P3
p3,P4 p4)
1176 {
1177 (Func(ftor.getFunc()))(p1,p2,p3,p4);
1178 }
1179 };
1180
1181 #if !defined(RHCB_CANT_OVERLOAD_ON_CONSTNESS)
1182 template <class P1,class P2,class P3,class P4,class Callee,
1183 class TRT,class CallType,class TP1,class TP2,class TP3,class
TP4>
1184 inline CBMemberTranslator4<P1,P2,P3,P4,Callee,
1185 TRT (CallType::*)(TP1,TP2,TP3,TP4)>
1186 makeFunctor(CBFunctor4<P1,P2,P3,P4>*,Callee &c,
1187 TRT (CallType::* RHCB_CONST_REF f)(TP1,TP2,TP3,TP4))
1188 {
1189 typedef TRT (CallType::*MemFunc)(TP1,TP2,TP3,TP4);
1190 return CBMemberTranslator4<P1,P2,P3,P4,Callee,MemFunc>(c,f);
1191 }
1192 #endif
1193
1194 template <class P1,class P2,class P3,class P4,class Callee,
1195 class TRT,class CallType,class TP1,class TP2,class TP3,class
TP4>
1196 inline CBMemberTranslator4<P1,P2,P3,P4,const Callee,
1197 TRT (CallType::*)(TP1,TP2,TP3,TP4)const>
1198 makeFunctor(CBFunctor4<P1,P2,P3,P4>*,const Callee &c,
1199 TRT (CallType::* RHCB_CONST_REF f)(TP1,TP2,TP3,TP4)const)
1200 {
1201 typedef TRT (CallType::*MemFunc)(TP1,TP2,TP3,TP4)const;
1202 return CBMemberTranslator4<P1,P2,P3,P4,const
Callee,MemFunc>(c,f);
1203 }
1204
1205 template <class P1,class P2,class P3,class P4,
1206 class TRT,class TP1,class TP2,class TP3,class TP4>
1207 inline CBFunctionTranslator4<P1,P2,P3,P4,TRT
(*)(TP1,TP2,TP3,TP4)>
1208 makeFunctor(CBFunctor4<P1,P2,P3,P4>*,TRT (*f)(TP1,TP2,TP3,TP4))
1209 {
1210 return CBFunctionTranslator4<P1,P2,P3,P4,TRT
(*)(TP1,TP2,TP3,TP4)>(f);
1211 }
1212
1213 template <class P1,class P2,class P3,class P4,class MemFunc>
1214 class CBMemberOf1stArgTranslator4:public
CBFunctor4<P1,P2,P3,P4>{
1215 public:
1216 CBMemberOf1stArgTranslator4(const MemFunc &m):
1217 CBFunctor4<P1,P2,P3,P4>(thunk,(void
*)1,0,&m,sizeof(MemFunc)){}
1218 static void thunk(const CBFunctorBase &ftor,P1 p1,P2 p2,P3
p3,P4 p4)
1219 {
1220 MemFunc &memFunc RHCB_CTOR_STYLE_INIT
1221 (*(MemFunc*)(void *)(ftor.getMemFunc()));
1222 (p1.*memFunc)(p2,p3,p4);
1223 }
1224 };
1225
1226 #if !defined(RHCB_CANT_OVERLOAD_ON_CONSTNESS)
1227 template <class P1,class P2,class P3,class P4,class TRT,class
CallType,
1228 class TP1,class TP2,class TP3>
1229 inline CBMemberOf1stArgTranslator4<P1,P2,P3,P4,TRT
(CallType::*)(TP1,TP2,TP3)>
1230 makeFunctor(CBFunctor4<P1,P2,P3,P4>*,
1231 TRT (CallType::* RHCB_CONST_REF f)(TP1,TP2,TP3))
1232 {
1233 typedef TRT (CallType::*MemFunc)(TP1,TP2,TP3);
1234 return CBMemberOf1stArgTranslator4<P1,P2,P3,P4,MemFunc>(f);
1235 }
1236 #endif
1237
1238 template <class P1,class P2,class P3,class P4,class TRT,class
CallType,
1239 class TP1,class TP2,class TP3>
1240 inline CBMemberOf1stArgTranslator4<P1,P2,P3,P4,
1241 TRT (CallType::*)(TP1,TP2,TP3)const>
1242 makeFunctor(CBFunctor4<P1,P2,P3,P4>*,
1243 TRT (CallType::* RHCB_CONST_REF f)(TP1,TP2,TP3)const)
1244 {
1245 typedef TRT (CallType::*MemFunc)(TP1,TP2,TP3)const;
1246 return CBMemberOf1stArgTranslator4<P1,P2,P3,P4,MemFunc>(f);
1247 }
1248
1249
1250 /************************* four args - with return
*******************/
1251 template <class P1,class P2,class P3,class P4,class RT>
1252 class CBFunctor4wRet:public CBFunctorBase{
1253 public:
1254 CBFunctor4wRet(RHCB_DUMMY_INIT = 0){}
1255 RT operator()(P1 p1,P2 p2,P3 p3,P4 p4)const
1256 {
1257 return RHCB_BC4_RET_BUG(thunk(*this,p1,p2,p3,p4));
1258 }
1259 protected:
1260 typedef RT (*Thunk)(const CBFunctorBase &,P1,P2,P3,P4);
1261 CBFunctor4wRet(Thunk t,const void *c,PFunc f,const void
*mf,size_t sz):
1262 CBFunctorBase(c,f,mf,sz),thunk(t){}
1263 private:
1264 Thunk thunk;
1265 };
1266
1267 template <class P1,class P2,class P3,class P4,class RT,
1268 class Callee, class MemFunc>
1269 class CBMemberTranslator4wRet:public
CBFunctor4wRet<P1,P2,P3,P4,RT>{
1270 public:
1271 CBMemberTranslator4wRet(Callee &c,const MemFunc &m):
1272
CBFunctor4wRet<P1,P2,P3,P4,RT>(thunk,&c,0,&m,sizeof(MemFunc)){}
1273 static RT thunk(const CBFunctorBase &ftor,P1 p1,P2 p2,P3 p3,P4
p4)
1274 {
1275 Callee *callee = (Callee *)ftor.getCallee();
1276 MemFunc &memFunc RHCB_CTOR_STYLE_INIT
1277 (*(MemFunc*)(void *)(ftor.getMemFunc()));
1278 return
RHCB_BC4_RET_BUG((callee->*memFunc)(p1,p2,p3,p4));
1279 }
1280 };
1281
1282 template <class P1,class P2,class P3,class P4,class RT,class
Func>
1283 class CBFunctionTranslator4wRet:public
CBFunctor4wRet<P1,P2,P3,P4,RT>{
1284 public:
1285 CBFunctionTranslator4wRet(Func f):
1286 CBFunctor4wRet<P1,P2,P3,P4,RT>(thunk,0,(PFunc)f,0,0){}
1287 static RT thunk(const CBFunctorBase &ftor,P1 p1,P2 p2,P3 p3,P4
p4)
1288 {
1289 return (Func(ftor.getFunc()))(p1,p2,p3,p4);
1290 }
1291 };
1292
1293 #if !defined(RHCB_CANT_OVERLOAD_ON_CONSTNESS)
1294 template <class P1,class P2,class P3,class P4,class RT,class
Callee,
1295 class TRT,class CallType,class TP1,class TP2,class TP3,class
TP4>
1296 inline CBMemberTranslator4wRet<P1,P2,P3,P4,RT,Callee,
1297 TRT (CallType::*)(TP1,TP2,TP3,TP4)>
1298 makeFunctor(CBFunctor4wRet<P1,P2,P3,P4,RT>*,Callee &c,
1299 TRT (CallType::* RHCB_CONST_REF f)(TP1,TP2,TP3,TP4))
1300 {
1301 typedef TRT (CallType::*MemFunc)(TP1,TP2,TP3,TP4);
1302 return
CBMemberTranslator4wRet<P1,P2,P3,P4,RT,Callee,MemFunc>(c,f);
1303 }
1304 #endif
1305
1306 template <class P1,class P2,class P3,class P4,class RT,class
Callee,
1307 class TRT,class CallType,class TP1,class TP2,class TP3,class
TP4>
1308 inline CBMemberTranslator4wRet<P1,P2,P3,P4,RT,const Callee,
1309 TRT (CallType::*)(TP1,TP2,TP3,TP4)const>
1310 makeFunctor(CBFunctor4wRet<P1,P2,P3,P4,RT>*,const Callee &c,
1311 TRT (CallType::* RHCB_CONST_REF f)(TP1,TP2,TP3,TP4)const)
1312 {
1313 typedef TRT (CallType::*MemFunc)(TP1,TP2,TP3,TP4)const;
1314 return CBMemberTranslator4wRet<P1,P2,P3,P4,RT,const
Callee,MemFunc>(c,f);
1315 }
1316
1317 template <class P1,class P2,class P3,class P4,class RT,
1318 class TRT,class TP1,class TP2,class TP3,class TP4>
1319 inline CBFunctionTranslator4wRet<P1,P2,P3,P4,RT,TRT
(*)(TP1,TP2,TP3,TP4)>
1320 makeFunctor(CBFunctor4wRet<P1,P2,P3,P4,RT>*,TRT
(*f)(TP1,TP2,TP3,TP4))
1321 {
1322 return CBFunctionTranslator4wRet
1323 <P1,P2,P3,P4,RT,TRT (*)(TP1,TP2,TP3,TP4)>(f);
1324 }
1325
1326
1327 template <class P1,class P2,class P3,class P4,class RT,class
MemFunc>
1328 class CBMemberOf1stArgTranslator4wRet:public
CBFunctor4wRet<P1,P2,P3,P4,RT>{
1329 public:
1330 CBMemberOf1stArgTranslator4wRet(const MemFunc &m):
1331 CBFunctor4wRet<P1,P2,P3,P4,RT>(thunk,(void
*)1,0,&m,sizeof(MemFunc)){}
1332 static RT thunk(const CBFunctorBase &ftor,P1 p1,P2 p2,P3 p3,P4
p4)
1333 {
1334 MemFunc &memFunc RHCB_CTOR_STYLE_INIT
1335 (*(MemFunc*)(void *)(ftor.getMemFunc()));
1336 return RHCB_BC4_RET_BUG((p1.*memFunc)(p2,p3,p4));
1337 }
1338 };
1339
1340 #if !defined(RHCB_CANT_OVERLOAD_ON_CONSTNESS)
1341 template <class P1,class P2,class P3,class P4,class RT,class
TRT,
1342 class CallType,class TP1,class TP2,class TP3>
1343 inline CBMemberOf1stArgTranslator4wRet<P1,P2,P3,P4,RT,
1344 TRT (CallType::*)(TP1,TP2,TP3)>
1345 makeFunctor(CBFunctor4wRet<P1,P2,P3,P4,RT>*,
1346 TRT (CallType::* RHCB_CONST_REF f)(TP1,TP2,TP3))
1347 {
1348 typedef TRT (CallType::*MemFunc)(TP1,TP2,TP3);
1349 return
CBMemberOf1stArgTranslator4wRet<P1,P2,P3,P4,RT,MemFunc>(f);
1350 }
1351 #endif
1352
1353 template <class P1,class P2,class P3,class P4,class RT,class
TRT,
1354 class CallType,class TP1,class TP2,class TP3>
1355 inline CBMemberOf1stArgTranslator4wRet<P1,P2,P3,P4,RT,
1356 TRT (CallType::*)(TP1,TP2,TP3)const>
1357 makeFunctor(CBFunctor4wRet<P1,P2,P3,P4,RT>*,
1358 TRT (CallType::* RHCB_CONST_REF f)(TP1,TP2,TP3)const)
1359 {
1360 typedef TRT (CallType::*MemFunc)(TP1,TP2,TP3)const;
1361 return
CBMemberOf1stArgTranslator4wRet<P1,P2,P3,P4,RT,MemFunc>(f);
1362 }
1363
1364
1365 #endif //_CALLBACK_HH
1366
Here are the warnings that I cannot prevent:
In file included from
/data/swalton/tree/inc/hcmCallbackHandler.hh:217,
from ../src/hcmCallbackHandler.cpp:113:
/data/swalton/tree/inc/Callback.hh: In constructor `
CBFunctionTranslator0wRet<RT,
Func>::CBFunctionTranslator0wRet(Func)':
/data/swalton/tree/inc/Callback.hh:460: warning:
`CBFunctionTranslator0wRet<RT,
Func>::PFunc' is implicitly a typename
/data/swalton/tree/inc/Callback.hh: In constructor
`CBFunctionTranslator1<P1,
Func>::CBFunctionTranslator1(Func)':
/data/swalton/tree/inc/Callback.hh:530: warning:
`CBFunctionTranslator1<P1,
Func>::PFunc' is implicitly a typename
/data/swalton/tree/inc/Callback.hh: In constructor `
CBFunctionTranslator1wRet<P1, RT,
Func>::CBFunctionTranslator1wRet(Func)':
/data/swalton/tree/inc/Callback.hh:632: warning:
`CBFunctionTranslator1wRet<P1,
RT, Func>::PFunc' is implicitly a typename
/data/swalton/tree/inc/Callback.hh: In constructor
`CBFunctionTranslator2<P1,
P2, Func>::CBFunctionTranslator2(Func)':
/data/swalton/tree/inc/Callback.hh:739: warning:
`CBFunctionTranslator2<P1, P2,
Func>::PFunc' is implicitly a typename
/data/swalton/tree/inc/Callback.hh: In constructor `
CBFunctionTranslator2wRet<P1, P2, RT,
Func>::CBFunctionTranslator2wRet(Func)
':
/data/swalton/tree/inc/Callback.hh:847: warning:
`CBFunctionTranslator2wRet<P1,
P2, RT, Func>::PFunc' is implicitly a typename
/data/swalton/tree/inc/Callback.hh: In constructor
`CBFunctionTranslator3<P1,
P2, P3, Func>::CBFunctionTranslator3(Func)':
/data/swalton/tree/inc/Callback.hh:952: warning:
`CBFunctionTranslator3<P1, P2,
P3, Func>::PFunc' is implicitly a typename
/data/swalton/tree/inc/Callback.hh: In constructor `
CBFunctionTranslator3wRet<P1, P2, P3, RT,
Func>::CBFunctionTranslator3wRet(Func)':
/data/swalton/tree/inc/Callback.hh:1062: warning: `
CBFunctionTranslator3wRet<P1, P2, P3, RT, Func>::PFunc' is
implicitly a
typename
/data/swalton/tree/inc/Callback.hh: In constructor
`CBFunctionTranslator4<P1,
P2, P3, P4, Func>::CBFunctionTranslator4(Func)':
/data/swalton/tree/inc/Callback.hh:1174: warning:
`CBFunctionTranslator4<P1,
P2, P3, P4, Func>::PFunc' is implicitly a typename
/data/swalton/tree/inc/Callback.hh: In constructor `
CBFunctionTranslator4wRet<P1, P2, P3, P4, RT,
Func>::CBFunctionTranslator4wRet(Func)':
/data/swalton/tree/inc/Callback.hh:1286: warning: `
CBFunctionTranslator4wRet<P1, P2, P3, P4, RT, Func>::PFunc' is
implicitly a
typename
- G++ 3 and typename warnings,
Shane Walton <=