FunctionList.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #pragma once
  2. #include <boost/function.hpp>
  3. template<typename Signature>
  4. class CFunctionList
  5. {
  6. public:
  7. std::vector<boost::function<Signature> > funcs;
  8. CFunctionList(int){};
  9. CFunctionList(){};
  10. template <typename Functor>
  11. CFunctionList(const Functor &f)
  12. {
  13. funcs.push_back(boost::function<Signature>(f));
  14. }
  15. CFunctionList(const boost::function<Signature> &first)
  16. {
  17. funcs.push_back(first);
  18. }
  19. CFunctionList(boost::function<Signature> &first)
  20. {
  21. funcs.push_back(first);
  22. }
  23. CFunctionList & operator+=(const boost::function<Signature> &first)
  24. {
  25. funcs.push_back(first);
  26. return *this;
  27. }
  28. //CFunctionList<Signature> & operator=(const boost::function<Signature> &first)
  29. //{
  30. // funcs.push_back(first);
  31. // return first;
  32. //}
  33. void clear()
  34. {
  35. funcs.clear();
  36. }
  37. operator bool() const
  38. {
  39. return funcs.size();
  40. }
  41. void operator()() const
  42. {
  43. std::vector<boost::function<Signature> > funcs2 = funcs; //backup
  44. for(int i=0;i<funcs2.size(); i++)
  45. funcs2[i]();
  46. }
  47. template <typename Arg>
  48. void operator()(const Arg & a) const
  49. {
  50. std::vector<boost::function<Signature> > funcs2 = funcs; //backup
  51. for(int i=0;i<funcs2.size(); i++)
  52. funcs2[i](a);
  53. }
  54. };