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 TLP_HASH_MAP<Graph*, std::set<Graph*> > addedSubGraphs;
144 TLP_HASH_MAP<Graph*, std::set<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,
216 void recordNewValues(GraphImpl*);
217 void recordNewNodeValues(PropertyInterface* p);
218 void recordNewEdgeValues(PropertyInterface* p);
221 void startRecording(GraphImpl*);
224 void stopRecording(Graph*);
226 void restartRecording(Graph*);
228 void doUpdates(GraphImpl*,
bool undo);
231 bool dontObserveProperty(PropertyInterface *);
233 bool isAddedOrDeletedProperty(Graph*, PropertyInterface *);
236 GraphUpdatesRecorder(
bool allowRestart =
true);
237 ~GraphUpdatesRecorder();
241 void addNode(Graph* g,
const node n);
244 void addEdge(Graph* g,
const edge e);
247 void delNode(Graph* g,
const node n);
250 void delEdge(Graph* g,
const edge e);
253 void reverseEdge(Graph* g,
const edge e);
256 void beforeSetEnds(Graph* g,
const edge e);
259 void afterSetEnds(Graph* g,
const edge e);
262 void addSubGraph(Graph* g, Graph* sg);
265 void delSubGraph(Graph* g, Graph* sg);
268 void addLocalProperty(Graph* g,
const std::string& name);
271 void delLocalProperty(Graph* g,
const std::string& name);
275 void beforeSetNodeValue(PropertyInterface* p,
const node n);
278 void beforeSetAllNodeValue(PropertyInterface* p);
281 void beforeSetEdgeValue(PropertyInterface* p,
const edge e);
284 void beforeSetAllEdgeValue(PropertyInterface* p);
287 void beforeSetAttribute(Graph* g,
const std::string& name);
290 void removeAttribute(Graph* g,
const std::string& name);
294 virtual void treatEvent(
const Event& ev);
299 #endif // TLPGRAPHRECORDER_H
300 #endif // DOXYGEN_NOTFOR_DEVEL