All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
CatalogBinding.h
1 // Copyright (c) 2014 eeGeo. All rights reserved.
2 
3 #pragma once
4 
5 #include <algorithm>
6 #include <vector>
7 #include "ICallback.h"
8 
9 namespace Eegeo
10 {
11  namespace Messaging
12  {
13  template <typename TMessage>
15  {
16  private:
17  typedef std::vector<Eegeo::Helpers::ICallback1<const TMessage&>* > TSubscribers;
18  TSubscribers m_subscribers;
19 
20  public:
21  void Subscribe(Eegeo::Helpers::ICallback1<const TMessage&>& subscription)
22  {
23  m_subscribers.push_back(&subscription);
24  }
25 
26  void Unsubscribe(Eegeo::Helpers::ICallback1<const TMessage&>& subscription)
27  {
28  m_subscribers.erase(std::find(m_subscribers.begin(), m_subscribers.end(), &subscription));
29  }
30 
31  void Dispatch(const TMessage& message)
32  {
33  for (typename TSubscribers::iterator it = m_subscribers.begin();
34  it != m_subscribers.end();
35  ++it)
36  {
38  func(message);
39  }
40  }
41  };
42  }
43 }