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 = NULL,
170 MutableContainer<bool>* rn = NULL,
171 MutableContainer<bool>* re = NULL):
172 values(prop), recordedNodes(rn), recordedEdges(re) {}
176 TLP_HASH_MAP<PropertyInterface*, RecordedValues> oldValues;
178 TLP_HASH_MAP<PropertyInterface*, RecordedValues> newValues;
183 void deleteDeletedObjects();
185 void deleteValues(TLP_HASH_MAP<PropertyInterface*, RecordedValues>& values);
187 void deleteDefaultValues(TLP_HASH_MAP<PropertyInterface*, DataMem*>& values);
189 void recordEdgeContainer(MutableContainer<std::vector<edge>*>&,
192 void removeFromEdgeContainer(MutableContainer<std::vector<edge>*>& containers,
195 void removeGraphData(Graph *);
199 void recordNewValues(GraphImpl*);
200 void recordNewNodeValues(PropertyInterface* p);
201 void recordNewEdgeValues(PropertyInterface* p);
204 void startRecording(GraphImpl*);
207 void stopRecording(Graph*);
209 void restartRecording(Graph*);
211 void doUpdates(GraphImpl*,
bool undo);
216 bool dontObserveProperty(PropertyInterface *);
218 bool isAddedOrDeletedProperty(Graph*, PropertyInterface *);
221 GraphUpdatesRecorder(
bool allowRestart =
true,
222 const GraphStorageIdsMemento* prevIdsMemento = NULL);
223 ~GraphUpdatesRecorder();
227 void addNode(Graph* g,
const node n);
230 void addEdge(Graph* g,
const edge e);
233 void delNode(Graph* g,
const node n);
236 void delEdge(Graph* g,
const edge e);
239 void reverseEdge(Graph* g,
const edge e);
242 void beforeSetEnds(Graph* g,
const edge e);
245 void afterSetEnds(Graph* g,
const edge e);
248 void addSubGraph(Graph* g, Graph* sg);
251 void delSubGraph(Graph* g, Graph* sg);
254 void addLocalProperty(Graph* g,
const std::string& name);
257 void delLocalProperty(Graph* g,
const std::string& name);
260 void beforeSetAttribute(Graph* g,
const std::string& name);
263 void removeAttribute(Graph* g,
const std::string& name);
267 void beforeSetNodeValue(PropertyInterface* p,
const node n);
270 void beforeSetAllNodeValue(PropertyInterface* p);
273 void beforeSetEdgeValue(PropertyInterface* p,
const edge e);
276 void beforeSetAllEdgeValue(PropertyInterface* p);
279 void propertyRenamed(PropertyInterface* p);
283 virtual void treatEvent(
const Event& ev);
287 #endif // TLPGRAPHRECORDER_H
unsigned int getId() const
Gets the unique identifier of the graph.