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 PropertyRecord {
63 PropertyInterface* prop;
66 PropertyRecord(PropertyInterface* p, std::string str)
67 :prop(p), name(str) {}
70 struct GraphEltsRecord {
72 MutableContainer<bool> elts;
74 GraphEltsRecord(Graph* g): graph(g) {}
81 struct less<tlp::PropertyRecord> {
82 size_t operator()(
const tlp::PropertyRecord& rp1,
const tlp::PropertyRecord& rp2)
const {
83 return rp1.name < rp2.name;
88 struct less<tlp::GraphEltsRecord*> {
89 size_t operator()(
const tlp::GraphEltsRecord* g1,
const tlp::GraphEltsRecord* g2)
const {
90 return g1->graph->getId() < g2->graph->getId();
97 class GraphStorageIdsMemento;
99 class GraphUpdatesRecorder :
public Observable {
100 friend class GraphImpl;
103 bool recordingStopped;
105 bool updatesReverted;
107 bool newValuesRecorded;
110 MutableContainer<GraphEltsRecord*> graphAddedNodes;
112 MutableContainer<bool> addedNodes;
114 MutableContainer<GraphEltsRecord*> graphDeletedNodes;
116 MutableContainer<GraphEltsRecord*> graphAddedEdges;
118 MutableContainer<std::pair<node, node>*> addedEdgesEnds;
120 MutableContainer<GraphEltsRecord*> graphDeletedEdges;
122 MutableContainer<std::pair<node, node>*> deletedEdgesEnds;
124 std::set<edge> revertedEdges;
126 TLP_HASH_MAP<edge, std::pair<node, node> > oldEdgesEnds;
128 TLP_HASH_MAP<edge, std::pair<node, node> > newEdgesEnds;
130 MutableContainer<std::vector<edge>*> oldContainers;
132 MutableContainer<std::vector<edge>*> newContainers;
135 const GraphStorageIdsMemento* oldIdsState;
137 const GraphStorageIdsMemento* newIdsState;
140 std::list<std::pair<Graph*, Graph*> > addedSubGraphs;
142 std::list<std::pair<Graph*, Graph*> > deletedSubGraphs;
145 TLP_HASH_MAP<Graph*, std::set<PropertyRecord> > addedProperties;
147 TLP_HASH_MAP<Graph*, std::set<PropertyRecord> > deletedProperties;
149 TLP_HASH_MAP<Graph*, DataSet> oldAttributeValues;
151 TLP_HASH_MAP<Graph*, DataSet> newAttributeValues;
154 TLP_HASH_MAP<PropertyInterface*, std::set<node> > updatedPropsAddedNodes;
157 TLP_HASH_MAP<PropertyInterface*, std::set<edge> > updatedPropsAddedEdges;
160 TLP_HASH_MAP<PropertyInterface*, DataMem*> oldNodeDefaultValues;
162 TLP_HASH_MAP<PropertyInterface*, DataMem*> newNodeDefaultValues;
164 TLP_HASH_MAP<PropertyInterface*, DataMem*> oldEdgeDefaultValues;
166 TLP_HASH_MAP<PropertyInterface*, DataMem*> newEdgeDefaultValues;
168 struct RecordedValues {
169 PropertyInterface* values;
170 MutableContainer<bool>* recordedNodes;
171 MutableContainer<bool>* recordedEdges;
173 RecordedValues(PropertyInterface* prop = NULL,
174 MutableContainer<bool>* rn = NULL,
175 MutableContainer<bool>* re = NULL):
176 values(prop), recordedNodes(rn), recordedEdges(re) {}
180 TLP_HASH_MAP<PropertyInterface*, RecordedValues> oldValues;
182 TLP_HASH_MAP<PropertyInterface*, RecordedValues> newValues;
187 void deleteDeletedObjects();
189 void deleteValues(TLP_HASH_MAP<PropertyInterface*, RecordedValues>& values);
191 void deleteDefaultValues(TLP_HASH_MAP<PropertyInterface*, DataMem*>& values);
194 void deleteContainerValues(MutableContainer<T>& ctnr) {
195 IteratorValue* it = ctnr.findAllValues(NULL,
false);
197 while(it->hasNext()) {
198 TypedValueContainer<T> tvc;
206 void recordEdgeContainer(MutableContainer<std::vector<edge>*>&,
209 void removeFromEdgeContainer(MutableContainer<std::vector<edge>*>& containers,
212 void removeGraphData(Graph *);
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