forked from lduchesne/cmatopo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtransaction.cpp
More file actions
176 lines (147 loc) · 3.72 KB
/
transaction.cpp
File metadata and controls
176 lines (147 loc) · 3.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#include <transaction.h>
#include <topology.h>
using namespace std;
namespace cma {
EdgeTransaction::EdgeTransaction(Topology& topology, edge* e)
: TopologyTransaction(topology)
, _edge(new edge(e, false))
{
}
EdgeTransaction::~EdgeTransaction()
{
if (_topology._edges[_edge->id]->geom == _edge->geom
|| _is_in(_edge->geom, *_topology._tr_track_geom))
{
_edge->geom = nullptr;
}
else {
_topology._tr_track_geom->insert(_edge->geom);
}
delete _edge;
}
void EdgeTransaction::rollback()
{
edge* oldEdge = _topology._edges[_edge->id];
_topology._edges[_edge->id] = _edge;
_edge = oldEdge;
}
NodeTransaction::NodeTransaction(Topology& topology, node* n)
: TopologyTransaction(topology)
, _node(new node(n, false))
{
}
NodeTransaction::~NodeTransaction()
{
if (_topology._nodes[_node->id]->geom == _node->geom
|| _is_in(_node->geom, *_topology._tr_track_geom))
{
_node->geom = nullptr;
}
else {
_topology._tr_track_geom->insert(_node->geom);
}
delete _node;
}
void NodeTransaction::rollback()
{
node* oldNode = _topology._nodes[_node->id];
_topology._nodes[_node->id] = _node;
_node = oldNode;
}
FaceTransaction::FaceTransaction(Topology& topology, face* f)
: TopologyTransaction(topology)
, _face(new face(f, false))
{
}
FaceTransaction::~FaceTransaction()
{
if (_face->geom == nullptr || _topology._faces[_face->id]->geom == _face->geom
|| _is_in(_face->geom, *_topology._tr_track_geom))
{
_face->geom = nullptr;
}
else {
_topology._tr_track_geom->insert(_face->geom);
}
delete _face;
}
void FaceTransaction::rollback()
{
face* oldFace = _topology._faces[_face->id];
_topology._faces[_face->id] = _face;
_face = oldFace;
}
AddFaceIndexTransaction::AddFaceIndexTransaction(
Topology& topology,
vector<edgeid_set_ptr>* index,
int faceId,
int edgeId
)
: TopologyTransaction(topology)
, _index(index)
, _faceId(faceId)
, _edgeId(edgeId)
{
}
AddFaceIndexTransaction::~AddFaceIndexTransaction()
{
}
void AddFaceIndexTransaction::rollback()
{
size_t nelem = (*_index)[_faceId]->erase(_edgeId);
assert (nelem == 1);
// invalidate face geometry cache
if ((*_topology._face_geometries)[_faceId]) {
GEOSGeom_destroy_r(hdl, (*_topology._face_geometries)[_faceId]);
(*_topology._face_geometries)[_faceId] = nullptr;
}
}
RemoveFaceIndexTransaction::RemoveFaceIndexTransaction(
Topology& topology,
vector<edgeid_set_ptr>* index,
int faceId,
int edgeId
)
: TopologyTransaction(topology)
, _index(index)
, _faceId(faceId)
, _edgeId(edgeId)
{
}
RemoveFaceIndexTransaction::~RemoveFaceIndexTransaction()
{
}
void RemoveFaceIndexTransaction::rollback()
{
(*_index)[_faceId]->insert(_edgeId);
// invalidate face geometry cache
if ((*_topology._face_geometries)[_faceId]) {
GEOSGeom_destroy_r(hdl, (*_topology._face_geometries)[_faceId]);
(*_topology._face_geometries)[_faceId] = nullptr;
}
}
AddRelationTransaction::AddRelationTransaction(Topology& topology, relation* r)
: TopologyTransaction(topology)
, _relation(r)
{
assert (_relation);
}
AddRelationTransaction::~AddRelationTransaction()
{
}
void AddRelationTransaction::rollback()
{
int topogeoId = _relation->topogeo_id;
assert (topogeoId < _topology._relations.size());
assert (_topology._relations[topogeoId]);
vector<relation*>* relations = _topology._relations[topogeoId];
auto it = find(relations->begin(), relations->end(), _relation);
assert (it != relations->end());
delete *it;
relations->erase(it);
if (relations->empty()) {
delete relations;
_topology._relations[topogeoId] = nullptr;
}
}
} // namespace cma