21 #ifndef DOXYGEN_NOTFOR_DEVEL
22 #ifndef TLPGRAPHRECORDER_H
23 #define TLPGRAPHRECORDER_H
30 #include <tulip/tuliphash.h>
31 #include <tulip/Node.h>
32 #include <tulip/Edge.h>
33 #include <tulip/Graph.h>
34 #include <tulip/Observable.h>
35 #include <tulip/ObservableGraph.h>
36 #include <tulip/ObservableProperty.h>
37 #include <tulip/MutableContainer.h>
41 struct less<tlp::Graph*> {
56 std::set<tlp::Graph*> graphs;
59 EdgeRecord(Graph* g, node s, node t) : source(s), target(t) {
64 struct PropertyRecord {
65 PropertyInterface* prop;
68 PropertyRecord(PropertyInterface* p, std::string str)
69 :prop(p), name(str) {}
72 struct GraphEltsRecord {
74 MutableContainer<bool> elts;
76 GraphEltsRecord(Graph* g): graph(g) {}
83 struct less<tlp::PropertyRecord> {
84 size_t operator()(
const tlp::PropertyRecord& rp1,
const tlp::PropertyRecord& rp2)
const {
85 return rp1.name < rp2.name;
90 struct less<tlp::GraphEltsRecord*> {
91 size_t operator()(
const tlp::GraphEltsRecord* g1,
const tlp::GraphEltsRecord* g2)
const {
92 return g1->graph->getId() < g2->graph->getId();
99 class GraphStorageIdsMemento;
101 class GraphUpdatesRecorder :
public GraphObserver,
public PropertyObserver,
public Observable {
102 friend class GraphImpl;
105 bool recordingStopped;
107 bool updatesReverted;
109 bool newValuesRecorded;
112 MutableContainer<GraphEltsRecord*> graphAddedNodes;
114 MutableContainer<bool> addedNodes;
116 MutableContainer<GraphEltsRecord*> graphDeletedNodes;
118 MutableContainer<GraphEltsRecord*> graphAddedEdges;
120 MutableContainer<std::pair<node, node>*> addedEdgesEnds;
122 MutableContainer<GraphEltsRecord*> graphDeletedEdges;
124 MutableContainer<std::pair<node, node>*> deletedEdgesEnds;
126 std::set<edge> revertedEdges;
128 TLP_HASH_MAP<edge, std::pair<node, node> > oldEdgesEnds;
130 TLP_HASH_MAP<edge, std::pair<node, node> > newEdgesEnds;
132 MutableContainer<std::vector<edge>*> oldContainers;
134 MutableContainer<std::vector<edge>*> newContainers;
137 const GraphStorageIdsMemento* oldIdsState;
139 const GraphStorageIdsMemento* newIdsState;
142 std::list<std::pair<Graph*, Graph*> > addedSubGraphs;
144 std::list<std::pair<Graph*, Graph*> > deletedSubGraphs;
147 TLP_HASH_MAP<Graph*, std::set<PropertyRecord> > addedProperties;
149 TLP_HASH_MAP<Graph*, std::set<PropertyRecord> > deletedProperties;
151 TLP_HASH_MAP<Graph*, DataSet> oldAttributeValues;
153 TLP_HASH_MAP<Graph*, DataSet> newAttributeValues;
156 TLP_HASH_MAP<PropertyInterface*, std::set<node> > updatedPropsAddedNodes;
159 TLP_HASH_MAP<PropertyInterface*, std::set<edge> > updatedPropsAddedEdges;
162 TLP_HASH_MAP<PropertyInterface*, DataMem*> oldNodeDefaultValues;
164 TLP_HASH_MAP<PropertyInterface*, DataMem*> newNodeDefaultValues;
166 TLP_HASH_MAP<PropertyInterface*, DataMem*> oldEdgeDefaultValues;
168 TLP_HASH_MAP<PropertyInterface*, DataMem*> newEdgeDefaultValues;
170 struct RecordedValues {
171 PropertyInterface* values;
172 MutableContainer<bool>* recordedNodes;
173 MutableContainer<bool>* recordedEdges;
175 RecordedValues(PropertyInterface* prop = NULL,
176 MutableContainer<bool>* rn = NULL,
177 MutableContainer<bool>* re = NULL):
178 values(prop), recordedNodes(rn), recordedEdges(re) {}
182 TLP_HASH_MAP<PropertyInterface*, RecordedValues> oldValues;
184 TLP_HASH_MAP<PropertyInterface*, RecordedValues> newValues;
189 void deleteDeletedObjects();
191 void deleteValues(TLP_HASH_MAP<PropertyInterface*, RecordedValues>& values);
193 void deleteDefaultValues(TLP_HASH_MAP<PropertyInterface*, DataMem*>& values);
196 void deleteContainerValues(MutableContainer<T>& ctnr) {
197 IteratorValue* it = ctnr.findAllValues(NULL,
false);
199 while(it->hasNext()) {
200 TypedValueContainer<T> tvc;
208 void recordEdgeContainer(MutableContainer<std::vector<edge>*>&,
211 void removeFromEdgeContainer(MutableContainer<std::vector<edge>*>& containers,
214 void removeGraphData(Graph *);
218 void recordNewValues(GraphImpl*);
219 void recordNewNodeValues(PropertyInterface* p);
220 void recordNewEdgeValues(PropertyInterface* p);
223 void startRecording(GraphImpl*);
226 void stopRecording(Graph*);
228 void restartRecording(Graph*);
230 void doUpdates(GraphImpl*,
bool undo);
233 bool dontObserveProperty(PropertyInterface *);
235 bool isAddedOrDeletedProperty(Graph*, PropertyInterface *);
238 GraphUpdatesRecorder(
bool allowRestart =
true);
239 ~GraphUpdatesRecorder();
243 void addNode(Graph* g,
const node n);
246 void addEdge(Graph* g,
const edge e);
249 void delNode(Graph* g,
const node n);
252 void delEdge(Graph* g,
const edge e);
255 void reverseEdge(Graph* g,
const edge e);
258 void beforeSetEnds(Graph* g,
const edge e);
261 void afterSetEnds(Graph* g,
const edge e);
264 void addSubGraph(Graph* g, Graph* sg);
267 void delSubGraph(Graph* g, Graph* sg);
270 void addLocalProperty(Graph* g,
const std::string& name);
273 void delLocalProperty(Graph* g,
const std::string& name);
277 void beforeSetNodeValue(PropertyInterface* p,
const node n);
280 void beforeSetAllNodeValue(PropertyInterface* p);
283 void beforeSetEdgeValue(PropertyInterface* p,
const edge e);
286 void beforeSetAllEdgeValue(PropertyInterface* p);
289 void beforeSetAttribute(Graph* g,
const std::string& name);
292 void removeAttribute(Graph* g,
const std::string& name);
296 virtual void treatEvent(
const Event& ev);
301 #endif // TLPGRAPHRECORDER_H
302 #endif // DOXYGEN_NOTFOR_DEVEL