谈一下信号分发器的作用及实现方法

信号分发器在很多游戏项目中都有使用,是一种典型的观察者模式。在游戏编程中,客户端的绘制往往需要靠逻辑数据来驱动,绘制通过监听信号等待逻辑的通知。当然了,逻辑模块跟逻辑模块相互之间的通知也可以使用信号。这种编程模式能够简化模块之间的通信问题,不需要引用烦人的指针调用,导致指针满屏飞的情况。C++恶心的地方就是在大型项目中,指针相当多。

那边,实现一个信号分发器需要哪些功能呢?我们知道,所谓的信号通知,无非就是函数调用。监听一个信号,其本质上就是绑定一个指针,这个问题的难点在于函数指针是各式各样的,那么我们怎么样来管理这些指针呢?毕竟我们是想通过一个类似list的集合来保存这些指针。有的人可能会想到用同一种list保持同一种指针,因为一个信号也许只对应一种函数签名,如果你采用了这种方法,那么很不幸告诉你,你实现起来会困难重重。要是在Java上,这个问题很好解决,因为JAVA上所有的引用类型对象都自动继承自Object对象。在C++上,解决这个问题一有两种方法:1是把所有的指针转换成int数值,这个能解决指针存问题。2是借用函数包装。这两种方法中,方法1显的很粗糙,无法实现类型安全检查;方法2就显示的很优雅,而且能在编译时期进行接口信号是否匹配问题的检查。那么接下来我们的讨论将以方法2为准,来讲解一个实现。

上面的指针保存问题是实现信号分发器遇到第一个要解决的问题。第二个问题就是,采用函数包装这种方式,为了方便函数调用,我们需要对参数进行序列化。

以下是一个信号分发器的实现原理的大体流程:

1.绑定一个信号,即有一个类似这样的结构: std::map>, 将函数指针放入信号对应的函数指针集中。

2.对这个信号进行通知,即通知这个信号找到对应的std::list, 然后将传递的参数进行序列化,将之传送到相应的处理例程,由相应的处理例程对参数进行反序列化,解析出各个参数,遍历std::list集合调用函数。

至此过程完毕,没错,就是这么简单。

总结一下需要用到的相应的库:一个类型萃取库traits,一个序列化库serialization,一个函数包装库callhelper。如果看过我之前博文的同学,那么就会注意到在下的小心机了,这三个库在下都一一按顺序发布过了。

接下来简单介绍下这个信号分发器的相应用法及主要功能。

这个库实现的主要三个优点:

1. 在调一次信号时只会产生一次序列化和一次反序列化消耗,这个应该是不可避免。大家要是有好的方法欢迎来讨论长知识(我见过会产生一次序列化和n次反序列化的信号库实现,原来公司项目中使用的一次实现就是这样,这个其实是没有必要的)。

2. 这个信号库允许一个信号对应多个不同签名的调用接口,至少实战中到底有没有这个必要,这里暂时不讨论。

3. 支持引用类型及指针类型的传递。

一个额外的支持就是这个库可以增加信号过滤器的,这个过滤器代码我就不贴出了。

接下来贴代码,说的再多,不如看代码:

#include "signalcall2/signalcall2.hpp"

// 声明一个信号并绑定一类签名
DECLARE_SIGNAL2(SIG_TEST,1,void(std::string&))
// 使用同一个信号并绑定别一类签名
VALIDE_SIGNAL(SIG_TEST,void(std::string ,int))

int main()
{
    // 定义一个类对象
    Stu stu;

    // 定义一个信号分发器对象
    signalcall::signalcall2 sig; // 你可能会好奇为什么是signalcall2,因为我还实现过一个版本1,这是版本2,版本1并不具备版本2的优雅性。
    // 绑定信号
    // 前两个接口是同一类型的签名
    sig.bindSignal(show);
    sig.bindSignal(&stu,&Stu::show);
    // 这个接口是不同的签名
    sig.bindSignal(show2);

    // sig.bindSignal(show3); // 当试图绑定show3函数,会编译不过,因为并没指声明信号SIG_TEST对应void(int)类型签名

    // 通知信号
    std::string str = "你好,我是字符串!";
    // 只会通知到void(std::string&)类型的接口
    sig.signal(str);

    // 只会通知到void(std::string,int)类型的接口
    sig.signal("我是void(std::string,int)类型的接口",1);

   // 解绑信号相应的接口
   sig.unbindSignal(show);

 
    

   // 或者解决信号的所有接口
   sig.unbindAllSignal();

return 0;
}

输出结果:

谈一下信号分发器的作用及实现方法_第1张图片

接下来是完整类库截图

//signalcall_config2.hpp
#ifndef SIGNALCALL_CONFIG2_INCLUDE
#define SIGNALCALL_CONFIG2_INCLUDE

#define NAMESPACE_SIGNALCALL_BEGIN    namespace signalcall{
#define NAMESPACE_SIGNALCALL_END    }

#include "serialization/archive.hpp"
#include "call_helper/call.hpp"

NAMESPACE_SIGNALCALL_BEGIN

typedef serialization::default_string_oarchive OArchive;
typedef serialization::default_string_iarchive IArchive;



NAMESPACE_SIGNALCALL_END
#endif
//signal_type2.hpp
#ifndef SIGNAL_TYPE_INCLUDE
#define SIGNAL_TYPE_INCLUDE

#include "traits/traits.hpp"

typedef unsigned int SigID; //消息ID的格式
typedef unsigned int ParamC; //函数参数个数

template struct signature_trait;

/**分一步直接定义信号**/
#define DECLARE_SIGNAL2(signal_name, signal_id, signature)                                            \
    enum {signal_name = signal_id};                                                                    \
                                                                                                    \
template<>                                                                                            \
struct signature_trait::arity>                        \
{                                                                                                    \
    typedef traits::function_traits::Function_Type Function_Type;                        \
    typedef traits::function_traits::FunctionP_Type FunctionP_Type;                        \
};


/**分两步定义信号**/
#define DECLARE_SIGNAL(signal_name,signal_id)                                                        \
    enum {signal_name = signal_id};


#define VALIDE_SIGNAL(signal_name,signature2)                                                        \
                                                                                                    \
template<>                                                                                            \
struct signature_trait::arity>                        \
{                                                                                                    \
    typedef traits::function_traits::Function_Type Function_Type;                                \
    typedef traits::function_traits::FunctionP_Type FunctionP_Type;                        \
};




#endif
//signalcall2.hpp
#ifndef SIGNALCALL2_INCLUDE
#define SIGNALCALL2_INCLUDE

#include "signalcall_config2.hpp"
#include "signal_type2.hpp"
#include 
#include 
#include 

NAMESPACE_SIGNALCALL_BEGIN

struct call_list_container
{
    call_list_container():_func(0),_method(0){}
    callhelper::basic_call_container* _func;
    callhelper::basic_call_container* _method;
};

typedef std::map param_callcontainer_map;
typedef std::map sig_paramc_callcontainer_map;


class signalcall2
{
protected:
    sig_paramc_callcontainer_map _sig_paramc_callcontainer_map;

    void _call(SigID id,ParamC c,std::string& str)
    {
        sig_paramc_callcontainer_map::iterator iter = _sig_paramc_callcontainer_map.find(id);
        if (iter!=_sig_paramc_callcontainer_map.end())
        {
            param_callcontainer_map::iterator iter2 = iter->second.find(c);
            if (iter2!=iter->second.end())
            {
                if (iter2->second._func!=0)
                {
                    IArchive iarc(str);
                    iter2->second._func->call(iarc);
                }
                if (iter2->second._method!=0)
                {
                    IArchive iarc(str);
                    iter2->second._method->call(iarc);
                }
            }
        }

        return ;
    }

    signalcall2(const signalcall2&);

    signalcall2& operator =(const signalcall2&);

public:
    signalcall2(){}

    virtual ~signalcall2()
    {
        unbindAllSignal();
    }

    template
    void bindSignal(classtype* obj,funtype fun)
    {
        // 安全检查
        typedef signature_trait::arity>::FunctionP_Type _FunctionP_Type;
        typename traits::fun_to_mem_converter<_FunctionP_Type,classtype>::MFunctionP_Type security_check(fun);

        typedef callhelper::call_containerset >,funtype,classtype> Call_Container_Type;

        sig_paramc_callcontainer_map::iterator iter = _sig_paramc_callcontainer_map.find(sigID);
        if (iter==_sig_paramc_callcontainer_map.end())
        {
            param_callcontainer_map _map;
            _sig_paramc_callcontainer_map[sigID] = _map;
            iter = _sig_paramc_callcontainer_map.find(sigID);
        }

        const int count = traits::mfunction_traits::arity;
        param_callcontainer_map::iterator iter2 = iter->second.find(count);
        if (iter2==iter->second.end())
        {
            call_list_container c_list_ontainer;
            iter->second[count] = c_list_ontainer;
            iter2 = iter->second.find(count);
        }

        if (iter2->second._method==0)
        {
            iter2->second._method = new Call_Container_Type;
        }

        callhelper::call_helper c_helper(obj,fun);
        Call_Container_Type& c_container = dynamic_cast(*(iter2->second)._method);
        c_container._container.insert(c_helper);
    }

    template
    void bindSignal(funtype fun)
    {
        // 安全检查
        typename signature_trait::arity>::FunctionP_Type security_check(fun);

        typedef callhelper::call_containersetvoid> >,funtype,void> Call_Container_Type;

        sig_paramc_callcontainer_map::iterator iter = _sig_paramc_callcontainer_map.find(sigID);
        if (iter==_sig_paramc_callcontainer_map.end())
        {
            param_callcontainer_map _map;
            _sig_paramc_callcontainer_map[sigID] = _map;
            iter = _sig_paramc_callcontainer_map.find(sigID);
        }

        const int count = traits::function_traits::arity;
        param_callcontainer_map::iterator iter2 = iter->second.find(count);
        if (iter2==iter->second.end())
        {
            call_list_container c_list_ontainer;
            iter->second[count] = c_list_ontainer;
            iter2 = iter->second.find(count);
        }

        if (iter2->second._func==0)
        {
            iter2->second._func = new Call_Container_Type;
        }

        callhelper::call_helpervoid> c_helper(fun);
        Call_Container_Type& c_container = dynamic_cast(*(iter2->second)._func);
        c_container._container.insert(c_helper);
    }

    template
    void unbindSignal(classtype* obj,funtype fun)
    {
        // 安全检查
        typename signature_trait::arity>::FunctionP_Type security_check(fun);

        sig_paramc_callcontainer_map::iterator iter = _sig_paramc_callcontainer_map.find(sigID);
        if (iter!=_sig_paramc_callcontainer_map.end())
        {
            const int count = traits::mfunction_traits::arity;
            param_callcontainer_map::iterator iter2 = iter->second.find(count);
            if (iter2!=iter->second.end())
            {
                if (iter2->second._method!=0)
                {
                    typedef callhelper::call_containerset >,funtype,classtype> Call_Container_Type;
                    Call_Container_Type& c_container = (Call_Container_Type&)(*(iter2->second)._method);

                    callhelper::call_helper c_helper(obj,fun);
                    c_container._container.erase(c_helper);

                    if (c_container._container.size()==0)
                    {
                        delete (iter2->second._method);
                        iter2->second._method = 0;
                    }
                }

                if (!iter2->second._func && !iter2->second._method)
                {
                    iter->second.erase(iter2);
                }
            }

            if (iter->second.size()==0)
            {
                _sig_paramc_callcontainer_map.erase(iter);
            }
        }
    }

    template
    void unbindSignal(funtype fun)
    {
        // 安全检查
        typename signature_trait::arity>::FunctionP_Type security_check(fun);

        sig_paramc_callcontainer_map::iterator iter = _sig_paramc_callcontainer_map.find(sigID);
        if (iter!=_sig_paramc_callcontainer_map.end())
        {
            const int count = traits::function_traits::arity;
            param_callcontainer_map::iterator iter2 = iter->second.find(count);
            if (iter2!=iter->second.end())
            {
                if (iter2->second._func!=0)
                {
                    typedef callhelper::call_containersetvoid> >,funtype,void> Call_Container_Type;
                    Call_Container_Type& c_container = (Call_Container_Type&)(*(iter2->second)._func);

                    callhelper::call_helpervoid> c_helper(fun);
                    c_container._container.erase(c_helper);

                    if (c_container._container.size()==0)
                    {
                        delete (iter2->second._func);
                        iter2->second._func = 0;
                    }
                }

                if (!iter2->second._func && !iter2->second._method)
                {
                    iter->second.erase(iter2);
                }
            }

            if (iter->second.size()==0)
            {
                _sig_paramc_callcontainer_map.erase(iter);
            }
        }
    }

    void unbindAllSignal()
    {
        for (sig_paramc_callcontainer_map::iterator iter=_sig_paramc_callcontainer_map.begin();
            iter!=_sig_paramc_callcontainer_map.end(); ++iter)
        {
            for (param_callcontainer_map::iterator iter2=iter->second.begin();
                iter2!=iter->second.end(); ++iter2)
            {
                delete (iter2->second._func);
                delete (iter2->second._method);

                iter2->second._func = 0;
                iter2->second._method = 0;
            }
            iter->second.clear();
        }
        _sig_paramc_callcontainer_map.clear();
    }

    template
    void signal()
    {
        typedef typename signature_trait0>::Function_Type Function_Type;
        _call(sigID,0,std::string(""));
    }

    template
    void signal(
        typename traits::function_traits1>::Function_Type>::arg1 p1
        )
    {
        std::string str;
        OArchive oarc(str);
        callhelper::param_set1>::Function_Type>::arg1>(p1,oarc);

        _call(sigID,1,str);
    }

    template
    void signal(
        typename traits::function_traits2>::Function_Type>::arg2 p2,
        typename traits::function_traits2>::Function_Type>::arg1 p1
        )
    {
        std::string str;
        OArchive oarc(str);
        callhelper::param_set2>::Function_Type>::arg2>(p2,oarc);
        callhelper::param_set2>::Function_Type>::arg1>(p1,oarc);

        _call(sigID,2,str);
    }

    template
    void signal(
        typename traits::function_traits3>::Function_Type>::arg3 p3,
        typename traits::function_traits3>::Function_Type>::arg2 p2,
        typename traits::function_traits3>::Function_Type>::arg1 p1
        )
    {
        std::string str;
        OArchive oarc(str);
        callhelper::param_set3>::Function_Type>::arg3>(p3,oarc);
        callhelper::param_set3>::Function_Type>::arg2>(p2,oarc);
        callhelper::param_set3>::Function_Type>::arg1>(p1,oarc);

        _call(sigID,3,str);
    }

    template
    void signal(
        typename traits::function_traits4>::Function_Type>::arg4 p4,
        typename traits::function_traits4>::Function_Type>::arg3 p3,
        typename traits::function_traits4>::Function_Type>::arg2 p2,
        typename traits::function_traits4>::Function_Type>::arg1 p1
        )
    {
        std::string str;
        OArchive oarc(str);
        callhelper::param_set4>::Function_Type>::arg4>(p4,oarc);
        callhelper::param_set4>::Function_Type>::arg3>(p3,oarc);
        callhelper::param_set4>::Function_Type>::arg2>(p2,oarc);
        callhelper::param_set4>::Function_Type>::arg1>(p1,oarc);

        _call(sigID,4,str);
    }

    template
    void signal(
        typename traits::function_traits5>::Function_Type>::arg5 p5,
        typename traits::function_traits5>::Function_Type>::arg4 p4,
        typename traits::function_traits5>::Function_Type>::arg3 p3,
        typename traits::function_traits5>::Function_Type>::arg2 p2,
        typename traits::function_traits5>::Function_Type>::arg1 p1
        )
    {
        std::string str;
        OArchive oarc(str);
        callhelper::param_set5>::Function_Type>::arg5>(p5,oarc);
        callhelper::param_set5>::Function_Type>::arg4>(p4,oarc);
        callhelper::param_set5>::Function_Type>::arg3>(p3,oarc);
        callhelper::param_set5>::Function_Type>::arg2>(p2,oarc);
        callhelper::param_set5>::Function_Type>::arg1>(p1,oarc);

        _call(sigID,5,str);
    }

    template
    void signal(
        typename traits::function_traits6>::Function_Type>::arg6 p6,
        typename traits::function_traits6>::Function_Type>::arg5 p5,
        typename traits::function_traits6>::Function_Type>::arg4 p4,
        typename traits::function_traits6>::Function_Type>::arg3 p3,
        typename traits::function_traits6>::Function_Type>::arg2 p2,
        typename traits::function_traits6>::Function_Type>::arg1 p1
        )
    {
        std::string str;
        OArchive oarc(str);
        callhelper::param_set6>::Function_Type>::arg6>(p6,oarc);
        callhelper::param_set6>::Function_Type>::arg5>(p5,oarc);
        callhelper::param_set6>::Function_Type>::arg4>(p4,oarc);
        callhelper::param_set6>::Function_Type>::arg3>(p3,oarc);
        callhelper::param_set6>::Function_Type>::arg2>(p2,oarc);
        callhelper::param_set6>::Function_Type>::arg1>(p1,oarc);

        _call(sigID,6,str);
    }

    template
    void signal(
        typename traits::function_traits7>::Function_Type>::arg7 p7,
        typename traits::function_traits7>::Function_Type>::arg6 p6,
        typename traits::function_traits7>::Function_Type>::arg5 p5,
        typename traits::function_traits7>::Function_Type>::arg4 p4,
        typename traits::function_traits7>::Function_Type>::arg3 p3,
        typename traits::function_traits7>::Function_Type>::arg2 p2,
        typename traits::function_traits7>::Function_Type>::arg1 p1
        )
    {
        std::string str;
        OArchive oarc(str);
        callhelper::param_set7>::Function_Type>::arg7>(p7,oarc);
        callhelper::param_set7>::Function_Type>::arg6>(p6,oarc);
        callhelper::param_set7>::Function_Type>::arg5>(p5,oarc);
        callhelper::param_set7>::Function_Type>::arg4>(p4,oarc);
        callhelper::param_set7>::Function_Type>::arg3>(p3,oarc);
        callhelper::param_set7>::Function_Type>::arg2>(p2,oarc);
        callhelper::param_set7>::Function_Type>::arg1>(p1,oarc);

        _call(sigID,7,str);
    }

    template
    void signal(
        typename traits::function_traits8>::Function_Type>::arg8 p8,
        typename traits::function_traits8>::Function_Type>::arg7 p7,
        typename traits::function_traits8>::Function_Type>::arg6 p6,
        typename traits::function_traits8>::Function_Type>::arg5 p5,
        typename traits::function_traits8>::Function_Type>::arg4 p4,
        typename traits::function_traits8>::Function_Type>::arg3 p3,
        typename traits::function_traits8>::Function_Type>::arg2 p2,
        typename traits::function_traits8>::Function_Type>::arg1 p1
        )
    {
        std::string str;
        OArchive oarc(str);
        callhelper::param_set8>::Function_Type>::arg8>(p8,oarc);
        callhelper::param_set8>::Function_Type>::arg7>(p7,oarc);
        callhelper::param_set8>::Function_Type>::arg6>(p6,oarc);
        callhelper::param_set8>::Function_Type>::arg5>(p5,oarc);
        callhelper::param_set8>::Function_Type>::arg4>(p4,oarc);
        callhelper::param_set8>::Function_Type>::arg3>(p3,oarc);
        callhelper::param_set8>::Function_Type>::arg2>(p2,oarc);
        callhelper::param_set8>::Function_Type>::arg1>(p1,oarc);

        _call(sigID,8,str);
    }

    template
    void signal(
        typename traits::function_traits9>::Function_Type>::arg9 p9,
        typename traits::function_traits9>::Function_Type>::arg8 p8,
        typename traits::function_traits9>::Function_Type>::arg7 p7,
        typename traits::function_traits9>::Function_Type>::arg6 p6,
        typename traits::function_traits9>::Function_Type>::arg5 p5,
        typename traits::function_traits9>::Function_Type>::arg4 p4,
        typename traits::function_traits9>::Function_Type>::arg3 p3,
        typename traits::function_traits9>::Function_Type>::arg2 p2,
        typename traits::function_traits9>::Function_Type>::arg1 p1
        )
    {
        std::string str;
        OArchive oarc(str);
        callhelper::param_set9>::Function_Type>::arg9>(p9,oarc);
        callhelper::param_set9>::Function_Type>::arg8>(p8,oarc);
        callhelper::param_set9>::Function_Type>::arg7>(p7,oarc);
        callhelper::param_set9>::Function_Type>::arg6>(p6,oarc);
        callhelper::param_set9>::Function_Type>::arg5>(p5,oarc);
        callhelper::param_set9>::Function_Type>::arg4>(p4,oarc);
        callhelper::param_set9>::Function_Type>::arg3>(p3,oarc);
        callhelper::param_set9>::Function_Type>::arg2>(p2,oarc);
        callhelper::param_set9>::Function_Type>::arg1>(p1,oarc);

        _call(sigID,9,str);
    }

    template
    void signal(
        typename traits::function_traits10>::Function_Type>::arg10 p10,
        typename traits::function_traits10>::Function_Type>::arg9 p9,
        typename traits::function_traits10>::Function_Type>::arg8 p8,
        typename traits::function_traits10>::Function_Type>::arg7 p7,
        typename traits::function_traits10>::Function_Type>::arg6 p6,
        typename traits::function_traits10>::Function_Type>::arg5 p5,
        typename traits::function_traits10>::Function_Type>::arg4 p4,
        typename traits::function_traits10>::Function_Type>::arg3 p3,
        typename traits::function_traits10>::Function_Type>::arg2 p2,
        typename traits::function_traits10>::Function_Type>::arg1 p1
        )
    {
        std::string str;
        OArchive oarc(str);
        callhelper::param_set10>::Function_Type>::arg10>(p10,oarc);
        callhelper::param_set10>::Function_Type>::arg9>(p9,oarc);
        callhelper::param_set10>::Function_Type>::arg8>(p8,oarc);
        callhelper::param_set10>::Function_Type>::arg7>(p7,oarc);
        callhelper::param_set10>::Function_Type>::arg6>(p6,oarc);
        callhelper::param_set10>::Function_Type>::arg5>(p5,oarc);
        callhelper::param_set10>::Function_Type>::arg4>(p4,oarc);
        callhelper::param_set10>::Function_Type>::arg3>(p3,oarc);
        callhelper::param_set10>::Function_Type>::arg2>(p2,oarc);
        callhelper::param_set10>::Function_Type>::arg1>(p1,oarc);

        _call(sigID,10,str);
    }

    template
    void signal(
        typename traits::function_traits11>::Function_Type>::arg11 p11,
        typename traits::function_traits11>::Function_Type>::arg10 p10,
        typename traits::function_traits11>::Function_Type>::arg9 p9,
        typename traits::function_traits11>::Function_Type>::arg8 p8,
        typename traits::function_traits11>::Function_Type>::arg7 p7,
        typename traits::function_traits11>::Function_Type>::arg6 p6,
        typename traits::function_traits11>::Function_Type>::arg5 p5,
        typename traits::function_traits11>::Function_Type>::arg4 p4,
        typename traits::function_traits11>::Function_Type>::arg3 p3,
        typename traits::function_traits11>::Function_Type>::arg2 p2,
        typename traits::function_traits11>::Function_Type>::arg1 p1
        )
    {
        std::string str;
        OArchive oarc(str);
        callhelper::param_set11>::Function_Type>::arg11>(p11,oarc);
        callhelper::param_set11>::Function_Type>::arg10>(p10,oarc);
        callhelper::param_set11>::Function_Type>::arg9>(p9,oarc);
        callhelper::param_set11>::Function_Type>::arg8>(p8,oarc);
        callhelper::param_set11>::Function_Type>::arg7>(p7,oarc);
        callhelper::param_set11>::Function_Type>::arg6>(p6,oarc);
        callhelper::param_set11>::Function_Type>::arg5>(p5,oarc);
        callhelper::param_set11>::Function_Type>::arg4>(p4,oarc);
        callhelper::param_set11>::Function_Type>::arg3>(p3,oarc);
        callhelper::param_set11>::Function_Type>::arg2>(p2,oarc);
        callhelper::param_set11>::Function_Type>::arg1>(p1,oarc);

        _call(sigID,11,str);
    }

    template
    void signal(
        typename traits::function_traits12>::Function_Type>::arg12 p12,
        typename traits::function_traits12>::Function_Type>::arg11 p11,
        typename traits::function_traits12>::Function_Type>::arg10 p10,
        typename traits::function_traits12>::Function_Type>::arg9 p9,
        typename traits::function_traits12>::Function_Type>::arg8 p8,
        typename traits::function_traits12>::Function_Type>::arg7 p7,
        typename traits::function_traits12>::Function_Type>::arg6 p6,
        typename traits::function_traits12>::Function_Type>::arg5 p5,
        typename traits::function_traits12>::Function_Type>::arg4 p4,
        typename traits::function_traits12>::Function_Type>::arg3 p3,
        typename traits::function_traits12>::Function_Type>::arg2 p2,
        typename traits::function_traits12>::Function_Type>::arg1 p1
        )
    {
        std::string str;
        OArchive oarc(str);
        callhelper::param_set12>::Function_Type>::arg12>(p12,oarc);
        callhelper::param_set12>::Function_Type>::arg11>(p11,oarc);
        callhelper::param_set12>::Function_Type>::arg10>(p10,oarc);
        callhelper::param_set12>::Function_Type>::arg9>(p9,oarc);
        callhelper::param_set12>::Function_Type>::arg8>(p8,oarc);
        callhelper::param_set12>::Function_Type>::arg7>(p7,oarc);
        callhelper::param_set12>::Function_Type>::arg6>(p6,oarc);
        callhelper::param_set12>::Function_Type>::arg5>(p5,oarc);
        callhelper::param_set12>::Function_Type>::arg4>(p4,oarc);
        callhelper::param_set12>::Function_Type>::arg3>(p3,oarc);
        callhelper::param_set12>::Function_Type>::arg2>(p2,oarc);
        callhelper::param_set12>::Function_Type>::arg1>(p1,oarc);

        _call(sigID,12,str);
    }

    template
    void signal(
        typename traits::function_traits13>::Function_Type>::arg13 p13,
        typename traits::function_traits13>::Function_Type>::arg12 p12,
        typename traits::function_traits13>::Function_Type>::arg11 p11,
        typename traits::function_traits13>::Function_Type>::arg10 p10,
        typename traits::function_traits13>::Function_Type>::arg9 p9,
        typename traits::function_traits13>::Function_Type>::arg8 p8,
        typename traits::function_traits13>::Function_Type>::arg7 p7,
        typename traits::function_traits13>::Function_Type>::arg6 p6,
        typename traits::function_traits13>::Function_Type>::arg5 p5,
        typename traits::function_traits13>::Function_Type>::arg4 p4,
        typename traits::function_traits13>::Function_Type>::arg3 p3,
        typename traits::function_traits13>::Function_Type>::arg2 p2,
        typename traits::function_traits13>::Function_Type>::arg1 p1
        )
    {
        std::string str;
        OArchive oarc(str);
        callhelper::param_set13>::Function_Type>::arg13>(p13,oarc);
        callhelper::param_set13>::Function_Type>::arg12>(p12,oarc);
        callhelper::param_set13>::Function_Type>::arg11>(p11,oarc);
        callhelper::param_set13>::Function_Type>::arg10>(p10,oarc);
        callhelper::param_set13>::Function_Type>::arg9>(p9,oarc);
        callhelper::param_set13>::Function_Type>::arg8>(p8,oarc);
        callhelper::param_set13>::Function_Type>::arg7>(p7,oarc);
        callhelper::param_set13>::Function_Type>::arg6>(p6,oarc);
        callhelper::param_set13>::Function_Type>::arg5>(p5,oarc);
        callhelper::param_set13>::Function_Type>::arg4>(p4,oarc);
        callhelper::param_set13>::Function_Type>::arg3>(p3,oarc);
        callhelper::param_set13>::Function_Type>::arg2>(p2,oarc);
        callhelper::param_set13>::Function_Type>::arg1>(p1,oarc);

        _call(sigID,13,str);
    }

    template
    void signal(
        typename traits::function_traits14>::Function_Type>::arg14 p14,
        typename traits::function_traits14>::Function_Type>::arg13 p13,
        typename traits::function_traits14>::Function_Type>::arg12 p12,
        typename traits::function_traits14>::Function_Type>::arg11 p11,
        typename traits::function_traits14>::Function_Type>::arg10 p10,
        typename traits::function_traits14>::Function_Type>::arg9 p9,
        typename traits::function_traits14>::Function_Type>::arg8 p8,
        typename traits::function_traits14>::Function_Type>::arg7 p7,
        typename traits::function_traits14>::Function_Type>::arg6 p6,
        typename traits::function_traits14>::Function_Type>::arg5 p5,
        typename traits::function_traits14>::Function_Type>::arg4 p4,
        typename traits::function_traits14>::Function_Type>::arg3 p3,
        typename traits::function_traits14>::Function_Type>::arg2 p2,
        typename traits::function_traits14>::Function_Type>::arg1 p1
        )
    {
        std::string str;
        OArchive oarc(str);
        callhelper::param_set14>::Function_Type>::arg14>(p14,oarc);
        callhelper::param_set14>::Function_Type>::arg13>(p13,oarc);
        callhelper::param_set14>::Function_Type>::arg12>(p12,oarc);
        callhelper::param_set14>::Function_Type>::arg11>(p11,oarc);
        callhelper::param_set14>::Function_Type>::arg10>(p10,oarc);
        callhelper::param_set14>::Function_Type>::arg9>(p9,oarc);
        callhelper::param_set14>::Function_Type>::arg8>(p8,oarc);
        callhelper::param_set14>::Function_Type>::arg7>(p7,oarc);
        callhelper::param_set14>::Function_Type>::arg6>(p6,oarc);
        callhelper::param_set14>::Function_Type>::arg5>(p5,oarc);
        callhelper::param_set14>::Function_Type>::arg4>(p4,oarc);
        callhelper::param_set14>::Function_Type>::arg3>(p3,oarc);
        callhelper::param_set14>::Function_Type>::arg2>(p2,oarc);
        callhelper::param_set14>::Function_Type>::arg1>(p1,oarc);

        _call(sigID,14,str);
    }

    template
    void signal(
        typename traits::function_traits15>::Function_Type>::arg15 p15,
        typename traits::function_traits15>::Function_Type>::arg14 p14,
        typename traits::function_traits15>::Function_Type>::arg13 p13,
        typename traits::function_traits15>::Function_Type>::arg12 p12,
        typename traits::function_traits15>::Function_Type>::arg11 p11,
        typename traits::function_traits15>::Function_Type>::arg10 p10,
        typename traits::function_traits15>::Function_Type>::arg9 p9,
        typename traits::function_traits15>::Function_Type>::arg8 p8,
        typename traits::function_traits15>::Function_Type>::arg7 p7,
        typename traits::function_traits15>::Function_Type>::arg6 p6,
        typename traits::function_traits15>::Function_Type>::arg5 p5,
        typename traits::function_traits15>::Function_Type>::arg4 p4,
        typename traits::function_traits15>::Function_Type>::arg3 p3,
        typename traits::function_traits15>::Function_Type>::arg2 p2,
        typename traits::function_traits15>::Function_Type>::arg1 p1
        )
    {
        std::string str;
        OArchive oarc(str);
        callhelper::param_set15>::Function_Type>::arg15>(p15,oarc);
        callhelper::param_set15>::Function_Type>::arg14>(p14,oarc);
        callhelper::param_set15>::Function_Type>::arg13>(p13,oarc);
        callhelper::param_set15>::Function_Type>::arg12>(p12,oarc);
        callhelper::param_set15>::Function_Type>::arg11>(p11,oarc);
        callhelper::param_set15>::Function_Type>::arg10>(p10,oarc);
        callhelper::param_set15>::Function_Type>::arg9>(p9,oarc);
        callhelper::param_set15>::Function_Type>::arg8>(p8,oarc);
        callhelper::param_set15>::Function_Type>::arg7>(p7,oarc);
        callhelper::param_set15>::Function_Type>::arg6>(p6,oarc);
        callhelper::param_set15>::Function_Type>::arg5>(p5,oarc);
        callhelper::param_set15>::Function_Type>::arg4>(p4,oarc);
        callhelper::param_set15>::Function_Type>::arg3>(p3,oarc);
        callhelper::param_set15>::Function_Type>::arg2>(p2,oarc);
        callhelper::param_set15>::Function_Type>::arg1>(p1,oarc);

        _call(sigID,15,str);
    }

    template
    void signal(
        typename traits::function_traits16>::Function_Type>::arg16 p16,
        typename traits::function_traits16>::Function_Type>::arg15 p15,
        typename traits::function_traits16>::Function_Type>::arg14 p14,
        typename traits::function_traits16>::Function_Type>::arg13 p13,
        typename traits::function_traits16>::Function_Type>::arg12 p12,
        typename traits::function_traits16>::Function_Type>::arg11 p11,
        typename traits::function_traits16>::Function_Type>::arg10 p10,
        typename traits::function_traits16>::Function_Type>::arg9 p9,
        typename traits::function_traits16>::Function_Type>::arg8 p8,
        typename traits::function_traits16>::Function_Type>::arg7 p7,
        typename traits::function_traits16>::Function_Type>::arg6 p6,
        typename traits::function_traits16>::Function_Type>::arg5 p5,
        typename traits::function_traits16>::Function_Type>::arg4 p4,
        typename traits::function_traits16>::Function_Type>::arg3 p3,
        typename traits::function_traits16>::Function_Type>::arg2 p2,
        typename traits::function_traits16>::Function_Type>::arg1 p1
        )
    {
        std::string str;
        OArchive oarc(str);
        callhelper::param_set16>::Function_Type>::arg16>(p16,oarc);
        callhelper::param_set16>::Function_Type>::arg15>(p15,oarc);
        callhelper::param_set16>::Function_Type>::arg14>(p14,oarc);
        callhelper::param_set16>::Function_Type>::arg13>(p13,oarc);
        callhelper::param_set16>::Function_Type>::arg12>(p12,oarc);
        callhelper::param_set16>::Function_Type>::arg11>(p11,oarc);
        callhelper::param_set16>::Function_Type>::arg10>(p10,oarc);
        callhelper::param_set16>::Function_Type>::arg9>(p9,oarc);
        callhelper::param_set16>::Function_Type>::arg8>(p8,oarc);
        callhelper::param_set16>::Function_Type>::arg7>(p7,oarc);
        callhelper::param_set16>::Function_Type>::arg6>(p6,oarc);
        callhelper::param_set16>::Function_Type>::arg5>(p5,oarc);
        callhelper::param_set16>::Function_Type>::arg4>(p4,oarc);
        callhelper::param_set16>::Function_Type>::arg3>(p3,oarc);
        callhelper::param_set16>::Function_Type>::arg2>(p2,oarc);
        callhelper::param_set16>::Function_Type>::arg1>(p1,oarc);

        _call(sigID,16,str);
    }

    template
    void signal(
        typename traits::function_traits17>::Function_Type>::arg17 p17,
        typename traits::function_traits17>::Function_Type>::arg16 p16,
        typename traits::function_traits17>::Function_Type>::arg15 p15,
        typename traits::function_traits17>::Function_Type>::arg14 p14,
        typename traits::function_traits17>::Function_Type>::arg13 p13,
        typename traits::function_traits17>::Function_Type>::arg12 p12,
        typename traits::function_traits17>::Function_Type>::arg11 p11,
        typename traits::function_traits17>::Function_Type>::arg10 p10,
        typename traits::function_traits17>::Function_Type>::arg9 p9,
        typename traits::function_traits17>::Function_Type>::arg8 p8,
        typename traits::function_traits17>::Function_Type>::arg7 p7,
        typename traits::function_traits17>::Function_Type>::arg6 p6,
        typename traits::function_traits17>::Function_Type>::arg5 p5,
        typename traits::function_traits17>::Function_Type>::arg4 p4,
        typename traits::function_traits17>::Function_Type>::arg3 p3,
        typename traits::function_traits17>::Function_Type>::arg2 p2,
        typename traits::function_traits17>::Function_Type>::arg1 p1
        )
    {
        std::string str;
        OArchive oarc(str);
        callhelper::param_set17>::Function_Type>::arg17>(p17,oarc);
        callhelper::param_set17>::Function_Type>::arg16>(p16,oarc);
        callhelper::param_set17>::Function_Type>::arg15>(p15,oarc);
        callhelper::param_set17>::Function_Type>::arg14>(p14,oarc);
        callhelper::param_set17>::Function_Type>::arg13>(p13,oarc);
        callhelper::param_set17>::Function_Type>::arg12>(p12,oarc);
        callhelper::param_set17>::Function_Type>::arg11>(p11,oarc);
        callhelper::param_set17>::Function_Type>::arg10>(p10,oarc);
        callhelper::param_set17>::Function_Type>::arg9>(p9,oarc);
        callhelper::param_set17>::Function_Type>::arg8>(p8,oarc);
        callhelper::param_set17>::Function_Type>::arg7>(p7,oarc);
        callhelper::param_set17>::Function_Type>::arg6>(p6,oarc);
        callhelper::param_set17>::Function_Type>::arg5>(p5,oarc);
        callhelper::param_set17>::Function_Type>::arg4>(p4,oarc);
        callhelper::param_set17>::Function_Type>::arg3>(p3,oarc);
        callhelper::param_set17>::Function_Type>::arg2>(p2,oarc);
        callhelper::param_set17>::Function_Type>::arg1>(p1,oarc);

        _call(sigID,17,str);
    }

    template
    void signal(
        typename traits::function_traits18>::Function_Type>::arg18 p18,
        typename traits::function_traits18>::Function_Type>::arg17 p17,
        typename traits::function_traits18>::Function_Type>::arg16 p16,
        typename traits::function_traits18>::Function_Type>::arg15 p15,
        typename traits::function_traits18>::Function_Type>::arg14 p14,
        typename traits::function_traits18>::Function_Type>::arg13 p13,
        typename traits::function_traits18>::Function_Type>::arg12 p12,
        typename traits::function_traits18>::Function_Type>::arg11 p11,
        typename traits::function_traits18>::Function_Type>::arg10 p10,
        typename traits::function_traits18>::Function_Type>::arg9 p9,
        typename traits::function_traits18>::Function_Type>::arg8 p8,
        typename traits::function_traits18>::Function_Type>::arg7 p7,
        typename traits::function_traits18>::Function_Type>::arg6 p6,
        typename traits::function_traits18>::Function_Type>::arg5 p5,
        typename traits::function_traits18>::Function_Type>::arg4 p4,
        typename traits::function_traits18>::Function_Type>::arg3 p3,
        typename traits::function_traits18>::Function_Type>::arg2 p2,
        typename traits::function_traits18>::Function_Type>::arg1 p1
        )
    {
        std::string str;
        OArchive oarc(str);
        callhelper::param_set18>::Function_Type>::arg18>(p18,oarc);
        callhelper::param_set18>::Function_Type>::arg17>(p17,oarc);
        callhelper::param_set18>::Function_Type>::arg16>(p16,oarc);
        callhelper::param_set18>::Function_Type>::arg15>(p15,oarc);
        callhelper::param_set18>::Function_Type>::arg14>(p14,oarc);
        callhelper::param_set18>::Function_Type>::arg13>(p13,oarc);
        callhelper::param_set18>::Function_Type>::arg12>(p12,oarc);
        callhelper::param_set18>::Function_Type>::arg11>(p11,oarc);
        callhelper::param_set18>::Function_Type>::arg10>(p10,oarc);
        callhelper::param_set18>::Function_Type>::arg9>(p9,oarc);
        callhelper::param_set18>::Function_Type>::arg8>(p8,oarc);
        callhelper::param_set18>::Function_Type>::arg7>(p7,oarc);
        callhelper::param_set18>::Function_Type>::arg6>(p6,oarc);
        callhelper::param_set18>::Function_Type>::arg5>(p5,oarc);
        callhelper::param_set18>::Function_Type>::arg4>(p4,oarc);
        callhelper::param_set18>::Function_Type>::arg3>(p3,oarc);
        callhelper::param_set18>::Function_Type>::arg2>(p2,oarc);
        callhelper::param_set18>::Function_Type>::arg1>(p1,oarc);

        _call(sigID,18,str);
    }

    template
    void signal(
        typename traits::function_traits19>::Function_Type>::arg19 p19,
        typename traits::function_traits19>::Function_Type>::arg18 p18,
        typename traits::function_traits19>::Function_Type>::arg17 p17,
        typename traits::function_traits19>::Function_Type>::arg16 p16,
        typename traits::function_traits19>::Function_Type>::arg15 p15,
        typename traits::function_traits19>::Function_Type>::arg14 p14,
        typename traits::function_traits19>::Function_Type>::arg13 p13,
        typename traits::function_traits19>::Function_Type>::arg12 p12,
        typename traits::function_traits19>::Function_Type>::arg11 p11,
        typename traits::function_traits19>::Function_Type>::arg10 p10,
        typename traits::function_traits19>::Function_Type>::arg9 p9,
        typename traits::function_traits19>::Function_Type>::arg8 p8,
        typename traits::function_traits19>::Function_Type>::arg7 p7,
        typename traits::function_traits19>::Function_Type>::arg6 p6,
        typename traits::function_traits19>::Function_Type>::arg5 p5,
        typename traits::function_traits19>::Function_Type>::arg4 p4,
        typename traits::function_traits19>::Function_Type>::arg3 p3,
        typename traits::function_traits19>::Function_Type>::arg2 p2,
        typename traits::function_traits19>::Function_Type>::arg1 p1
        )
    {
        std::string str;
        OArchive oarc(str);
        callhelper::param_set19>::Function_Type>::arg19>(p19,oarc);
        callhelper::param_set19>::Function_Type>::arg18>(p18,oarc);
        callhelper::param_set19>::Function_Type>::arg17>(p17,oarc);
        callhelper::param_set19>::Function_Type>::arg16>(p16,oarc);
        callhelper::param_set19>::Function_Type>::arg15>(p15,oarc);
        callhelper::param_set19>::Function_Type>::arg14>(p14,oarc);
        callhelper::param_set19>::Function_Type>::arg13>(p13,oarc);
        callhelper::param_set19>::Function_Type>::arg12>(p12,oarc);
        callhelper::param_set19>::Function_Type>::arg11>(p11,oarc);
        callhelper::param_set19>::Function_Type>::arg10>(p10,oarc);
        callhelper::param_set19>::Function_Type>::arg9>(p9,oarc);
        callhelper::param_set19>::Function_Type>::arg8>(p8,oarc);
        callhelper::param_set19>::Function_Type>::arg7>(p7,oarc);
        callhelper::param_set19>::Function_Type>::arg6>(p6,oarc);
        callhelper::param_set19>::Function_Type>::arg5>(p5,oarc);
        callhelper::param_set19>::Function_Type>::arg4>(p4,oarc);
        callhelper::param_set19>::Function_Type>::arg3>(p3,oarc);
        callhelper::param_set19>::Function_Type>::arg2>(p2,oarc);
        callhelper::param_set19>::Function_Type>::arg1>(p1,oarc);

        _call(sigID,19,str);
    }

    template
    void signal(
        typename traits::function_traits20>::Function_Type>::arg20 p20,
        typename traits::function_traits20>::Function_Type>::arg19 p19,
        typename traits::function_traits20>::Function_Type>::arg18 p18,
        typename traits::function_traits20>::Function_Type>::arg17 p17,
        typename traits::function_traits20>::Function_Type>::arg16 p16,
        typename traits::function_traits20>::Function_Type>::arg15 p15,
        typename traits::function_traits20>::Function_Type>::arg14 p14,
        typename traits::function_traits20>::Function_Type>::arg13 p13,
        typename traits::function_traits20>::Function_Type>::arg12 p12,
        typename traits::function_traits20>::Function_Type>::arg11 p11,
        typename traits::function_traits20>::Function_Type>::arg10 p10,
        typename traits::function_traits20>::Function_Type>::arg9 p9,
        typename traits::function_traits20>::Function_Type>::arg8 p8,
        typename traits::function_traits20>::Function_Type>::arg7 p7,
        typename traits::function_traits20>::Function_Type>::arg6 p6,
        typename traits::function_traits20>::Function_Type>::arg5 p5,
        typename traits::function_traits20>::Function_Type>::arg4 p4,
        typename traits::function_traits20>::Function_Type>::arg3 p3,
        typename traits::function_traits20>::Function_Type>::arg2 p2,
        typename traits::function_traits20>::Function_Type>::arg1 p1
        )
    {
        std::string str;
        OArchive oarc(str);
        callhelper::param_set20>::Function_Type>::arg20>(p20,oarc);
        callhelper::param_set20>::Function_Type>::arg19>(p19,oarc);
        callhelper::param_set20>::Function_Type>::arg18>(p18,oarc);
        callhelper::param_set20>::Function_Type>::arg17>(p17,oarc);
        callhelper::param_set20>::Function_Type>::arg16>(p16,oarc);
        callhelper::param_set20>::Function_Type>::arg15>(p15,oarc);
        callhelper::param_set20>::Function_Type>::arg14>(p14,oarc);
        callhelper::param_set20>::Function_Type>::arg13>(p13,oarc);
        callhelper::param_set20>::Function_Type>::arg12>(p12,oarc);
        callhelper::param_set20>::Function_Type>::arg11>(p11,oarc);
        callhelper::param_set20>::Function_Type>::arg10>(p10,oarc);
        callhelper::param_set20>::Function_Type>::arg9>(p9,oarc);
        callhelper::param_set20>::Function_Type>::arg8>(p8,oarc);
        callhelper::param_set20>::Function_Type>::arg7>(p7,oarc);
        callhelper::param_set20>::Function_Type>::arg6>(p6,oarc);
        callhelper::param_set20>::Function_Type>::arg5>(p5,oarc);
        callhelper::param_set20>::Function_Type>::arg4>(p4,oarc);
        callhelper::param_set20>::Function_Type>::arg3>(p3,oarc);
        callhelper::param_set20>::Function_Type>::arg2>(p2,oarc);
        callhelper::param_set20>::Function_Type>::arg1>(p1,oarc);

        _call(sigID,20,str);
    }
};




NAMESPACE_SIGNALCALL_END
#endif

 

转载于:https://www.cnblogs.com/openlib/p/5346694.html

你可能感兴趣的:(谈一下信号分发器的作用及实现方法)