2008-08-15 15:11:42 +03:00
|
|
|
#pragma once
|
|
|
|
#include <boost/function.hpp>
|
|
|
|
|
2008-08-20 09:57:53 +03:00
|
|
|
template<typename Signature>
|
2008-08-15 15:11:42 +03:00
|
|
|
class CFunctionList
|
|
|
|
{
|
|
|
|
public:
|
2008-08-20 09:57:53 +03:00
|
|
|
std::vector<boost::function<Signature> > funcs;
|
2008-08-15 15:11:42 +03:00
|
|
|
|
|
|
|
CFunctionList(int){};
|
|
|
|
CFunctionList(){};
|
2008-08-25 13:25:16 +03:00
|
|
|
template <typename Functor>
|
|
|
|
CFunctionList(const Functor &f)
|
|
|
|
{
|
|
|
|
funcs.push_back(boost::function<Signature>(f));
|
|
|
|
}
|
2008-08-20 09:57:53 +03:00
|
|
|
CFunctionList(const boost::function<Signature> &first)
|
2008-08-15 15:11:42 +03:00
|
|
|
{
|
|
|
|
funcs.push_back(first);
|
|
|
|
}
|
2008-08-22 15:21:09 +03:00
|
|
|
CFunctionList(boost::function<Signature> &first)
|
|
|
|
{
|
|
|
|
funcs.push_back(first);
|
|
|
|
}
|
2008-08-20 09:57:53 +03:00
|
|
|
CFunctionList & operator+=(const boost::function<Signature> &first)
|
2008-08-15 15:11:42 +03:00
|
|
|
{
|
|
|
|
funcs.push_back(first);
|
|
|
|
return *this;
|
|
|
|
}
|
2008-08-28 20:36:34 +03:00
|
|
|
void clear()
|
|
|
|
{
|
|
|
|
funcs.clear();
|
|
|
|
}
|
2008-08-15 15:11:42 +03:00
|
|
|
operator bool() const
|
|
|
|
{
|
|
|
|
return funcs.size();
|
|
|
|
}
|
|
|
|
void operator()() const
|
|
|
|
{
|
2008-08-20 09:57:53 +03:00
|
|
|
std::vector<boost::function<Signature> > funcs2 = funcs; //backup
|
2008-08-15 15:11:42 +03:00
|
|
|
for(int i=0;i<funcs2.size(); i++)
|
|
|
|
funcs2[i]();
|
|
|
|
}
|
2008-08-22 15:21:09 +03:00
|
|
|
template <typename Arg>
|
|
|
|
void operator()(const Arg & a) const
|
|
|
|
{
|
|
|
|
std::vector<boost::function<Signature> > funcs2 = funcs; //backup
|
|
|
|
for(int i=0;i<funcs2.size(); i++)
|
|
|
|
funcs2[i](a);
|
|
|
|
}
|
2008-09-24 11:15:49 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
template<typename Signature>
|
|
|
|
class CFunctionList2
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
std::vector<boost::function<Signature> > funcs;
|
|
|
|
|
|
|
|
CFunctionList2(int){};
|
|
|
|
CFunctionList2(){};
|
|
|
|
template <typename Functor>
|
|
|
|
CFunctionList2(const Functor &f)
|
|
|
|
{
|
|
|
|
funcs.push_back(boost::function<Signature>(f));
|
|
|
|
}
|
|
|
|
CFunctionList2(const boost::function<Signature> &first)
|
|
|
|
{
|
|
|
|
funcs.push_back(first);
|
|
|
|
}
|
|
|
|
CFunctionList2(boost::function<Signature> &first)
|
|
|
|
{
|
|
|
|
funcs.push_back(first);
|
|
|
|
}
|
|
|
|
CFunctionList2 & operator+=(const boost::function<Signature> &first)
|
|
|
|
{
|
|
|
|
funcs.push_back(first);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
void clear()
|
|
|
|
{
|
|
|
|
funcs.clear();
|
|
|
|
}
|
|
|
|
operator bool() const
|
|
|
|
{
|
|
|
|
return funcs.size();
|
|
|
|
}
|
|
|
|
template <typename Arg>
|
|
|
|
void operator()(const Arg & a) const
|
|
|
|
{
|
|
|
|
std::vector<boost::function<Signature> > funcs2 = funcs; //backup
|
|
|
|
for(int i=0;i<funcs2.size(); i++)
|
|
|
|
funcs2[i](a);
|
|
|
|
}
|
2008-08-15 15:11:42 +03:00
|
|
|
};
|