26 #if ! defined (octave_action_container_h)
27 #define octave_action_container_h 1
29 #include "octave-config.h"
64 virtual void run (
void) { }
73 template <
typename F,
typename... Args>
75 : m_fcn (std::bind (fcn, args...))
78 void run (
void) { m_fcn (); }
82 std::function<void (
void)>
m_fcn;
93 : m_ptr (&ref), m_val (val) { }
101 void run (
void) { *m_ptr = m_val; }
110 template <
typename T>
124 void run (
void) {
delete m_ptr; }
141 template <
typename F,
typename... Args>
142 void add (F&& fcn, Args&&... args)
144 add_action (
new fcn_elem (std::forward<F> (fcn),
145 std::forward<Args> (args)...));
152 template <
typename... Params,
typename... Args>
153 void add_fcn (
void (*fcn) (Params...), Args&&... args)
155 add_action (
new fcn_elem (fcn, std::forward<Args> (args)...));
158 template <
typename T,
typename... Params,
typename... Args>
159 void add_method (T *obj,
void (T::*method) (Params...), Args&&... args)
161 add_action (
new fcn_elem (method, obj, std::forward<Args> (args)...));
164 template <
typename T,
typename... Params,
typename... Args>
165 void add_method (T& obj,
void (T::*method) (Params...), Args&&... args)
167 add_action (
new fcn_elem (method, &obj, std::forward<Args> (args)...));
172 template <
typename T>
179 template <
typename T>
186 template <
typename T>
192 operator bool (
void)
const {
return ! empty (); }
196 void run (
size_t num);
207 for (
size_t i = 0; i < num; i++)
213 virtual size_t size (
void)
const = 0;
215 bool empty (
void)
const {
return size () == 0; }
delete_ptr_elem(const delete_ptr_elem &)=delete
virtual ~elem(void)=default
elem(const elem &)=delete
fcn_elem(F &&fcn, Args &&... args)
std::function< void(void)> m_fcn
restore_var_elem(const restore_var_elem &)=delete
restore_var_elem(T &ref, const T &val)
void add_method(T &obj, void(T::*method)(Params...), Args &&... args)
virtual size_t size(void) const =0
action_container(const action_container &)=delete
virtual void run_first(void)=0
void add_method(T *obj, void(T::*method)(Params...), Args &&... args)
void add_fcn(void(*fcn)(Params...), Args &&... args)
void add(F &&fcn, Args &&... args)
virtual void add_action(elem *new_elem)=0
virtual ~action_container(void)=default
virtual void discard_first(void)=0
void protect_var(T &var, const T &val)