pianod2
multisource multiuser scriptable networked music player
callback.h
Go to the documentation of this file.
1 
10 #pragma once
11 
12 #include <unordered_map>
13 #include <functional>
14 
20 template <typename TOwner, typename TCallbacks, typename TCallbackClientId = void *>
22  friend TOwner;
23 
25  std::unordered_map<TCallbackClientId, TCallbacks> registered_handlers;
26 
27  template<typename TMemberFunction, typename... Arguments>
28  void notify (TMemberFunction function, const Arguments &... arguments);
29 
30 
31  template<typename TMemberFunction, typename... Arguments>
32  void callback (TMemberFunction function, Arguments &&... arguments);
33 
34  template <typename TReturnType, typename TMemberFunction, typename... Arguments>
35  TReturnType aggregate (TReturnType result, const std::function<TReturnType (TReturnType, TReturnType)> &combine,
36  TMemberFunction function, const Arguments &... arguments);
37 
38  template<typename TMemberFunction, typename... Arguments>
39  bool queryUnanimousApproval (bool default_result, TMemberFunction function, const Arguments &... arguments);
40 
41  template<typename TMemberFunction, typename... Arguments>
42  bool queryAnyApproval (bool default_result, TMemberFunction function, const Arguments &... arguments);
43 
44 public:
45  void subscribe (const TCallbackClientId client_id, const TCallbacks &handlers);
46  void unsubscribe (const TCallbackClientId client_id);
47 };
48 
A template class to manage callback, delegate and notification functions.
Definition: callback.h:21
TReturnType aggregate(TReturnType result, const std::function< TReturnType(TReturnType, TReturnType)> &combine, TMemberFunction function, const Arguments &... arguments)
Invoke a delegate function and aggregate the results.
Definition: callbackimpl.h:56
std::unordered_map< TCallbackClientId, TCallbacks > registered_handlers
The list of subscribers to the callbacks.
Definition: callback.h:25
void callback(TMemberFunction function, Arguments &&... arguments)
Invoke a callback function.
Definition: callbackimpl.h:40
void notify(TMemberFunction function, const Arguments &... arguments)
Invoke a notification function.
Definition: callbackimpl.h:26
void unsubscribe(const TCallbackClientId client_id)
Remove registered callbacks, delegates, or notifications.
Definition: callbackimpl.h:108
bool queryAnyApproval(bool default_result, TMemberFunction function, const Arguments &... arguments)
Check for approval by any delegate.
Definition: callbackimpl.h:92
void subscribe(const TCallbackClientId client_id, const TCallbacks &handlers)
Register callback, delegate, or notification functions.
Definition: callbackimpl.h:101
friend TOwner
Definition: callback.h:22
bool queryUnanimousApproval(bool default_result, TMemberFunction function, const Arguments &... arguments)
Check for approval from all delegates.
Definition: callbackimpl.h:80