21 #ifndef TLPGRAPHRECORDER_H 22 #define TLPGRAPHRECORDER_H 29 #include <tulip/Node.h> 31 #include <tulip/Graph.h> 33 #include <tulip/MutableContainer.h> 37 struct less<
tlp::Graph *> {
52 std::set<tlp::Graph *> graphs;
55 EdgeRecord(Graph *g, node s, node t) : source(s), target(t) {
60 struct GraphEltsRecord {
62 MutableContainer<bool> elts;
64 GraphEltsRecord(Graph *g) : graph(g) {}
71 struct less<
tlp::GraphEltsRecord *> {
72 size_t operator()(
const tlp::GraphEltsRecord *g1,
const tlp::GraphEltsRecord *g2)
const {
73 return g1->graph->getId() < g2->graph->getId();
80 class GraphStorageIdsMemento;
85 typedef GraphEltsRecord *GraphEltsRecordPtr;
86 DECL_STORED_PTR(GraphEltsRecordPtr);
87 typedef std::pair<node, node> *NodePairPtr;
88 DECL_STORED_PTR(NodePairPtr);
89 typedef std::vector<edge> *EdgeVectPtr;
90 DECL_STORED_PTR(EdgeVectPtr);
92 class GraphUpdatesRecorder :
public Observable {
93 friend class GraphImpl;
96 bool recordingStopped;
100 bool newValuesRecorded;
101 const bool oldIdsStateRecorded;
104 MutableContainer<GraphEltsRecordPtr> graphAddedNodes;
106 MutableContainer<bool> addedNodes;
108 MutableContainer<GraphEltsRecordPtr> graphDeletedNodes;
110 MutableContainer<GraphEltsRecord *> graphAddedEdges;
112 MutableContainer<NodePairPtr> addedEdgesEnds;
114 MutableContainer<GraphEltsRecord *> graphDeletedEdges;
116 MutableContainer<NodePairPtr> deletedEdgesEnds;
118 std::set<edge> revertedEdges;
120 TLP_HASH_MAP<edge, std::pair<node, node>> oldEdgesEnds;
122 TLP_HASH_MAP<edge, std::pair<node, node>> newEdgesEnds;
124 MutableContainer<EdgeVectPtr> oldContainers;
126 MutableContainer<EdgeVectPtr> newContainers;
129 const GraphStorageIdsMemento *oldIdsState;
131 const GraphStorageIdsMemento *newIdsState;
134 std::list<std::pair<Graph *, Graph *>> addedSubGraphs;
136 std::list<std::pair<Graph *, Graph *>> deletedSubGraphs;
139 TLP_HASH_MAP<Graph *, std::set<PropertyInterface *>> addedProperties;
141 TLP_HASH_MAP<Graph *, std::set<PropertyInterface *>> deletedProperties;
143 TLP_HASH_MAP<Graph *, DataSet> oldAttributeValues;
145 TLP_HASH_MAP<Graph *, DataSet> newAttributeValues;
148 TLP_HASH_MAP<PropertyInterface *, std::set<node>> updatedPropsAddedNodes;
151 TLP_HASH_MAP<PropertyInterface *, std::set<edge>> updatedPropsAddedEdges;
154 TLP_HASH_MAP<PropertyInterface *, DataMem *> oldNodeDefaultValues;
156 TLP_HASH_MAP<PropertyInterface *, DataMem *> newNodeDefaultValues;
158 TLP_HASH_MAP<PropertyInterface *, DataMem *> oldEdgeDefaultValues;
160 TLP_HASH_MAP<PropertyInterface *, DataMem *> newEdgeDefaultValues;
162 TLP_HASH_MAP<PropertyInterface *, std::string> renamedProperties;
164 struct RecordedValues {
165 PropertyInterface *values;
166 MutableContainer<bool> *recordedNodes;
167 MutableContainer<bool> *recordedEdges;
169 RecordedValues(PropertyInterface *prop =
nullptr, MutableContainer<bool> *rn =
nullptr,
170 MutableContainer<bool> *re =
nullptr)
171 : values(prop), recordedNodes(rn), recordedEdges(re) {}
175 TLP_HASH_MAP<PropertyInterface *, RecordedValues> oldValues;
177 TLP_HASH_MAP<PropertyInterface *, RecordedValues> newValues;
182 void deleteDeletedObjects();
184 void deleteValues(TLP_HASH_MAP<PropertyInterface *, RecordedValues> &values);
186 void deleteDefaultValues(TLP_HASH_MAP<PropertyInterface *, DataMem *> &values);
188 void recordEdgeContainer(MutableContainer<std::vector<edge> *> &, GraphImpl *, node);
190 void removeFromEdgeContainer(MutableContainer<std::vector<edge> *> &containers, edge e, node n);
192 void removeGraphData(Graph *);
196 void recordNewValues(GraphImpl *);
197 void recordNewNodeValues(PropertyInterface *p);
198 void recordNewEdgeValues(PropertyInterface *p);
201 void startRecording(GraphImpl *);
204 void stopRecording(Graph *);
206 void restartRecording(Graph *);
208 void doUpdates(GraphImpl *,
bool undo);
213 bool dontObserveProperty(PropertyInterface *);
215 bool isAddedOrDeletedProperty(Graph *, PropertyInterface *);
218 GraphUpdatesRecorder(
bool allowRestart =
true,
219 const GraphStorageIdsMemento *prevIdsMemento =
nullptr);
220 ~GraphUpdatesRecorder()
override;
224 void addNode(Graph *g,
const node n);
227 void addEdge(Graph *g,
const edge e);
230 void delNode(Graph *g,
const node n);
233 void delEdge(Graph *g,
const edge e);
236 void reverseEdge(Graph *g,
const edge e);
239 void beforeSetEnds(Graph *g,
const edge e);
242 void afterSetEnds(Graph *g,
const edge e);
245 void addSubGraph(Graph *g, Graph *sg);
248 void delSubGraph(Graph *g, Graph *sg);
251 void addLocalProperty(Graph *g,
const std::string &name);
254 void delLocalProperty(Graph *g,
const std::string &name);
257 void beforeSetAttribute(Graph *g,
const std::string &name);
260 void removeAttribute(Graph *g,
const std::string &name);
264 void beforeSetNodeValue(PropertyInterface *p,
const node n);
267 void beforeSetAllNodeValue(PropertyInterface *p);
270 void beforeSetEdgeValue(PropertyInterface *p,
const edge e);
273 void beforeSetAllEdgeValue(PropertyInterface *p);
276 void propertyRenamed(PropertyInterface *p);
280 void treatEvent(
const Event &ev)
override;
284 #endif // TLPGRAPHRECORDER_H
unsigned int getId() const
Gets the unique identifier of the graph.