6 #include "StreamConsumer.hpp"
8 #include "ValueStream.hpp"
9 #include "ValueStreamChannels.hpp"
13 #include <unordered_map>
18 class SHOWCASE_API CachedNode :
public std::enable_shared_from_this<CachedNode>
23 PropertyMap properties;
24 std::map<NodeId, PropertyMap> edges;
26 NodeEventStreamPtr childStream;
27 PropertyEventStreamPtr propertyStream;
28 std::unordered_map<EdgeId, PropertyEventStreamPtr> edgePropertyStreams;
36 PropertyMap properties;
37 std::map<NodeId, PropertyMap> edges;
41 std::vector<ChannelGuard<ValueStreamChannel<PropertyEvent>>> propertyGuards;
43 friend class CachedNode;
46 typedef std::function<void(const PropertyEvent& ev)> PropFunc;
47 typedef std::function<void(const NodeId& child, const PropertyEvent& ev)> EdgePropFunc;
48 typedef std::function<void(const NodeEvent& ev)> ChildFunc;
58 CachedNode(GraphPtr graph,
const NodeId& node, std::size_t maxChildren=0);
67 const NodeId& nodeId()
const;
72 std::shared_ptr<CachedNode> clone();
75 void setOnChildEvent(ChildFunc f);
76 void setOnPropertyEvent(PropFunc f);
77 void setOnEdgePropertyEvent(EdgePropFunc f);
79 void addOnChildEvent(ChildFunc f);
80 void addOnPropertyEvent(PropFunc f);
81 void addOnEdgePropertyEvent(EdgePropFunc f);
83 void setChildrenPaused(
bool paused);
100 typedef CloneableValueStreamChannelPtr<NodeEvent> NodeEventChannelPtr;
101 typedef CloneableValueStreamChannelPtr<PropertyEvent> PropertyEventChannelPtr;
103 void initChildConsumer();
104 void initPropertyConsumer();
105 StreamConsumerPtr<PropEvType> initEdgePropertyConsumer(
const NodeId& childId);
109 void handlePropertyEvent(PropertyMap& targetMap,
const PropertyEvent& ev);
112 std::weak_ptr<Graph> m_graph;
115 std::size_t m_maxChildren;
118 PropertyMap m_properties;
122 std::map<NodeId, PropertyMap> m_edges;
125 std::mutex m_childMutex;
128 StreamConsumerPtr<NodeEvType> m_childConsumer;
129 StreamConsumerPtr<PropEvType> m_propertyConsumer;
130 std::unordered_map<EdgeId, StreamConsumerPtr<PropEvType>> m_edgePropertyConsumers;
134 NodeEventChannelPtr m_childStream;
135 PropertyEventChannelPtr m_propertyStream;
136 std::unordered_map<EdgeId, PropertyEventChannelPtr> m_edgePropertyStreams;
138 std::vector<ChildFunc> m_onChild;
139 std::vector<EdgePropFunc> m_onEdgeProp;
140 std::vector<PropFunc> m_onProp;
142 typedef std::shared_ptr<CachedNode> CachedNodePtr;