YAPOG  0.0.1
Yet Another Pokemon Online Game
Event.hpp
Go to the documentation of this file.
1 #ifndef YAPOG_EVENT_HPP
2 # define YAPOG_EVENT_HPP
3 
4 # include <functional>
5 # include <memory>
6 
7 # include <boost/signals2.hpp>
8 
9 # include "YAPOG/Macros.hpp"
10 # include "YAPOG/Collection/Map.hpp"
11 # include "YAPOG/System/String.hpp"
12 
13 namespace yap
14 {
16 
17  template <typename T>
19  {
20  public: ConstChangeEventArgs (const T& old, const T& current)
21  : Old (old), Current (current) { }
22  const T& Old, Current;
23  };
24 
25  template <typename T>
27  {
28  public: ChangeEventArgs (T& old, T& current)
29  : Old (old), Current (current) { }
30  T& Old, Current;
31  };
32 
33  template <typename SenderType,
34  typename ArgsType = const EmptyEventArgs&,
35  typename ReturnType = void>
36  class Event
37  {
39 
40  typedef boost::signals2::signal<
41  ReturnType (SenderType, ArgsType)> SignalType;
42  typedef typename SignalType::slot_type HandlerType;
43 
44  public:
45 
46  Event ();
47  ~Event ();
48 
49  Event& operator+= (HandlerType handler);
50 
51  void AddHandler (const String& name, HandlerType handler);
52  void RemoveHandler (const String& name);
53 
54  ReturnType operator() (SenderType sender, ArgsType args);
55 
56  private:
57 
58  typedef boost::signals2::scoped_connection ConnectionType;
59 
61 
63  };
64 } // namespace yap
65 
67 
68 #endif // YAPOG_EVENT_HPP