reference

This documentation is automatically generated from the openFrameworks source code using doxygen and refers to the most recent release, version 0.12.0.

ofEvent.h
Go to the documentation of this file.
1#pragma once
2
3#include <vector>
4#include <functional>
5#include <mutex>
6#include <thread>
7#include <memory>
8#include <iterator>
9#include <atomic>
10#include <stddef.h>
11#include <functional>
12#include <deque>
13
14#include <cstddef>
15#include <iostream>
16#include <array>
17
18// FIXME: constants deprecated only
19#include "ofConstants.h"
20
21
23namespace of{
24namespace priv{
25 // Helper classes and methods, only for internal use of ofEvent
26
27 // -------------------------------------
28 class NoopMutex{
29 public:
30 void lock(){}
31 void unlock(){}
32 };
33
34 // -------------------------------------
35 class AbstractEventToken{
36 public:
37 virtual ~AbstractEventToken();
38 };
39
40
41 // -------------------------------------
42 class BaseFunctionId{
43 public:
44 BaseFunctionId(){}
45 BaseFunctionId(const BaseFunctionId &) = delete;
46 BaseFunctionId & operator=(const BaseFunctionId &) = delete;
47 virtual ~BaseFunctionId();
48 virtual bool operator==(const BaseFunctionId &) const = 0;
49 virtual BaseFunctionId * clone() const = 0;
50 };
51
52 // -------------------------------------
53 class StdFunctionId: public BaseFunctionId{
54 static std::atomic<uint_fast64_t> nextId;
55 uint64_t id;
56
57 StdFunctionId(uint64_t id)
58 :id(id){}
59 public:
60 StdFunctionId()
61 :id(nextId++){}
62
63 virtual ~StdFunctionId();
64
65 bool operator==(const BaseFunctionId & otherid) const{
66 const auto * other = dynamic_cast<const StdFunctionId*>(&otherid);
67 return other && id == other->id;
68 }
69
70 BaseFunctionId * clone() const{
71 return new StdFunctionId(id);
72 }
73 };
74
75
76 // -------------------------------------
77 inline std::unique_ptr<StdFunctionId> make_function_id(){
78 return std::make_unique<StdFunctionId>();
79 }
80
81 // -------------------------------------
82 template<typename T, class Mutex>
83 class Function{
84 public:
85 Function(int priority, std::function<bool(const void*,T&)> function, std::unique_ptr<BaseFunctionId>&& id )
86 :priority(priority)
87 ,id(std::move(id))
88 ,function(function){}
89
90 bool operator==(const Function<T,Mutex> & f) const{
91 return f.priority == priority && *id == *f.id;
92 }
93
94 inline bool notify(const void*s,T&t){
95 std::unique_lock<Mutex> lck(mtx);
96 try{
97 return function(s,t);
98 }catch(std::bad_function_call &){
99 return false;
100 }
101 }
102
103 inline void disable(){
104 std::unique_lock<Mutex> lck(mtx);
105 function = nullptr;
106 }
107
108 int priority;
109 std::unique_ptr<BaseFunctionId> id;
110
111 private:
112 std::function<bool(const void*,T&)> function;
113 Mutex mtx;
114 };
115
116 // -------------------------------------
117 template<class Mutex>
118 class Function<void,Mutex>{
119 public:
120 Function(int priority, std::function<bool(const void*)> function, std::unique_ptr<BaseFunctionId> && id )
121 :priority(priority)
122 ,id(std::move(id))
123 ,function(function){}
124
125 bool operator==(const Function<void,Mutex> & f) const{
126 return f.priority == priority && *id == *f.id;
127 }
128
129 inline bool notify(const void*s){
130 std::unique_lock<Mutex> lck(mtx);
131 try{
132 return function(s);
133 }catch(std::bad_function_call &){
134 return false;
135 }
136 }
137
138 inline void disable(){
139 std::unique_lock<Mutex> lck(mtx);
140 function = nullptr;
141 }
142
143 int priority;
144 std::unique_ptr<BaseFunctionId> id;
145 private:
146 std::function<bool(const void*)> function;
147 Mutex mtx;
148 };
149
150
151 // -------------------------------------
152 template<typename Function, typename Mutex=std::recursive_mutex>
153 class BaseEvent{
154 public:
155 BaseEvent(){}
156
157 BaseEvent(const BaseEvent & mom){
158 std::unique_lock<Mutex> lck(const_cast<BaseEvent&>(mom).self->mtx);
159 self->functions = mom.self->functions;
160 }
161
162 BaseEvent & operator=(const BaseEvent & mom){
163 if(&mom==this){
164 return *this;
165 }
166 std::unique_lock<Mutex> lck(const_cast<BaseEvent&>(mom).self->mtx);
167 std::unique_lock<Mutex> lck2(self->mtx);
168 self->functions = mom.self->functions;
169 self->enabled = mom.self->enabled;
170 return *this;
171 }
172
173 BaseEvent(BaseEvent && mom){
174 std::unique_lock<Mutex> lck(const_cast<BaseEvent&>(mom).self->mtx);
175 self->functions = std::move(mom.self->functions);
176 self->enabled = std::move(mom.self->enabled);
177 }
178
179 BaseEvent & operator=(BaseEvent && mom){
180 if(&mom==this){
181 return *this;
182 }
183 std::unique_lock<Mutex> lck(const_cast<BaseEvent&>(mom).self->mtx);
184 std::unique_lock<Mutex> lck2(self->mtx);
185 self->functions = mom.self->functions;
186 self->enabled = mom.self->enabled;
187 return *this;
188 }
189
190 void enable() {
191 self->enabled = true;
192 }
193
194 void disable() {
195 self->enabled = false;
196 }
197
198 bool isEnabled() const {
199 return self->enabled;
200 }
201
202 std::size_t size() const {
203 return self->functions.size();
204 }
205
206 protected:
207
208 struct Data{
209 Mutex mtx;
210 std::vector<std::shared_ptr<Function>> functions;
211 bool enabled = true;
212
213 void remove(const BaseFunctionId & id){
214 std::unique_lock<Mutex> lck(mtx);
215 auto it = functions.begin();
216 for(; it!=functions.end(); ++it){
217 auto f = *it;
218 if(*f->id == id){
219 f->disable();
220 functions.erase(it);
221 break;
222 }
223 }
224 }
225 };
226 std::shared_ptr<Data> self{new Data};
227
228 class EventToken: public AbstractEventToken{
229 public:
230 EventToken() {};
231 template<typename Id>
232 EventToken(std::shared_ptr<Data> & event, const Id & id)
233 :event(event)
234 ,id(id.clone()){
235
236 }
237
238 ~EventToken(){
239 auto event = this->event.lock();
240 if(event){
241 event->remove(*id);
242 }
243 }
244
245 private:
246 std::weak_ptr<Data> event;
247 std::unique_ptr<BaseFunctionId> id;
248 };
249
250 std::unique_ptr<EventToken> make_token(const Function & f){
251 return std::make_unique<EventToken>(self,*f.id);
252 }
253
254 template<typename TFunction>
255 void addNoToken(TFunction && f){
256 std::unique_lock<Mutex> lck(self->mtx);
257 auto it = self->functions.begin();
258 for(; it!=self->functions.end(); ++it){
259 if((*it)->priority>f->priority) break;
260 }
261 self->functions.emplace(it, f);
262 }
263
264 template<typename TFunction>
265 std::unique_ptr<EventToken> addFunction(TFunction && f){
266 std::unique_lock<Mutex> lck(self->mtx);
267 auto it = self->functions.begin();
268 for(; it!=self->functions.end(); ++it){
269 if((*it)->priority>f->priority) break;
270 }
271 self->functions.emplace(it, f);
272 return make_token(*f);
273 }
274 };
275
276
277
278
279 // -------------------------------------
280 // Helper functions to disambiguate parameters
281 // https://github.com/sth/callable.hpp
282 namespace detail {
283
285 template<typename... Types>
286 struct tva_count;
287
288 template<>
289 struct tva_count<> {
290 static const size_t value = 0;
291 };
292
293 template<typename Type, typename... Types>
294 struct tva_count<Type, Types...> {
295 static const size_t value = tva_count<Types...>::value + 1;
296 };
297
298
300 template<size_t n, typename... Types>
301 struct tva_n;
302
303 template<size_t N, typename Type, typename... Types>
304 struct tva_n<N, Type, Types...> : tva_n<N-1, Types...> {
305 };
306
307 template<typename Type, typename... Types>
308 struct tva_n<0, Type, Types...> {
309 typedef Type type;
310 };
311
312
314 template<typename Fun>
315 struct callable_traits_fn;
316
317 template<typename Ret, typename... Args>
318 struct callable_traits_fn<Ret (Args...)> {
319 typedef Ret (*function_ptr)(Args...);
320 typedef Ret function_type(Args...);
321 typedef Ret return_type;
322 static const size_t argc;
323
324 template<size_t N>
325 using argument_type = typename tva_n<N, Args...>::type;
326 };
327
328 template<typename Ret, typename... Args>
329 const size_t callable_traits_fn<Ret (Args...)>::argc = tva_count<Args...>::value;
330
331
333 template<typename MemFun>
334 struct callable_traits_memfn;
335
336 template<typename Class, typename Ret, typename... Args>
337 struct callable_traits_memfn<Ret (Class::*)(Args...)> : callable_traits_fn<Ret (Args...)> {
338 };
339
340 template<typename Class, typename Ret, typename... Args>
341 struct callable_traits_memfn<Ret (Class::*)(Args...) const> : callable_traits_fn<Ret (Args...)> {
342 };
343
344
345 // classes with operator()
346 template<typename Callable>
347 struct callable_traits_d : detail::callable_traits_memfn<decltype(&Callable::operator())> {
348 };
349
350 // functions
351 template<typename Ret, typename... Args>
352 struct callable_traits_d<Ret (Args...)> : detail::callable_traits_fn<Ret (Args...)> {
353 };
354
355 // function pointers
356 template<typename Ret, typename... Args>
357 struct callable_traits_d<Ret (*)(Args...)> : detail::callable_traits_fn<Ret (Args...)> {
358 };
359
360 // std::function specializations
361 template<typename Ret, typename... Args>
362 struct callable_traits_d<std::function<Ret (Args...)>> : detail::callable_traits_fn<Ret (Args...)> {
363 };
364
365 } // namespace detail
366
367
368 // Main template
369
370 template<typename Callable>
371 struct callable_traits : detail::callable_traits_d<typename std::remove_reference<Callable>::type> {
372 };
373}
374}
377// -------------------------------------
383
384// -------------------------------------
386public:
392
393 ofEventListener(std::unique_ptr<of::priv::AbstractEventToken> && token)
394 :token(std::move(token)){}
395
396 ofEventListener & operator=(std::unique_ptr<of::priv::AbstractEventToken> && token){
397 std::swap(this->token, token);
398 return *this;
399 }
400
402 token.reset();
403 }
404private:
405 std::unique_ptr<of::priv::AbstractEventToken> token;
406};
407
408
409
410// -------------------------------------
412public:
418
419
420 void push(std::unique_ptr<of::priv::AbstractEventToken> && listener){
421 listeners.emplace_back(std::move(listener));
422 }
423
424 OF_DEPRECATED_MSG("Don't use this method. If you need granular control over each listener, then use individual ofEventListener instances for each.", void unsubscribe(std::size_t pos));
425
427 listeners.clear();
428 }
429
430 bool empty() const {
431 return listeners.size() == 0 ;
432 }
433private:
434 std::deque<ofEventListener> listeners;
435};
436
437inline void ofEventListeners::unsubscribe(std::size_t pos){
438 listeners[pos].unsubscribe();
439}
440
441// -------------------------------------
442// ofEvent main implementation
443template<typename T, typename Mutex=std::recursive_mutex>
444class ofEvent: public of::priv::BaseEvent<of::priv::Function<T,Mutex>,Mutex>{
445protected:
446 typedef of::priv::Function<T,Mutex> Function;
447 typedef std::shared_ptr<Function> FunctionPtr;
448
449 template<class TObj, typename TMethod>
450 class FunctionId: public of::priv::BaseFunctionId{
451 public:
452 TObj * listener;
453 TMethod method;
454
455 FunctionId(TObj * listener, TMethod method)
457 ,method(method){
458
459 }
460
461 BaseFunctionId * clone() const{
463 }
464
465 template<typename F>
466 bool operator==(const F & f1) const{
467 return f1.listener == this->listener && f1.method == this->method;
468 }
469
470 bool operator==(const BaseFunctionId & f) const{
471 const auto * other = dynamic_cast<const FunctionId<TObj,TMethod>*>(&f);
472 return other && other->listener == this->listener && other->method == this->method;
473 }
474 };
475
476 template<class TObj, typename TMethod>
477 std::unique_ptr<FunctionId<TObj,TMethod>> make_function_id(TObj * listener, TMethod method){
478 return std::make_unique<FunctionId<TObj,TMethod>>(listener,method);
479 }
480
481 template<class TObj>
482 FunctionPtr make_function(TObj * listener, bool (TObj::*method)(T&), int priority){
483 return std::make_shared<Function>(priority, std::bind(method,listener,std::placeholders::_2), make_function_id(listener,method));
484 }
485
486 template<class TObj>
487 FunctionPtr make_function(TObj * listener, void (TObj::*method)(T&), int priority){
488 return std::make_shared<Function>(priority, [listener, method](const void*, T&t){
489 ((listener)->*(method))(t);
490 return false;
491 }, make_function_id(listener,method));
492 }
493
494 template<class TObj>
495 FunctionPtr make_function(TObj * listener, bool (TObj::*method)(const void*, T&), int priority){
496 return std::make_shared<Function>(priority, std::bind(method,listener,std::placeholders::_1,std::placeholders::_2), make_function_id(listener,method));
497 }
498
499 template<class TObj>
500 FunctionPtr make_function(TObj * listener, void (TObj::*method)(const void*, T&), int priority){
501 return std::make_shared<Function>(priority, [listener, method](const void*s, T&t){
502 std::bind(method,listener,std::placeholders::_1,std::placeholders::_2)(s,t);
503 return false;
504 }, make_function_id(listener,method));
505 }
506
507 template<typename F>
508 std::unique_ptr<of::priv::BaseFunctionId> make_std_function_id(const F & f){
509 auto function = f.template target<typename of::priv::callable_traits<F>::function_ptr>();
510 if(function){
511 return make_function_id((ofEvent<T>*)nullptr,*function);
512 }else{
513 return of::priv::make_function_id();
514 }
515 }
516
517 FunctionPtr make_function(std::function<bool(T&)> f, int priority) {
518 return std::make_shared<Function>(priority, [f](const void*, T&t) {return f(t); }, make_std_function_id(f));
519 }
520
521 FunctionPtr make_function(std::function<bool(const void*, T&)> f, int priority) {
522 return std::make_shared<Function>(priority, f, make_std_function_id(f));
523 }
524
525 FunctionPtr make_function(std::function<void(T&)> f, int priority) {
526 return std::make_shared<Function>(priority, [f](const void*, T&t) {f(t); return false; }, make_std_function_id(f));
527 }
528
529 FunctionPtr make_function(std::function<void(const void*, T&)> f, int priority) {
530 return std::make_shared<Function>(priority, [f](const void*s, T&t) {f(s, t); return false; }, make_std_function_id(f));
531 }
532
533
534 using of::priv::BaseEvent<of::priv::Function<T,Mutex>,Mutex>::addFunction;
535 using of::priv::BaseEvent<of::priv::Function<T,Mutex>,Mutex>::addNoToken;
536
537public:
538 template<class TObj, typename TMethod>
539 std::unique_ptr<of::priv::AbstractEventToken> newListener(TObj * listener, TMethod method, int priority = OF_EVENT_ORDER_AFTER_APP){
540 return addFunction(make_function(listener,method,priority));
541 }
542
543 template<class TObj, typename TMethod>
544 void add(TObj * listener, TMethod method, int priority){
545 addNoToken(make_function(listener,method,priority));
546 }
547
548 template<class TObj, typename TMethod>
549 void remove(TObj * listener, TMethod method, int priority){
551 }
552
553 template<typename TFunction>
554 std::unique_ptr<of::priv::AbstractEventToken> newListener(TFunction function, int priority = OF_EVENT_ORDER_AFTER_APP) {
555 return addFunction(make_function(std::function<typename of::priv::callable_traits<TFunction>::function_type>(function), priority));
556 }
557
558 template<typename TFunction>
559 void add(TFunction function, int priority){
560 addNoToken(make_function(std::function<typename of::priv::callable_traits<TFunction>::function_type>(function),priority));
561 }
562
563 template<typename TFunction>
564 void remove(TFunction function, int priority){
565 ofEvent<T,Mutex>::self->remove(*make_function(std::function<typename of::priv::callable_traits<TFunction>::function_type>(function), priority)->id);
566 }
567
568 inline bool notify(const void* sender, T & param){
569 if(ofEvent<T,Mutex>::self->enabled && !ofEvent<T,Mutex>::self->functions.empty()){
570 std::unique_lock<Mutex> lck(ofEvent<T,Mutex>::self->mtx);
571 auto functions_copy = ofEvent<T,Mutex>::self->functions;
572 lck.unlock();
573 for(auto & f: functions_copy){
574 if(f->notify(sender,param)){
575 return true;
576 }
577 }
578 }
579 return false;
580 }
581
582 inline bool notify(T & param){
583 if(ofEvent<T,Mutex>::self->enabled && !ofEvent<T,Mutex>::self->functions.empty()){
584 std::unique_lock<Mutex> lck(ofEvent<T,Mutex>::self->mtx);
585 auto functions_copy = ofEvent<T,Mutex>::self->functions;
586 lck.unlock();
587 for(auto & f: functions_copy){
588 if(f->notify(nullptr,param)){
589 return true;
590 }
591 }
592 }
593 return false;
594 }
595};
596
597
598
599// -------------------------------------
600// void event template specialization,
601template<typename Mutex>
602class ofEvent<void,Mutex>: public of::priv::BaseEvent<of::priv::Function<void,Mutex>,Mutex>{
603protected:
604 typedef of::priv::Function<void,Mutex> Function;
605 typedef std::shared_ptr<Function> FunctionPtr;
606
607 template<class TObj, typename TMethod>
608 class FunctionId: public of::priv::BaseFunctionId{
609 public:
610 TObj * listener;
611 TMethod method;
612
613 FunctionId(TObj * listener, TMethod method)
615 ,method(method){
616
617 }
618
619 BaseFunctionId * clone() const{
620 return new FunctionId<TObj,TMethod>(listener, method);
621 }
622
623 template<typename F>
624 bool operator==(const F & f1) const{
625 return f1.listener == this->listener && f1.method == this->method;
626 }
627
628 bool operator==(const BaseFunctionId & f) const{
629 const auto * other = dynamic_cast<const FunctionId<TObj,TMethod>*>(&f);
630 return other && other->listener == this->listener && other->method == this->method;
631 }
632 };
633
634
635 template<class TObj, typename TMethod>
636 std::unique_ptr<FunctionId<TObj,TMethod>> make_function_id(TObj * listener, TMethod method){
637 return std::unique_ptr<FunctionId<TObj,TMethod>>(new FunctionId<TObj,TMethod>(listener,method));
638 }
639
640 template<class TObj>
641 FunctionPtr make_function(TObj * listener, bool (TObj::*method)(), int priority){
642 return std::make_shared<Function>(priority, std::bind(method,listener), make_function_id(listener,method));
643 }
644
645 template<class TObj>
646 FunctionPtr make_function(TObj * listener, void (TObj::*method)(), int priority){
647 return std::make_shared<Function>(priority,[listener, method](const void*){
648 std::bind(method,listener)();
649 return false;
650 }, make_function_id(listener,method));
651 }
652
653 template<class TObj>
654 FunctionPtr make_function(TObj * listener, bool (TObj::*method)(const void*), int priority){
655 return std::make_shared<Function>(priority,std::bind(method,listener,std::placeholders::_1), make_function_id(listener,method));
656 }
657
658 template<class TObj>
659 FunctionPtr make_function(TObj * listener, void (TObj::*method)(const void*), int priority){
660 return std::make_shared<Function>(priority,[listener, method](const void* sender){
661 std::bind(method,listener,std::placeholders::_1)(sender);
662 return false;
663 }, make_function_id(listener,method));
664 }
665
666 template<typename F>
667 std::unique_ptr<of::priv::BaseFunctionId> make_std_function_id(const F & f){
668 auto function = f.template target<typename of::priv::callable_traits<F>::function_ptr>();
669 if(function){
670 return make_function_id((ofEvent<void>*)nullptr,*function);
671 }else{
672 return of::priv::make_function_id();
673 }
674 }
675
676 FunctionPtr make_function(std::function<bool()> f, int priority) {
677 return std::make_shared<Function>(priority, [f](const void*) {return f(); }, make_std_function_id(f));
678 }
679
680 FunctionPtr make_function(std::function<bool(const void*)> f, int priority) {
681 return std::make_shared<Function>(priority, f, make_std_function_id(f));
682 }
683
684 FunctionPtr make_function(std::function<void()> f, int priority) {
685 return std::make_shared<Function>(priority, [f](const void*) {f(); return false; }, make_std_function_id(f));
686 }
687
688 FunctionPtr make_function(std::function<void(const void*)> f, int priority) {
689 return std::make_shared<Function>(priority, [f](const void*s) {f(s); return false; }, make_std_function_id(f));
690 }
691
692 using of::priv::BaseEvent<of::priv::Function<void,Mutex>,Mutex>::addFunction;
693 using of::priv::BaseEvent<of::priv::Function<void,Mutex>,Mutex>::addNoToken;
694
695public:
696 template<class TObj, typename TMethod>
697 void add(TObj * listener, TMethod method, int priority){
698 addNoToken(make_function(listener,method,priority));
699 }
700
701 template<class TObj, typename TMethod>
702 std::unique_ptr<of::priv::AbstractEventToken> newListener(TObj * listener, TMethod method, int priority = OF_EVENT_ORDER_AFTER_APP){
703 return addFunction(make_function(listener,method,priority));
704 }
705
706 template<class TObj, typename TMethod>
707 void remove(TObj * listener, TMethod method, int priority){
709 }
710
711 template<typename TFunction>
712 void add(TFunction function, int priority){
713 addNoToken(make_function(std::function<typename of::priv::callable_traits<TFunction>::function_type>(function),priority));
714 }
715
716 template<typename TFunction>
717 std::unique_ptr<of::priv::AbstractEventToken> newListener(TFunction function, int priority = OF_EVENT_ORDER_AFTER_APP) {
718 return addFunction(make_function(std::function<typename of::priv::callable_traits<TFunction>::function_type>(function), priority));
719 }
720
721 template<typename TFunction>
722 void remove(TFunction function, int priority){
723 ofEvent<void,Mutex>::self->remove(*make_function(std::function<typename of::priv::callable_traits<TFunction>::function_type>(function),priority)->id);
724 }
725
726 bool notify(const void* sender){
727 if(ofEvent<void,Mutex>::self->enabled && !ofEvent<void,Mutex>::self->functions.empty()){
728 std::unique_lock<Mutex> lck(ofEvent<void,Mutex>::self->mtx);
729 auto functions_copy = ofEvent<void,Mutex>::self->functions;
730 lck.unlock();
731 for(auto & f: functions_copy){
732 if(f->notify(sender)){
733 return true;
734 }
735 }
736 }
737 return false;
738 }
739
740 bool notify(){
741 if(ofEvent<void,Mutex>::self->enabled && !ofEvent<void,Mutex>::self->functions.empty()){
742 std::unique_lock<Mutex> lck(ofEvent<void,Mutex>::self->mtx);
743 auto functions_copy = ofEvent<void,Mutex>::self->functions;
744 lck.unlock();
745 for(auto & f: functions_copy){
746 if(f->notify(nullptr)){
747 return true;
748 }
749 }
750 }
751 return false;
752 }
753};
754
755// -------------------------------------
758template<typename T>
759class ofFastEvent: public ofEvent<T,of::priv::NoopMutex>{
760public:
761 inline bool notify(const void* sender, T & param){
762 if(this->isEnabled()){
763 for(auto & f: ofFastEvent<T>::self->functions){
764 if(f->notify(sender, param)){
765 return true;
766 }
767 }
768 }
769 return false;
770 }
771};
772
Definition ofEvent.h:450
BaseFunctionId * clone() const
Definition ofEvent.h:461
bool operator==(const F &f1) const
Definition ofEvent.h:466
TMethod method
Definition ofEvent.h:453
FunctionId(TObj *listener, TMethod method)
Definition ofEvent.h:455
TObj * listener
Definition ofEvent.h:452
bool operator==(const BaseFunctionId &f) const
Definition ofEvent.h:470
bool operator==(const F &f1) const
Definition ofEvent.h:624
TMethod method
Definition ofEvent.h:611
FunctionId(TObj *listener, TMethod method)
Definition ofEvent.h:613
TObj * listener
Definition ofEvent.h:610
BaseFunctionId * clone() const
Definition ofEvent.h:619
bool operator==(const BaseFunctionId &f) const
Definition ofEvent.h:628
bool notify()
Definition ofEvent.h:740
FunctionPtr make_function(TObj *listener, bool(TObj::*method)(const void *), int priority)
Definition ofEvent.h:654
void add(TFunction function, int priority)
Definition ofEvent.h:712
std::unique_ptr< of::priv::AbstractEventToken > newListener(TFunction function, int priority=OF_EVENT_ORDER_AFTER_APP)
Definition ofEvent.h:717
std::unique_ptr< of::priv::BaseFunctionId > make_std_function_id(const F &f)
Definition ofEvent.h:667
FunctionPtr make_function(TObj *listener, void(TObj::*method)(), int priority)
Definition ofEvent.h:646
std::unique_ptr< of::priv::AbstractEventToken > newListener(TObj *listener, TMethod method, int priority=OF_EVENT_ORDER_AFTER_APP)
Definition ofEvent.h:702
void remove(TFunction function, int priority)
Definition ofEvent.h:722
FunctionPtr make_function(TObj *listener, bool(TObj::*method)(), int priority)
Definition ofEvent.h:641
FunctionPtr make_function(std::function< bool(const void *)> f, int priority)
Definition ofEvent.h:680
std::shared_ptr< Function > FunctionPtr
Definition ofEvent.h:605
FunctionPtr make_function(std::function< void()> f, int priority)
Definition ofEvent.h:684
void add(TObj *listener, TMethod method, int priority)
Definition ofEvent.h:697
FunctionPtr make_function(std::function< void(const void *)> f, int priority)
Definition ofEvent.h:688
bool notify(const void *sender)
Definition ofEvent.h:726
FunctionPtr make_function(TObj *listener, void(TObj::*method)(const void *), int priority)
Definition ofEvent.h:659
FunctionPtr make_function(std::function< bool()> f, int priority)
Definition ofEvent.h:676
std::unique_ptr< FunctionId< TObj, TMethod > > make_function_id(TObj *listener, TMethod method)
Definition ofEvent.h:636
of::priv::Function< void, Mutex > Function
Definition ofEvent.h:604
void remove(TObj *listener, TMethod method, int priority)
Definition ofEvent.h:707
Definition ofEvent.h:444
FunctionPtr make_function(std::function< bool(T &)> f, int priority)
Definition ofEvent.h:517
FunctionPtr make_function(std::function< void(T &)> f, int priority)
Definition ofEvent.h:525
FunctionPtr make_function(std::function< void(const void *, T &)> f, int priority)
Definition ofEvent.h:529
bool notify(T &param)
Definition ofEvent.h:582
std::unique_ptr< of::priv::AbstractEventToken > newListener(TObj *listener, TMethod method, int priority=OF_EVENT_ORDER_AFTER_APP)
Definition ofEvent.h:539
FunctionPtr make_function(std::function< bool(const void *, T &)> f, int priority)
Definition ofEvent.h:521
void remove(TFunction function, int priority)
Definition ofEvent.h:564
FunctionPtr make_function(TObj *listener, void(TObj::*method)(T &), int priority)
Definition ofEvent.h:487
std::unique_ptr< of::priv::BaseFunctionId > make_std_function_id(const F &f)
Definition ofEvent.h:508
bool notify(const void *sender, T &param)
Definition ofEvent.h:568
void add(TObj *listener, TMethod method, int priority)
Definition ofEvent.h:544
FunctionPtr make_function(TObj *listener, bool(TObj::*method)(const void *, T &), int priority)
Definition ofEvent.h:495
void remove(TObj *listener, TMethod method, int priority)
Definition ofEvent.h:549
std::unique_ptr< FunctionId< TObj, TMethod > > make_function_id(TObj *listener, TMethod method)
Definition ofEvent.h:477
std::unique_ptr< of::priv::AbstractEventToken > newListener(TFunction function, int priority=OF_EVENT_ORDER_AFTER_APP)
Definition ofEvent.h:554
std::shared_ptr< Function > FunctionPtr
Definition ofEvent.h:447
FunctionPtr make_function(TObj *listener, bool(TObj::*method)(T &), int priority)
Definition ofEvent.h:482
of::priv::Function< T, Mutex > Function
Definition ofEvent.h:446
FunctionPtr make_function(TObj *listener, void(TObj::*method)(const void *, T &), int priority)
Definition ofEvent.h:500
void add(TFunction function, int priority)
Definition ofEvent.h:559
Definition ofEvent.h:385
ofEventListener & operator=(ofEventListener &&)=delete
ofEventListener(ofEventListener &&)=delete
ofEventListener(std::unique_ptr< of::priv::AbstractEventToken > &&token)
Definition ofEvent.h:393
ofEventListener()
Definition ofEvent.h:387
ofEventListener & operator=(const ofEventListener &)=delete
void unsubscribe()
Definition ofEvent.h:401
ofEventListener(const ofEventListener &)=delete
ofEventListener & operator=(std::unique_ptr< of::priv::AbstractEventToken > &&token)
Definition ofEvent.h:396
Definition ofEvent.h:411
ofEventListeners(ofEventListeners &&)=delete
void unsubscribeAll()
Definition ofEvent.h:426
ofEventListeners & operator=(ofEventListeners &&)=delete
void push(std::unique_ptr< of::priv::AbstractEventToken > &&listener)
Definition ofEvent.h:420
ofEventListeners()
Definition ofEvent.h:413
bool empty() const
Definition ofEvent.h:430
OF_DEPRECATED_MSG("Don't use this method. If you need granular control over each listener, then use individual ofEventListener instances for each.", void unsubscribe(std::size_t pos))
ofEventListeners(const ofEventListeners &)=delete
ofEventListeners & operator=(const ofEventListeners &)=delete
Definition ofEvent.h:759
bool notify(const void *sender, T &param)
Definition ofEvent.h:761
Definition ofEvents.cpp:625
Definition ofPixels.h:1522
ofEventOrder
Definition ofEvent.h:378
@ OF_EVENT_ORDER_AFTER_APP
Definition ofEvent.h:381
@ OF_EVENT_ORDER_APP
Definition ofEvent.h:380
@ OF_EVENT_ORDER_BEFORE_APP
Definition ofEvent.h:379