5 #ifndef __dispatchlist__ 6 #define __dispatchlist__ 19 void add (
const T& obj);
21 void remove (
const T& obj);
22 void remove (T&& obj);
25 template <
typename Procedure>
26 void forEach (Procedure proc);
28 template <
typename Procedure>
29 void forEachReverse (Procedure proc);
32 using Array = std::vector<T>;
39 bool inForEach {
false};
50 inline void DispatchList<T>::add (
const T& obj)
53 toAdd.emplace_back (obj);
55 entries.emplace_back (obj);
60 inline void DispatchList<T>::add (T&& obj)
63 toAdd.emplace_back (std::move (obj));
65 entries.emplace_back (std::move (obj));
70 inline void DispatchList<T>::remove (
const T& obj)
73 toRemove.emplace_back (obj);
76 auto it = std::find (entries.begin (), entries.end (), obj);
77 if (it != entries.end ())
84 inline void DispatchList<T>::remove (T&& obj)
87 toRemove.emplace_back (std::move (obj));
90 auto it = std::find (entries.begin (), entries.end (), obj);
91 if (it != entries.end ())
98 inline bool DispatchList<T>::empty ()
const 100 return entries.empty ();
104 template <
typename T>
105 inline void DispatchList<T>::postForEach ()
109 for (
auto&& it : toAdd)
110 add (std::move (it));
113 if (!toRemove.empty ())
115 for (
auto&& it : toRemove)
116 remove (std::move (it));
122 template <
typename T>
123 template <
typename Procedure>
124 inline void DispatchList<T>::forEach (Procedure proc)
126 if (entries.empty ())
129 bool wasInForEach = inForEach;
131 for (
auto& it : entries)
133 inForEach = wasInForEach;
139 template <
typename T>
140 template <
typename Procedure>
141 inline void DispatchList<T>::forEachReverse (Procedure proc)
143 if (entries.empty ())
146 bool wasInForEach = inForEach;
148 for (
auto it = entries.rbegin (); it != entries.rend (); ++it)
150 inForEach = wasInForEach;
158 #endif // __dispatchlist__ Definition: dispatchlist.h:14
Definition: customcontrols.cpp:8