[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: G++ 3 and typename warnings
From: |
Shane Walton |
Subject: |
Re: G++ 3 and typename warnings |
Date: |
15 Sep 2004 06:44:57 -0700 |
I am having a hard time understanding this code, so I hope cutting it
down to 256 lines minus line numbers will help. I have also listed
the warning output that I am trying to prevent. Thanks again for the
help.
#ifndef _CALLBACK_HH
#define _CALLBACK_HH
#define RHCB_BC4_RET_BUG(x) x
#define RHCB_CONST_REF const &
#define RHCB_CTOR_STYLE_INIT
#define RHCB_DUMMY_INIT DummyInit *
////////////////////////////// THE CODE //////////////////////////
//change these when your compiler gets bool
typedef int RHCB_BOOL;
enum {RHCB_FALSE ,RHCB_TRUE};
#include <string.h> //for memstuff
#include <stddef.h> //for size_t
//typeless representation of a function and optional object
class CBFunctorBase{
public:
class DummyInit{};
typedef void (CBFunctorBase::*PMemFunc)();
typedef void (*PFunc)();
enum {MEM_FUNC_SIZE = sizeof(PMemFunc)};
PFunc getFunc() const {return func;}
void *getCallee() const {return callee;}
const char *getMemFunc() const {return memFunc;}
protected:
union{
PFunc func;
char memFunc[MEM_FUNC_SIZE];
};
void *callee;
CBFunctorBase():callee(0),func(0){}
CBFunctorBase(const void *c,PFunc f, const void *mf,size_t sz):
callee((void *)c)
{
if(c) //must be callee/memfunc
{
memcpy(memFunc,mf,sz);
if(sz<MEM_FUNC_SIZE)
{
memset(memFunc+sz,0,MEM_FUNC_SIZE-sz);
}
}
else //must be ptr-to-func
{
func = f;
}
}
};
/************************* one arg - no return *******************/
template <class P1>
class CBFunctor1:public CBFunctorBase{
public:
CBFunctor1(RHCB_DUMMY_INIT = 0){}
void operator()(P1 p1)const
{
thunk(*this,p1);
}
//for STL
typedef P1 argument_type;
typedef void result_type;
protected:
typedef void (*Thunk)(const CBFunctorBase &,P1);
CBFunctor1(Thunk t,const void *c,PFunc f,const void *mf,size_t sz):
CBFunctorBase(c,f,mf,sz),thunk(t){}
private:
Thunk thunk;
};
template <class P1,class Callee, class MemFunc>
class CBMemberTranslator1:public CBFunctor1<P1>{
public:
CBMemberTranslator1(Callee &c,const MemFunc &m):
CBFunctor1<P1>(thunk,&c,0,&m,sizeof(MemFunc)){}
static void thunk(const CBFunctorBase &ftor,P1 p1)
{
Callee *callee = (Callee *)ftor.getCallee();
MemFunc &memFunc RHCB_CTOR_STYLE_INIT
(*(MemFunc*)(void *)(ftor.getMemFunc()));
(callee->*memFunc)(p1);
}
};
template <class P1,class Func>
class CBFunctionTranslator1:public CBFunctor1<P1>{
public:
CBFunctionTranslator1(Func f):CBFunctor1<P1>(thunk,0,(PFunc)f,0,0){}
static void thunk(const CBFunctorBase &ftor,P1 p1)
{
(Func(ftor.getFunc()))(p1);
}
};
#if !defined(RHCB_CANT_OVERLOAD_ON_CONSTNESS)
template <class P1,class Callee,class TRT,class CallType,class TP1>
inline CBMemberTranslator1<P1,Callee,TRT (CallType::*)(TP1)>
makeFunctor(CBFunctor1<P1>*,Callee &c,
TRT (CallType::* RHCB_CONST_REF f)(TP1))
{
typedef TRT (CallType::*MemFunc)(TP1);
return CBMemberTranslator1<P1,Callee,MemFunc>(c,f);
}
#endif
template <class P1,class Callee,class TRT,class CallType,class TP1>
inline CBMemberTranslator1<P1,const Callee,TRT
(CallType::*)(TP1)const>
makeFunctor(CBFunctor1<P1>*,const Callee &c,
TRT (CallType::* RHCB_CONST_REF f)(TP1)const)
{
typedef TRT (CallType::*MemFunc)(TP1)const;
return CBMemberTranslator1<P1,const Callee,MemFunc>(c,f);
}
template <class P1,class TRT,class TP1>
inline CBFunctionTranslator1<P1,TRT (*)(TP1)>
makeFunctor(CBFunctor1<P1>*,TRT (*f)(TP1))
{
return CBFunctionTranslator1<P1,TRT (*)(TP1)>(f);
}
template <class P1,class MemFunc>
class CBMemberOf1stArgTranslator1:public CBFunctor1<P1>{
public:
CBMemberOf1stArgTranslator1(const MemFunc &m):
CBFunctor1<P1>(thunk,(void *)1,0,&m,sizeof(MemFunc)){}
static void thunk(const CBFunctorBase &ftor,P1 p1)
{
MemFunc &memFunc RHCB_CTOR_STYLE_INIT
(*(MemFunc*)(void *)(ftor.getMemFunc()));
(p1.*memFunc)();
}
};
#if !defined(RHCB_CANT_OVERLOAD_ON_CONSTNESS)
template <class P1,class TRT,class CallType>
inline CBMemberOf1stArgTranslator1<P1,TRT (CallType::*)()>
makeFunctor(CBFunctor1<P1>*,TRT (CallType::* RHCB_CONST_REF f)())
{
typedef TRT (CallType::*MemFunc)();
return CBMemberOf1stArgTranslator1<P1,MemFunc>(f);
}
#endif
template <class P1,class TRT,class CallType>
inline CBMemberOf1stArgTranslator1<P1,TRT (CallType::*)()const>
makeFunctor(CBFunctor1<P1>*,TRT (CallType::* RHCB_CONST_REF f)()const)
{
typedef TRT (CallType::*MemFunc)()const;
return CBMemberOf1stArgTranslator1<P1,MemFunc>(f);
}
/************************* one arg - with return *******************/
template <class P1,class RT>
class CBFunctor1wRet:public CBFunctorBase{
public:
CBFunctor1wRet(RHCB_DUMMY_INIT = 0){}
RT operator()(P1 p1)const
{
return RHCB_BC4_RET_BUG(thunk(*this,p1));
}
//for STL
typedef P1 argument_type;
typedef RT result_type;
protected:
typedef RT (*Thunk)(const CBFunctorBase &,P1);
CBFunctor1wRet(Thunk t,const void *c,PFunc f,
const void *mf,size_t sz):
CBFunctorBase(c,f,mf,sz),thunk(t){}
private:
Thunk thunk;
};
template <class P1,class RT,class Callee, class MemFunc>
class CBMemberTranslator1wRet:public CBFunctor1wRet<P1,RT>{
public:
CBMemberTranslator1wRet(Callee &c,const MemFunc &m):
CBFunctor1wRet<P1,RT>(thunk,&c,0,&m,sizeof(MemFunc)){}
static RT thunk(const CBFunctorBase &ftor,P1 p1)
{
Callee *callee = (Callee *)ftor.getCallee();
MemFunc &memFunc RHCB_CTOR_STYLE_INIT
(*(MemFunc*)(void *)(ftor.getMemFunc()));
return RHCB_BC4_RET_BUG((callee->*memFunc)(p1));
}
};
template <class P1,class RT,class Func>
class CBFunctionTranslator1wRet:public CBFunctor1wRet<P1,RT>{
public:
CBFunctionTranslator1wRet(Func f):
CBFunctor1wRet<P1,RT>(thunk,0,(PFunc)f,0,0){}
static RT thunk(const CBFunctorBase &ftor,P1 p1)
{
return (Func(ftor.getFunc()))(p1);
}
};
#if !defined(RHCB_CANT_OVERLOAD_ON_CONSTNESS)
template <class P1,class RT,
class Callee,class TRT,class CallType,class TP1>
inline CBMemberTranslator1wRet<P1,RT,Callee,TRT (CallType::*)(TP1)>
makeFunctor(CBFunctor1wRet<P1,RT>*,Callee &c,
TRT (CallType::* RHCB_CONST_REF f)(TP1))
{
typedef TRT (CallType::*MemFunc)(TP1);
return CBMemberTranslator1wRet<P1,RT,Callee,MemFunc>(c,f);
}
#endif
template <class P1,class RT,
class Callee,class TRT,class CallType,class TP1>
inline CBMemberTranslator1wRet<P1,RT,
const Callee,TRT (CallType::*)(TP1)const>
makeFunctor(CBFunctor1wRet<P1,RT>*,
const Callee &c,TRT (CallType::* RHCB_CONST_REF f)(TP1)const)
{
typedef TRT (CallType::*MemFunc)(TP1)const;
return CBMemberTranslator1wRet<P1,RT,const Callee,MemFunc>(c,f);
}
template <class P1,class RT,class TRT,class TP1>
inline CBFunctionTranslator1wRet<P1,RT,TRT (*)(TP1)>
makeFunctor(CBFunctor1wRet<P1,RT>*,TRT (*f)(TP1))
{
return CBFunctionTranslator1wRet<P1,RT,TRT (*)(TP1)>(f);
}
template <class P1,class RT,class MemFunc>
class CBMemberOf1stArgTranslator1wRet:public CBFunctor1wRet<P1,RT>{
public:
CBMemberOf1stArgTranslator1wRet(const MemFunc &m):
CBFunctor1wRet<P1,RT>(thunk,(void *)1,0,&m,sizeof(MemFunc)){}
static RT thunk(const CBFunctorBase &ftor,P1 p1)
{
MemFunc &memFunc RHCB_CTOR_STYLE_INIT
(*(MemFunc*)(void *)(ftor.getMemFunc()));
return RHCB_BC4_RET_BUG((p1.*memFunc)());
}
};
#if !defined(RHCB_CANT_OVERLOAD_ON_CONSTNESS)
template <class P1,class RT,class TRT,class CallType>
inline CBMemberOf1stArgTranslator1wRet<P1,RT,TRT (CallType::*)()>
makeFunctor(CBFunctor1wRet<P1,RT>*,TRT (CallType::* RHCB_CONST_REF
f)())
{
typedef TRT (CallType::*MemFunc)();
return CBMemberOf1stArgTranslator1wRet<P1,RT,MemFunc>(f);
}
#endif
template <class P1,class RT,class TRT,class CallType>
inline CBMemberOf1stArgTranslator1wRet<P1,RT,TRT (CallType::*)()const>
makeFunctor(CBFunctor1wRet<P1,RT>*,
TRT (CallType::* RHCB_CONST_REF f)()const)
{
typedef TRT (CallType::*MemFunc)()const;
return CBMemberOf1stArgTranslator1wRet<P1,RT,MemFunc>(f);
}
#endif //_CALLBACK_HH
Callback.hh: In constructor
`CBFunctionTranslator1<P1, Func>::CBFunctionTranslator1(Func)':
Callback.hh:95: warning:
`CBFunctionTranslator1<P1, Func>::PFunc' is implicitly a typename
Callback.hh: In constructor
`CBFunctionTranslator1wRet<P1, RT,
Func>::CBFunctionTranslator1wRet(Func)':
Callback.hh:199: warning:
`CBFunctionTranslator1wRet<P1, RT, Func>::PFunc' is implicitly a
typename