MT Showcase SDK
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
ChangeListener.hpp
1 #pragma once
2 
3 #include "Export.hpp"
4 
5 #include <memory>
6 #include <unordered_map>
7 
8 #include "Hashes.hpp"
9 
10 #include "GraphGenerators.hpp"
11 #include "GraphTypes.hpp"
12 
13 namespace Showcase
14 {
15 
17  class SHOWCASE_API ChangeListener
18  {
19  public:
20  typedef std::weak_ptr<Notifiable> NotifiableWeakPtr;
21  typedef std::vector<std::pair<NotifiableWeakPtr, size_t>> NodeEntries;
22  typedef std::unordered_map<NodeId, NodeEntries> Notifiables;
23  typedef std::pair<NodeId, size_t> Key;
24 
26 
27  void notifyAll();
28  void changed(const NodeId& node);
29 
30  Key subscribeToChanges(const NodeId& nid, NotifiableWeakPtr gen);
31  void unsubscribeToChanges(const Key& key);
32 
33  private:
35  std::mutex m_changeMutex;
36  Notifiables m_subscribers;
37 
38  size_t m_identifier;
39  };
40  typedef std::shared_ptr<ChangeListener> ChangeListenerPtr;
41 
42 }