21 #ifndef TLPGRAPHRECORDER_H
22 #define TLPGRAPHRECORDER_H
26 #include <unordered_set>
29 #include <tulip/Graph.h>
30 #include <tulip/MutableContainer.h>
31 #include <tulip/tuliphash.h>
35 struct less<
tlp::Graph *> {
47 class GraphStorageIdsMemento;
49 class GraphUpdatesRecorder :
public Observable {
50 friend class GraphImpl;
53 bool recordingStopped;
57 bool newValuesRecorded;
58 const bool oldIdsStateRecorded;
61 tlp_hash_map<Graph *, std::unordered_set<node>> graphAddedNodes;
63 std::unordered_set<node> addedNodes;
65 tlp_hash_map<Graph *, std::unordered_set<node>> graphDeletedNodes;
67 std::map<Graph *, std::unordered_set<edge>> graphAddedEdges;
69 tlp_hash_map<edge, std::pair<node, node>> addedEdgesEnds;
71 std::map<Graph *, std::unordered_set<edge>> graphDeletedEdges;
73 tlp_hash_map<edge, std::pair<node, node>> deletedEdgesEnds;
75 std::unordered_set<edge> revertedEdges;
77 tlp_hash_map<edge, std::pair<node, node>> oldEdgesEnds;
79 tlp_hash_map<edge, std::pair<node, node>> newEdgesEnds;
81 tlp_hash_map<node, std::vector<edge>> oldContainers;
83 tlp_hash_map<node, std::vector<edge>> newContainers;
86 const GraphStorageIdsMemento *oldIdsState;
88 const GraphStorageIdsMemento *newIdsState;
91 std::list<std::pair<Graph *, Graph *>> addedSubGraphs;
93 std::list<std::pair<Graph *, Graph *>> deletedSubGraphs;
96 tlp_hash_map<Graph *, std::set<PropertyInterface *>> addedProperties;
98 tlp_hash_map<Graph *, std::set<PropertyInterface *>> deletedProperties;
100 tlp_hash_map<Graph *, DataSet> oldAttributeValues;
102 tlp_hash_map<Graph *, DataSet> newAttributeValues;
105 tlp_hash_map<PropertyInterface *, std::set<node>> updatedPropsAddedNodes;
108 tlp_hash_map<PropertyInterface *, std::set<edge>> updatedPropsAddedEdges;
111 tlp_hash_map<PropertyInterface *, DataMem *> oldNodeDefaultValues;
113 tlp_hash_map<PropertyInterface *, DataMem *> newNodeDefaultValues;
115 tlp_hash_map<PropertyInterface *, DataMem *> oldEdgeDefaultValues;
117 tlp_hash_map<PropertyInterface *, DataMem *> newEdgeDefaultValues;
119 tlp_hash_map<PropertyInterface *, std::string> renamedProperties;
121 struct RecordedValues {
122 PropertyInterface *values;
123 MutableContainer<bool> *recordedNodes;
124 MutableContainer<bool> *recordedEdges;
126 RecordedValues(PropertyInterface *prop =
nullptr, MutableContainer<bool> *rn =
nullptr,
127 MutableContainer<bool> *re =
nullptr)
128 : values(prop), recordedNodes(rn), recordedEdges(re) {}
132 tlp_hash_map<PropertyInterface *, RecordedValues> oldValues;
134 tlp_hash_map<PropertyInterface *, RecordedValues> newValues;
139 void deleteDeletedObjects();
141 void deleteValues(tlp_hash_map<PropertyInterface *, RecordedValues> &values);
143 void deleteDefaultValues(tlp_hash_map<PropertyInterface *, DataMem *> &values);
145 void recordEdgeContainer(tlp_hash_map<node, std::vector<edge>> &, GraphImpl *, node,
146 edge e = edge(),
bool loop =
false);
147 void recordEdgeContainer(tlp_hash_map<node, std::vector<edge>> &, GraphImpl *, node,
148 const std::vector<edge> &,
unsigned int);
150 void removeFromEdgeContainer(tlp_hash_map<node, std::vector<edge>> &containers, edge e, node n);
152 void removeGraphData(Graph *);
156 void recordNewValues(GraphImpl *);
157 void recordNewNodeValues(PropertyInterface *p);
158 void recordNewEdgeValues(PropertyInterface *p);
161 void startRecording(GraphImpl *);
164 void stopRecording(Graph *);
166 void restartRecording(Graph *);
168 void doUpdates(GraphImpl *,
bool undo);
173 bool dontObserveProperty(PropertyInterface *);
175 bool isAddedOrDeletedProperty(Graph *, PropertyInterface *);
178 GraphUpdatesRecorder(
bool allowRestart =
true,
179 const GraphStorageIdsMemento *prevIdsMemento =
nullptr);
180 ~GraphUpdatesRecorder()
override;
184 void addNode(Graph *g,
const node n);
187 void addEdge(Graph *g,
const edge e);
189 void addEdges(Graph *g,
unsigned int nbAddedEdges);
192 void delNode(Graph *g,
const node n);
195 void delEdge(Graph *g,
const edge e);
198 void reverseEdge(Graph *g,
const edge e);
201 void beforeSetEnds(Graph *g,
const edge e);
204 void afterSetEnds(Graph *g,
const edge e);
207 void addSubGraph(Graph *g, Graph *sg);
210 void delSubGraph(Graph *g, Graph *sg);
213 void addLocalProperty(Graph *g,
const std::string &name);
216 void delLocalProperty(Graph *g,
const std::string &name);
219 void beforeSetAttribute(Graph *g,
const std::string &name);
222 void removeAttribute(Graph *g,
const std::string &name);
226 void beforeSetNodeValue(PropertyInterface *p,
const node n);
229 void beforeSetAllNodeValue(PropertyInterface *p);
232 void beforeSetEdgeValue(PropertyInterface *p,
const edge e);
235 void beforeSetAllEdgeValue(PropertyInterface *p);
238 void propertyRenamed(PropertyInterface *p);
242 void treatEvent(
const Event &ev)
override;
unsigned int getId() const
Gets the unique identifier of the graph.