求大神解释 #define问题

#define DEFINE_BASECALSS class Call{ public: virtual RT call(TPARAM) = 0; virtual RT call(TPARAM) const = 0;};

#define DEFINE_FUNCALSS template<typename F> class FunCall : Call { public: FunCall(F f):m_func(f){} protected: F m_func;\
virtual RT call(TPARAM){ return m_func(PARAM);}\
virtual RT call(TPARAM) const { return m_func(PARAM);}};

#define DEFINE_MEMCALSS template<typename O,typename F> class MemCall : public Call{public:MemCall(O* obj,F f):m_obj(obj),m_func(f){} protected:O* m_obj;F m_func;\
	virtual RT call(TPARAM){ return ((m_obj)->*m_func)(PARAM);}\
	virtual RT call(TPARAM) const{ return ((m_obj)->*m_func)(PARAM);}};

#define DEFINE_CALL(CLASSNAME) template <typename RT,TEMPLATE size_t size = 4 * sizeof(void*)>\
	class CLASSNAME\
	{\
	protected:\
	DEFINE_BASECALSS\
	DEFINE_MEMCALSS\
	DEFINE_FUNCALSS\
	public:\
	template <typename O,typename F>\
	CLASSNAME(O* obj,F f):m_call(0)\
	{\
		assert(sizeof(MemCall<O,F>) <= size);\
		m_call = new (&m_buffer[0]) MemCall<O,F>(obj,f);\
	}\
	template<typename F>\
	CLASSNAME(F f):m_call(0)\
	{\
		m_call = new (&m_buffer[0]) FunCall<F>(f);\
	}\
	CLASSNAME():m_call(0){}\
	CLASSNAME(const CLASSNAME& cf)\
	{\
		m_call = (Call*)&m_buffer[0];\
		memcpy(m_buffer,cf.m_buffer,sizeof(m_buffer));\
	}\
        void operator = (const CLASSNAME& cf)\
        {\
        m_call = (Call*)&m_buffer[0];\
        memcpy(m_buffer,cf.m_buffer,sizeof(m_buffer));\
        }\
	RT call(TPARAM)\
	{\
		if(m_call)return m_call->call(PARAM);\
		return RT();\
	}\
	RT call(TPARAM) const\
	{\
		if(m_call)return m_call->call(PARAM);\
		return RT();\
    }\
	protected:\
		Call* m_call;\
		char m_buffer[size];\
	};



template <typename RT, size_t size = 4 * sizeof(void*)>
class CallFunc_0
{
protected:
    class Call
    {
    public: 
        virtual RT call() = 0; 
        virtual RT call() const = 0;
    };
    template<typename O,typename F> 
    class MemCall : public Call{
    public:
        MemCall(O* obj,F f):m_obj(obj),m_func(f){} 
    protected:
        O* m_obj;
        F m_func;
        virtual RT call()
        {
            return ((m_obj)->*m_func)();
        }
        virtual RT call() const
        {
            return ((m_obj)->*m_func)();
        }
    };
    template<typename F> 
    class FunCall : Call 
    { 
    public: 
        FunCall(F f):m_func(f){} 
    protected: 
        F m_func;
        virtual RT call()
        { return m_func();}
        virtual RT call() const 
        { return m_func();}
    };
public:
    template <typename O,typename F>
    CallFunc_0(O* obj,F f):m_call(0)
    {
        assert(sizeof(MemCall<O,F>) <= size);
        m_call = new (&m_buffer[0]) MemCall<O,F>(obj,f);
    }
    template<typename F>
    CallFunc_0(F f):m_call(0)
    {
        m_call = new (&m_buffer[0]) FunCall<F>(f);
    }
    CallFunc_0():m_call(0){}
    CallFunc_0(const CallFunc_0& cf)
    {
        m_call = (Call*)&m_buffer[0];
        memcpy(m_buffer,cf.m_buffer,sizeof(m_buffer));
    }
    void operator = (const CallFunc_0& cf)
    {
        m_call = (Call*)&m_buffer[0];
        memcpy(m_buffer,cf.m_buffer,sizeof(m_buffer));
    }
    RT call()
    {
        if(m_call)return m_call->call();
        return RT();
    }
    RT call() const
    {
        if(m_call)return m_call->call();
        return RT();
    }
protected:
    Call* m_call;
    char m_buffer[size];
};

#define TEMPLATE typename P1, 这种define 看不懂??
#define TPARAM P1 p1
#define PARAM p1
DEFINE_CALL(CallFunc_1)
#undef TPARAM
#undef PARAM
#undef TEMPLATE

#define TEMPLATE typename P1,typename P2,  同样看不懂
#define TPARAM P1 p1,P2 p2
#define PARAM p1,p2
DEFINE_CALL(CallFunc_2)
#undef TPARAM
#undef PARAM
#undef TEMPLATE


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值