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;
82 class GraphUpdatesRecorder :
public Observable {
83 friend class GraphImpl;
86 bool recordingStopped;
90 bool newValuesRecorded;
91 const bool oldIdsStateRecorded;
94 MutableContainer<GraphEltsRecord*> graphAddedNodes;
96 MutableContainer<bool> addedNodes;
98 MutableContainer<GraphEltsRecord*> graphDeletedNodes;
100 MutableContainer<GraphEltsRecord*> graphAddedEdges;
102 MutableContainer<std::pair<node, node>*> addedEdgesEnds;
104 MutableContainer<GraphEltsRecord*> graphDeletedEdges;
106 MutableContainer<std::pair<node, node>*> deletedEdgesEnds;
108 std::set<edge> revertedEdges;
110 TLP_HASH_MAP<edge, std::pair<node, node> > oldEdgesEnds;
112 TLP_HASH_MAP<edge, std::pair<node, node> > newEdgesEnds;
114 MutableContainer<std::vector<edge>*> oldContainers;
116 MutableContainer<std::vector<edge>*> newContainers;
119 const GraphStorageIdsMemento* oldIdsState;
121 const GraphStorageIdsMemento* newIdsState;
124 std::list<std::pair<Graph*, Graph*> > addedSubGraphs;
126 std::list<std::pair<Graph*, Graph*> > deletedSubGraphs;
129 TLP_HASH_MAP<Graph*, std::set<PropertyInterface*> > addedProperties;
131 TLP_HASH_MAP<Graph*, std::set<PropertyInterface*> > deletedProperties;
133 TLP_HASH_MAP<Graph*, DataSet> oldAttributeValues;
135 TLP_HASH_MAP<Graph*, DataSet> newAttributeValues;
138 TLP_HASH_MAP<PropertyInterface*, std::set<node> > updatedPropsAddedNodes;
141 TLP_HASH_MAP<PropertyInterface*, std::set<edge> > updatedPropsAddedEdges;
144 TLP_HASH_MAP<PropertyInterface*, DataMem*> oldNodeDefaultValues;
146 TLP_HASH_MAP<PropertyInterface*, DataMem*> newNodeDefaultValues;
148 TLP_HASH_MAP<PropertyInterface*, DataMem*> oldEdgeDefaultValues;
150 TLP_HASH_MAP<PropertyInterface*, DataMem*> newEdgeDefaultValues;
152 TLP_HASH_MAP<PropertyInterface*, std::string> renamedProperties;
154 struct RecordedValues {
155 PropertyInterface* values;
156 MutableContainer<bool>* recordedNodes;
157 MutableContainer<bool>* recordedEdges;
159 RecordedValues(PropertyInterface* prop = NULL,
160 MutableContainer<bool>* rn = NULL,
161 MutableContainer<bool>* re = NULL):
162 values(prop), recordedNodes(rn), recordedEdges(re) {}
166 TLP_HASH_MAP<PropertyInterface*, RecordedValues> oldValues;
168 TLP_HASH_MAP<PropertyInterface*, RecordedValues> newValues;
173 void deleteDeletedObjects();
175 void deleteValues(TLP_HASH_MAP<PropertyInterface*, RecordedValues>& values);
177 void deleteDefaultValues(TLP_HASH_MAP<PropertyInterface*, DataMem*>& values);
180 void deleteContainerValues(MutableContainer<T>& ctnr) {
181 IteratorValue* it = ctnr.findAllValues(NULL,
false);
183 while(it->hasNext()) {
184 TypedValueContainer<T> tvc;
192 void recordEdgeContainer(MutableContainer<std::vector<edge>*>&,
195 void removeFromEdgeContainer(MutableContainer<std::vector<edge>*>& containers,
198 void removeGraphData(Graph *);
202 void recordNewValues(GraphImpl*);
203 void recordNewNodeValues(PropertyInterface* p);
204 void recordNewEdgeValues(PropertyInterface* p);
207 void startRecording(GraphImpl*);
210 void stopRecording(Graph*);
212 void restartRecording(Graph*);
214 void doUpdates(GraphImpl*,
bool undo);
217 bool dontObserveProperty(PropertyInterface *);
219 bool isAddedOrDeletedProperty(Graph*, PropertyInterface *);
222 GraphUpdatesRecorder(
bool allowRestart =
true,
223 const GraphStorageIdsMemento* prevIdsMemento = NULL);
224 ~GraphUpdatesRecorder();
228 void addNode(Graph* g,
const node n);
231 void addEdge(Graph* g,
const edge e);
234 void delNode(Graph* g,
const node n);
237 void delEdge(Graph* g,
const edge e);
240 void reverseEdge(Graph* g,
const edge e);
243 void beforeSetEnds(Graph* g,
const edge e);
246 void afterSetEnds(Graph* g,
const edge e);
249 void addSubGraph(Graph* g, Graph* sg);
252 void delSubGraph(Graph* g, Graph* sg);
255 void addLocalProperty(Graph* g,
const std::string& name);
258 void delLocalProperty(Graph* g,
const std::string& name);
261 void beforeSetAttribute(Graph* g,
const std::string& name);
264 void removeAttribute(Graph* g,
const std::string& name);
268 void beforeSetNodeValue(PropertyInterface* p,
const node n);
271 void beforeSetAllNodeValue(PropertyInterface* p);
274 void beforeSetEdgeValue(PropertyInterface* p,
const edge e);
277 void beforeSetAllEdgeValue(PropertyInterface* p);
280 void propertyRenamed(PropertyInterface* p);
284 virtual void treatEvent(
const Event& ev);
288 #endif // TLPGRAPHRECORDER_H
unsigned int getId() const
Gets the unique identifier of the graph.