FunctionList.h 881 B

123456789101112131415161718192021222324252627282930313233343536
  1. #pragma once
  2. #include <boost/function.hpp>
  3. template<typename Signature, typename Allocator = std::allocator<void> >
  4. class CFunctionList
  5. {
  6. public:
  7. std::vector<boost::function<Signature,Allocator> > funcs;
  8. CFunctionList(int){};
  9. CFunctionList(){};
  10. CFunctionList(const boost::function<Signature,Allocator> &first)
  11. {
  12. funcs.push_back(first);
  13. }
  14. CFunctionList & operator+=(const boost::function<Signature,Allocator> &first)
  15. {
  16. funcs.push_back(first);
  17. return *this;
  18. }
  19. const boost::function<Signature,Allocator> & operator=(const boost::function<Signature,Allocator> &first)
  20. {
  21. funcs.push_back(first);
  22. return first;
  23. }
  24. operator bool() const
  25. {
  26. return funcs.size();
  27. }
  28. void operator()() const
  29. {
  30. std::vector<boost::function<Signature,Allocator> > funcs2 = funcs; //backup
  31. for(int i=0;i<funcs2.size(); i++)
  32. funcs2[i]();
  33. }
  34. };