45 size_t rv = list.size();
46 for (
auto entry: list)
62 for (list_type::size_type i = 0; i < list.size(); i++)
64 if (list.at(i) == entry)
66 list.erase(list.begin() + i, list.begin() + i + 1);
85 for (
auto it = list.begin(); it != list.end();)
88 if (!entry->validListener())
110 void appendListener(base_type* entry)
115 list.insert(list.end(), entry);
118 typedef std::vector<base_type*> list_type;
124 template<
typename... Args>
133template<
typename... Args>
157 owner->appendListener(
this);
209 auto rv =
new TListener(listener_list, function);
210 list.insert(list.end(), rv->ptr);
224 for (
auto it = list.begin(); it != list.end();)
234 (*it->lock().get())(args...);
249 for (
auto it = list.begin(); it != list.end();)
279 std::vector<std::weak_ptr<func_type>> list;
288 bool validListener()
override
300 std::shared_ptr<func_type> ptr{};
Base class used as container for classes having listeners created by sf::TListener template.
Definition TListener.h:13
size_t cleanupListeners()
Removes all invalid/unused entries.
Definition TListener.h:81
size_t flushListeners()
Deletes all the linked entries in the list.
Definition TListener.h:43
size_t removeListener(base_type *entry)
Removes the given entry from the list.
Definition TListener.h:59
~ListenerList()
Destructor deleting all entries by calling flushListeners().
Definition TListener.h:33
Emitter class type for creating an instance which is emitting events to listeners.
Definition TListener.h:180
size_t cleanup()
Removes expired listeners.
Definition TListener.h:245
void callListeners(Args... args)
Call the registered listeners.
Definition TListener.h:221
TListener * linkListener(ListenerList *listener_list, const func_type &function)
Assigns a listener instance to this handler instance and also to the passed listener list.
Definition TListener.h:207
void flush()
Removes all listeners.
Definition TListener.h:270
~emitter_type()
Destructor clearing all shared pointers.
Definition TListener.h:189
Template class used to bind listeners to a handler_type instance.
Definition TListener.h:135
~TListener() override
Overridden destructor from ListenerList::base_type in order to delete entries of any instantiated tem...
Definition TListener.h:170
TListener< Args... > listener_type
Listener type of the lambda or function.
Definition TListener.h:146
TListener(ListenerList *list, const func_type &lambda)
Constructor.
Definition TListener.h:154
std::function< void(Args...)> func_type
Function type of the lambda or function.
Definition TListener.h:140
TListener(const TListener &)=delete
Do not allow copying.
Definition Application.h:10
void delete_null(T &p)
Deletes object and clears pointer.
Definition pointer.h:14
Type definition of a class having a virtual destructor used as a base class for sf::TListener.
Definition TListener.h:19
virtual ~base_type()=default
virtual bool validListener()=0
Will be overloaded in template to check the emitter has gone away.