21 #ifndef DOXYGEN_NOTFOR_DEVEL
22 #ifndef TLPGRAPHRECORDER_H
23 #define TLPGRAPHRECORDER_H
31 #include <tulip/Node.h>
33 #include <tulip/Graph.h>
35 #include <tulip/MutableContainer.h>
39 struct less<tlp::Graph*> {
54 std::set<tlp::Graph*> graphs;
57 EdgeRecord(Graph* g, node s, node t) : source(s), target(t) {
62 struct GraphEltsRecord {
64 MutableContainer<bool> elts;
66 GraphEltsRecord(Graph* g): graph(g) {}
73 struct less<tlp::GraphEltsRecord*> {
74 size_t operator()(
const tlp::GraphEltsRecord* g1,
const tlp::GraphEltsRecord* g2)
const {
75 return g1->graph->getId() < g2->graph->getId();
82 class GraphStorageIdsMemento;
84 class GraphUpdatesRecorder :
public Observable {
85 friend class GraphImpl;
88 bool recordingStopped;
92 bool newValuesRecorded;
93 const bool oldIdsStateRecorded;
96 MutableContainer<GraphEltsRecord*> graphAddedNodes;
98 MutableContainer<bool> addedNodes;
100 MutableContainer<GraphEltsRecord*> graphDeletedNodes;
102 MutableContainer<GraphEltsRecord*> graphAddedEdges;
104 MutableContainer<std::pair<node, node>*> addedEdgesEnds;
106 MutableContainer<GraphEltsRecord*> graphDeletedEdges;
108 MutableContainer<std::pair<node, node>*> deletedEdgesEnds;
110 std::set<edge> revertedEdges;
112 TLP_HASH_MAP<edge, std::pair<node, node> > oldEdgesEnds;
114 TLP_HASH_MAP<edge, std::pair<node, node> > newEdgesEnds;
116 MutableContainer<std::vector<edge>*> oldContainers;
118 MutableContainer<std::vector<edge>*> newContainers;
121 const GraphStorageIdsMemento* oldIdsState;
123 const GraphStorageIdsMemento* newIdsState;
126 std::list<std::pair<Graph*, Graph*> > addedSubGraphs;
128 std::list<std::pair<Graph*, Graph*> > deletedSubGraphs;
131 TLP_HASH_MAP<Graph*, std::set<PropertyInterface*> > addedProperties;
133 TLP_HASH_MAP<Graph*, std::set<PropertyInterface*> > deletedProperties;
135 TLP_HASH_MAP<Graph*, DataSet> oldAttributeValues;
137 TLP_HASH_MAP<Graph*, DataSet> newAttributeValues;
140 TLP_HASH_MAP<PropertyInterface*, std::set<node> > updatedPropsAddedNodes;
143 TLP_HASH_MAP<PropertyInterface*, std::set<edge> > updatedPropsAddedEdges;
146 TLP_HASH_MAP<PropertyInterface*, DataMem*> oldNodeDefaultValues;
148 TLP_HASH_MAP<PropertyInterface*, DataMem*> newNodeDefaultValues;
150 TLP_HASH_MAP<PropertyInterface*, DataMem*> oldEdgeDefaultValues;
152 TLP_HASH_MAP<PropertyInterface*, DataMem*> newEdgeDefaultValues;
154 TLP_HASH_MAP<PropertyInterface*, std::string> renamedProperties;
156 struct RecordedValues {
157 PropertyInterface* values;
158 MutableContainer<bool>* recordedNodes;
159 MutableContainer<bool>* recordedEdges;
161 RecordedValues(PropertyInterface* prop = NULL,
162 MutableContainer<bool>* rn = NULL,
163 MutableContainer<bool>* re = NULL):
164 values(prop), recordedNodes(rn), recordedEdges(re) {}
168 TLP_HASH_MAP<PropertyInterface*, RecordedValues> oldValues;
170 TLP_HASH_MAP<PropertyInterface*, RecordedValues> newValues;
175 void deleteDeletedObjects();
177 void deleteValues(TLP_HASH_MAP<PropertyInterface*, RecordedValues>& values);
179 void deleteDefaultValues(TLP_HASH_MAP<PropertyInterface*, DataMem*>& values);
182 void deleteContainerValues(MutableContainer<T>& ctnr) {
183 IteratorValue* it = ctnr.findAllValues(NULL,
false);
185 while(it->hasNext()) {
186 TypedValueContainer<T> tvc;
194 void recordEdgeContainer(MutableContainer<std::vector<edge>*>&,
197 void removeFromEdgeContainer(MutableContainer<std::vector<edge>*>& containers,
200 void removeGraphData(Graph *);
204 void recordNewValues(GraphImpl*);
205 void recordNewNodeValues(PropertyInterface* p);
206 void recordNewEdgeValues(PropertyInterface* p);
209 void startRecording(GraphImpl*);
212 void stopRecording(Graph*);
214 void restartRecording(Graph*);
216 void doUpdates(GraphImpl*,
bool undo);
219 bool dontObserveProperty(PropertyInterface *);
221 bool isAddedOrDeletedProperty(Graph*, PropertyInterface *);
224 GraphUpdatesRecorder(
bool allowRestart =
true,
225 const GraphStorageIdsMemento* prevIdsMemento = NULL);
226 ~GraphUpdatesRecorder();
230 void addNode(Graph* g,
const node n);
233 void addEdge(Graph* g,
const edge e);
236 void delNode(Graph* g,
const node n);
239 void delEdge(Graph* g,
const edge e);
242 void reverseEdge(Graph* g,
const edge e);
245 void beforeSetEnds(Graph* g,
const edge e);
248 void afterSetEnds(Graph* g,
const edge e);
251 void addSubGraph(Graph* g, Graph* sg);
254 void delSubGraph(Graph* g, Graph* sg);
257 void addLocalProperty(Graph* g,
const std::string& name);
260 void delLocalProperty(Graph* g,
const std::string& name);
263 void beforeSetAttribute(Graph* g,
const std::string& name);
266 void removeAttribute(Graph* g,
const std::string& name);
270 void beforeSetNodeValue(PropertyInterface* p,
const node n);
273 void beforeSetAllNodeValue(PropertyInterface* p);
276 void beforeSetEdgeValue(PropertyInterface* p,
const edge e);
279 void beforeSetAllEdgeValue(PropertyInterface* p);
282 void propertyRenamed(PropertyInterface* p);
286 virtual void treatEvent(
const Event& ev);
291 #endif // TLPGRAPHRECORDER_H
292 #endif // DOXYGEN_NOTFOR_DEVEL
unsigned int getId() const
Gets the unique identifier of the graph.