MT Showcase SDK
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
CachedGraph.hpp
1 #pragma once
2 
3 #include "Export.hpp"
4 #include "CachedNode.hpp"
5 
6 namespace Showcase
7 {
8 
18  class SHOWCASE_API CachedGraph : public std::enable_shared_from_this<CachedGraph>
19  {
20  public:
21  CachedGraph(const GraphNode& root, GraphPtr graph);
22  ~CachedGraph();
23 
27  CachedNodePtr getNode(const NodeId& id) const;
28 
29  void startCaching();
30 
31  private:
35  void initNode(const GraphNode& node, std::unique_lock<std::mutex>&& lock);
36 
37  void nodeAdded(const GraphNode& node, const GraphNode& parent);
38  void nodeRemoved(const GraphNode& node, const GraphNode& parent);
39 
40  void addEdge(const NodeId& setOwner, const NodeId& toSet,
41  std::unordered_map<NodeId, std::set<NodeId>>& edges);
42  void removeEdge(const NodeId& from, const NodeId& to);
43 
45  void collectNodes(const NodeId& node, std::set<NodeId>& visited);
46 
47 
48  mutable std::mutex m_nodeMutex;
49  std::unordered_map<NodeId, CachedNodePtr> m_nodes;
50 
51  std::mutex m_edgeMutex;
53  std::unordered_map<NodeId, std::set<NodeId>> m_outgoingEdges;
54 
56  std::unordered_map<NodeId, std::set<NodeId>> m_incomingEdges;
57 
58  std::weak_ptr<Graph> m_graph;
59  };
60  typedef std::shared_ptr<CachedGraph> CachedGraphPtr;
61 
62 }
63