2008-12-21 21:17:35 +02:00
|
|
|
#ifndef FUNCTIONLIST_H
|
|
|
|
#define FUNCTIONLIST_H
|
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
2008-08-15 15:11:42 +03:00
|
|
|
#pragma once
|
2008-12-21 21:17:35 +02:00
|
|
|
#endif
|
|
|
|
|
2008-08-15 15:11:42 +03:00
|
|
|
#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;
|
|
|
|
}
|
2009-04-14 15:47:09 +03:00
|
|
|
void add(const CFunctionList<Signature> &first)
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < first.funcs.size(); i++)
|
|
|
|
{
|
|
|
|
funcs.push_back(first.funcs[i]);
|
|
|
|
}
|
|
|
|
}
|
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
|
2009-04-14 15:47:09 +03:00
|
|
|
for(size_t i=0;i<funcs2.size(); ++i)
|
|
|
|
{
|
2008-08-15 15:11:42 +03:00
|
|
|
funcs2[i]();
|
2009-04-14 15:47:09 +03:00
|
|
|
}
|
2008-08-15 15:11:42 +03:00
|
|
|
}
|
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
|
2009-04-14 15:47:09 +03:00
|
|
|
for(int i=0;i<funcs2.size(); i++)
|
|
|
|
{
|
2008-08-22 15:21:09 +03:00
|
|
|
funcs2[i](a);
|
2009-04-14 15:47:09 +03:00
|
|
|
}
|
2008-08-22 15:21:09 +03:00
|
|
|
}
|
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
|
2009-04-14 15:47:09 +03:00
|
|
|
for(size_t i=0;i<funcs2.size(); ++i)
|
|
|
|
{
|
2008-09-24 11:15:49 +03:00
|
|
|
funcs2[i](a);
|
2009-04-14 15:47:09 +03:00
|
|
|
}
|
2008-09-24 11:15:49 +03:00
|
|
|
}
|
2008-12-21 21:17:35 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif //FUNCTIONLISt_H
|