Ion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
calllist.h
Go to the documentation of this file.
1 
18 #ifndef ION_BASE_CALLLIST_H_
19 #define ION_BASE_CALLLIST_H_
20 
21 #include <memory>
22 
23 #include "base/macros.h"
24 #include "ion/base/functioncall.h"
25 #include "ion/base/referent.h"
27 
28 namespace ion {
29 namespace base {
30 
53 class ION_API CallList : public Referent {
54  public:
55  CallList();
56 
61  template <typename ReturnType, class... Args>
62  void Add(ReturnType(*func)(Args...), Args&&... args) {
63  calls_.push_back(std::unique_ptr<FunctionCallBase>(
64  new (GetAllocator()) FunctionCall<ReturnType(Args...)>(
65  func, std::forward<Args>(args)...)));
66  }
67 
71  template <typename Func, class... Args>
72  void Add(Func&& func, Args&&... args) {
73  calls_.push_back(std::unique_ptr<FunctionCallBase>(
74  new (GetAllocator()) FunctionCall<typename Func::result_type(Args...)>(
75  std::forward<Func>(func), std::forward<Args>(args)...)));
76  }
77 
79  void Execute();
80 
82  void Clear();
83 
88  template <typename Func>
90  return i >= calls_.size()
91  ? NULL
92  : dynamic_cast<FunctionCall<Func>*>(calls_[i].get());
93  }
94 
95  private:
97  ~CallList() override;
98 
101 
102  DISALLOW_COPY_AND_ASSIGN(CallList);
103 };
104 
106 
107 } // namespace base
108 } // namespace ion
109 
110 #endif // ION_BASE_CALLLIST_H_
FunctionCall wraps an arbitrary call to a function, including its arguments.
Definition: functioncall.h:59
FunctionCall< Func > * GetCall(size_t i)
Returns the ith FunctionCall in this list.
Definition: calllist.h:89
void Add(ReturnType(*func)(Args...), Args &&...args)
Adds a function call to the list of calls to execute, overloaded for non-member (free) functions...
Definition: calllist.h:62
void Add(Func &&func, Args &&...args)
Adds a function call to the list of calls to execute, overloaded for std::functions.
Definition: calllist.h:72
ReferentPtr< CallList >::Type CallListPtr
Definition: calllist.h:105
Thread-safe abstract base class.
Definition: referent.h:49
CallList contains a list of function calls to execute.
Definition: calllist.h:53
A SharedPtr is a smart shared pointer to an instance of some class that implements reference counting...
Definition: sharedptr.h:60
This class can be used in place of std::vector to allow an Ion Allocator to be used for memory alloca...
Definition: allocvector.h:50