Line data Source code
1 : /* File: ctrl_undo_redo_entry.inl; Copyright and License: see below */
2 :
3 : #include "entity/data_feature_type.h"
4 : #include <assert.h>
5 :
6 872 : static inline void ctrl_undo_redo_entry_init_empty ( ctrl_undo_redo_entry_t *this_ )
7 : {
8 872 : (*this_).action_type = CTRL_UNDO_REDO_ENTRY_TYPE_BOUNDARY;
9 872 : (*this_).data_before_action.boundary_revision = DATA_REVISION_VOID;
10 872 : (*this_).data_after_action.boundary_revision = DATA_REVISION_VOID;
11 872 : }
12 :
13 929 : static inline void ctrl_undo_redo_entry_destroy ( ctrl_undo_redo_entry_t *this_ )
14 : {
15 929 : }
16 :
17 : /* ================================ BOUNDARY ================================ */
18 :
19 541 : static inline void ctrl_undo_redo_entry_init_boundary ( ctrl_undo_redo_entry_t *this_, data_revision_t boundary_revision )
20 : {
21 541 : (*this_).action_type = CTRL_UNDO_REDO_ENTRY_TYPE_BOUNDARY;
22 541 : (*this_).data_before_action.boundary_revision = DATA_REVISION_VOID; /* unused */
23 541 : (*this_).data_after_action.boundary_revision = boundary_revision;
24 541 : }
25 :
26 155 : static inline data_revision_t ctrl_undo_redo_entry_get_boundary_revision ( const ctrl_undo_redo_entry_t *this_ )
27 : {
28 155 : return (*this_).data_after_action.boundary_revision;
29 : }
30 :
31 : /* ================================ DIAGRAM ================================ */
32 :
33 184 : static inline void ctrl_undo_redo_entry_init_create_diagram ( ctrl_undo_redo_entry_t *this_,
34 : const data_diagram_t *data_after )
35 : {
36 184 : (*this_).action_type = CTRL_UNDO_REDO_ENTRY_TYPE_CREATE_DIAGRAM;
37 184 : data_diagram_init_empty( &((*this_).data_before_action.diagram) );
38 184 : data_diagram_replace( &((*this_).data_after_action.diagram), data_after );
39 184 : }
40 :
41 13 : static inline void ctrl_undo_redo_entry_init_update_diagram ( ctrl_undo_redo_entry_t *this_,
42 : const data_diagram_t *data_before,
43 : const data_diagram_t *data_after )
44 : {
45 13 : (*this_).action_type = CTRL_UNDO_REDO_ENTRY_TYPE_UPDATE_DIAGRAM;
46 13 : data_diagram_replace( &((*this_).data_before_action.diagram), data_before );
47 13 : data_diagram_replace( &((*this_).data_after_action.diagram), data_after );
48 13 : }
49 :
50 2 : static inline void ctrl_undo_redo_entry_init_delete_diagram ( ctrl_undo_redo_entry_t *this_,
51 : const data_diagram_t *data_before )
52 : {
53 2 : (*this_).action_type = CTRL_UNDO_REDO_ENTRY_TYPE_DELETE_DIAGRAM;
54 2 : data_diagram_replace( &((*this_).data_before_action.diagram), data_before );
55 2 : data_diagram_init_empty( &((*this_).data_after_action.diagram) );
56 2 : }
57 :
58 136 : static inline const data_diagram_t *ctrl_undo_redo_entry_get_diagram_after_action_const ( const ctrl_undo_redo_entry_t *this_ )
59 : {
60 136 : return &((*this_).data_after_action.diagram);
61 : }
62 :
63 2 : static inline const data_diagram_t *ctrl_undo_redo_entry_get_diagram_before_action_const ( const ctrl_undo_redo_entry_t *this_ )
64 : {
65 2 : return &((*this_).data_before_action.diagram);
66 : }
67 :
68 : /* ================================ DIAGRAMELEMENT ================================ */
69 :
70 62 : static inline void ctrl_undo_redo_entry_init_create_diagramelement ( ctrl_undo_redo_entry_t *this_,
71 : const data_diagramelement_t *data_after )
72 : {
73 62 : (*this_).action_type = CTRL_UNDO_REDO_ENTRY_TYPE_CREATE_DIAGRAMELEMENT;
74 62 : data_diagramelement_init_empty( &((*this_).data_before_action.diagramelement) );
75 62 : data_diagramelement_replace( &((*this_).data_after_action.diagramelement), data_after );
76 62 : }
77 :
78 23 : static inline void ctrl_undo_redo_entry_init_update_diagramelement ( ctrl_undo_redo_entry_t *this_,
79 : const data_diagramelement_t *data_before,
80 : const data_diagramelement_t *data_after )
81 : {
82 23 : (*this_).action_type = CTRL_UNDO_REDO_ENTRY_TYPE_UPDATE_DIAGRAMELEMENT;
83 23 : data_diagramelement_replace( &((*this_).data_before_action.diagramelement), data_before );
84 23 : data_diagramelement_replace( &((*this_).data_after_action.diagramelement), data_after );
85 23 : }
86 :
87 9 : static inline void ctrl_undo_redo_entry_init_delete_diagramelement ( ctrl_undo_redo_entry_t *this_,
88 : const data_diagramelement_t *data_before )
89 : {
90 9 : (*this_).action_type = CTRL_UNDO_REDO_ENTRY_TYPE_DELETE_DIAGRAMELEMENT;
91 9 : data_diagramelement_replace( &((*this_).data_before_action.diagramelement), data_before );
92 9 : data_diagramelement_init_empty( &((*this_).data_after_action.diagramelement) );
93 9 : }
94 :
95 4 : static inline const data_diagramelement_t *ctrl_undo_redo_entry_get_diagramelement_after_action_const ( const ctrl_undo_redo_entry_t *this_ )
96 : {
97 4 : return &((*this_).data_after_action.diagramelement);
98 : }
99 :
100 3 : static inline const data_diagramelement_t *ctrl_undo_redo_entry_get_diagramelement_before_action_const ( const ctrl_undo_redo_entry_t *this_ )
101 : {
102 3 : return &((*this_).data_before_action.diagramelement);
103 : }
104 :
105 : /* ================================ CLASSIFIER ================================ */
106 :
107 40 : static inline void ctrl_undo_redo_entry_init_create_classifier ( ctrl_undo_redo_entry_t *this_ ,
108 : const data_classifier_t *data_after )
109 : {
110 40 : (*this_).action_type = CTRL_UNDO_REDO_ENTRY_TYPE_CREATE_CLASSIFIER;
111 40 : data_classifier_init_empty( &((*this_).data_before_action.classifier) );
112 40 : data_classifier_replace( &((*this_).data_after_action.classifier), data_after );
113 40 : }
114 :
115 7 : static inline void ctrl_undo_redo_entry_init_update_classifier ( ctrl_undo_redo_entry_t *this_ ,
116 : const data_classifier_t *data_before,
117 : const data_classifier_t *data_after )
118 : {
119 7 : (*this_).action_type = CTRL_UNDO_REDO_ENTRY_TYPE_UPDATE_CLASSIFIER;
120 7 : data_classifier_replace( &((*this_).data_before_action.classifier), data_before );
121 7 : data_classifier_replace( &((*this_).data_after_action.classifier), data_after );
122 7 : }
123 :
124 3 : static inline void ctrl_undo_redo_entry_init_delete_classifier ( ctrl_undo_redo_entry_t *this_ ,
125 : const data_classifier_t *data_before )
126 : {
127 3 : (*this_).action_type = CTRL_UNDO_REDO_ENTRY_TYPE_DELETE_CLASSIFIER;
128 3 : data_classifier_replace( &((*this_).data_before_action.classifier), data_before );
129 3 : data_classifier_init_empty( &((*this_).data_after_action.classifier) );
130 3 : }
131 :
132 : static inline data_classifier_t *ctrl_undo_redo_entry_get_classifier_before_action_ptr ( ctrl_undo_redo_entry_t *this_ )
133 : {
134 : return &((*this_).data_before_action.classifier);
135 : }
136 :
137 : static inline data_classifier_t *ctrl_undo_redo_entry_get_classifier_after_action_ptr ( ctrl_undo_redo_entry_t *this_ )
138 : {
139 : return &((*this_).data_after_action.classifier);
140 : }
141 :
142 3 : static inline const data_classifier_t *ctrl_undo_redo_entry_get_classifier_after_action_const ( const ctrl_undo_redo_entry_t *this_ )
143 : {
144 3 : return &((*this_).data_after_action.classifier);
145 : }
146 :
147 1 : static inline const data_classifier_t *ctrl_undo_redo_entry_get_classifier_before_action_const ( const ctrl_undo_redo_entry_t *this_ )
148 : {
149 1 : return &((*this_).data_before_action.classifier);
150 : }
151 :
152 : /* ================================ FEATURE ================================ */
153 :
154 39 : static inline void ctrl_undo_redo_entry_init_create_feature ( ctrl_undo_redo_entry_t *this_,
155 : const data_feature_t *data_after )
156 : {
157 39 : (*this_).action_type = CTRL_UNDO_REDO_ENTRY_TYPE_CREATE_FEATURE;
158 39 : data_feature_init_empty( &((*this_).data_before_action.feature) );
159 39 : data_feature_replace( &((*this_).data_after_action.feature), data_after );
160 39 : }
161 :
162 7 : static inline void ctrl_undo_redo_entry_init_update_feature ( ctrl_undo_redo_entry_t *this_,
163 : const data_feature_t *data_before,
164 : const data_feature_t *data_after )
165 : {
166 7 : (*this_).action_type = CTRL_UNDO_REDO_ENTRY_TYPE_UPDATE_FEATURE;
167 7 : data_feature_replace( &((*this_).data_before_action.feature), data_before );
168 7 : data_feature_replace( &((*this_).data_after_action.feature), data_after );
169 7 : }
170 :
171 15 : static inline void ctrl_undo_redo_entry_init_delete_feature ( ctrl_undo_redo_entry_t *this_,
172 : const data_feature_t *data_before )
173 : {
174 15 : (*this_).action_type = CTRL_UNDO_REDO_ENTRY_TYPE_DELETE_FEATURE;
175 15 : data_feature_replace( &((*this_).data_before_action.feature), data_before );
176 15 : data_feature_init_empty( &((*this_).data_after_action.feature) );
177 15 : }
178 :
179 4 : static inline const data_feature_t *ctrl_undo_redo_entry_get_feature_after_action_const ( const ctrl_undo_redo_entry_t *this_ )
180 : {
181 4 : return &((*this_).data_after_action.feature);
182 : }
183 :
184 5 : static inline const data_feature_t *ctrl_undo_redo_entry_get_feature_before_action_const ( const ctrl_undo_redo_entry_t *this_ )
185 : {
186 5 : return &((*this_).data_before_action.feature);
187 : }
188 :
189 : /* ================================ RELATIONSHIP ================================ */
190 :
191 19 : static inline void ctrl_undo_redo_entry_init_create_relationship ( ctrl_undo_redo_entry_t *this_,
192 : const data_relationship_t *data_after )
193 : {
194 19 : (*this_).action_type = CTRL_UNDO_REDO_ENTRY_TYPE_CREATE_RELATIONSHIP;
195 19 : data_relationship_init_empty( &((*this_).data_before_action.relationship) );
196 19 : data_relationship_replace( &((*this_).data_after_action.relationship), data_after );
197 19 : }
198 :
199 6 : static inline void ctrl_undo_redo_entry_init_update_relationship ( ctrl_undo_redo_entry_t *this_,
200 : const data_relationship_t *data_before,
201 : const data_relationship_t *data_after )
202 : {
203 6 : (*this_).action_type = CTRL_UNDO_REDO_ENTRY_TYPE_UPDATE_RELATIONSHIP;
204 6 : data_relationship_replace( &((*this_).data_before_action.relationship), data_before );
205 6 : data_relationship_replace( &((*this_).data_after_action.relationship), data_after );
206 6 : }
207 :
208 8 : static inline void ctrl_undo_redo_entry_init_delete_relationship ( ctrl_undo_redo_entry_t *this_,
209 : const data_relationship_t *data_before )
210 : {
211 8 : (*this_).action_type = CTRL_UNDO_REDO_ENTRY_TYPE_DELETE_RELATIONSHIP;
212 8 : data_relationship_replace( &((*this_).data_before_action.relationship), data_before );
213 8 : data_relationship_init_empty( &((*this_).data_after_action.relationship) );
214 8 : }
215 :
216 3 : static inline const data_relationship_t *ctrl_undo_redo_entry_get_relationship_after_action_const ( const ctrl_undo_redo_entry_t *this_ )
217 : {
218 3 : return &((*this_).data_after_action.relationship);
219 : }
220 :
221 3 : static inline const data_relationship_t *ctrl_undo_redo_entry_get_relationship_before_action_const ( const ctrl_undo_redo_entry_t *this_ )
222 : {
223 3 : return &((*this_).data_before_action.relationship);
224 : }
225 :
226 : /* ================================ ENTRY_TYPE ================================ */
227 :
228 38052 : static inline ctrl_undo_redo_entry_type_t ctrl_undo_redo_entry_get_action_type ( const ctrl_undo_redo_entry_t *this_ )
229 : {
230 38052 : return (*this_).action_type;
231 : }
232 :
233 : /* ================================ STATISTICS ================================ */
234 :
235 167 : static inline void ctrl_undo_redo_entry_to_statistics ( const ctrl_undo_redo_entry_t *this_, bool undo, bool err, data_stat_t *io_stat )
236 : {
237 167 : assert( NULL != io_stat );
238 :
239 167 : data_stat_table_t table = DATA_STAT_TABLE_LIFELINE;
240 167 : data_stat_series_t series = DATA_STAT_SERIES_ERROR;
241 167 : switch( (*this_).action_type )
242 : {
243 0 : case CTRL_UNDO_REDO_ENTRY_TYPE_DELETE_DIAGRAM:
244 : {
245 0 : table = DATA_STAT_TABLE_DIAGRAM;
246 0 : series = undo ? DATA_STAT_SERIES_CREATED : DATA_STAT_SERIES_DELETED;
247 : }
248 0 : break;
249 :
250 5 : case CTRL_UNDO_REDO_ENTRY_TYPE_UPDATE_DIAGRAM:
251 : {
252 5 : table = DATA_STAT_TABLE_DIAGRAM;
253 5 : series = DATA_STAT_SERIES_MODIFIED;
254 : }
255 5 : break;
256 :
257 134 : case CTRL_UNDO_REDO_ENTRY_TYPE_CREATE_DIAGRAM:
258 : {
259 134 : table = DATA_STAT_TABLE_DIAGRAM;
260 134 : series = undo ? DATA_STAT_SERIES_DELETED : DATA_STAT_SERIES_CREATED;
261 : }
262 134 : break;
263 :
264 1 : case CTRL_UNDO_REDO_ENTRY_TYPE_DELETE_DIAGRAMELEMENT:
265 : {
266 1 : table = DATA_STAT_TABLE_DIAGRAMELEMENT;
267 1 : series = undo ? DATA_STAT_SERIES_CREATED : DATA_STAT_SERIES_DELETED;
268 : }
269 1 : break;
270 :
271 5 : case CTRL_UNDO_REDO_ENTRY_TYPE_UPDATE_DIAGRAMELEMENT:
272 : {
273 5 : table = DATA_STAT_TABLE_DIAGRAMELEMENT;
274 5 : series = DATA_STAT_SERIES_MODIFIED;
275 : }
276 5 : break;
277 :
278 2 : case CTRL_UNDO_REDO_ENTRY_TYPE_CREATE_DIAGRAMELEMENT:
279 : {
280 2 : table = DATA_STAT_TABLE_DIAGRAMELEMENT;
281 2 : series = undo ? DATA_STAT_SERIES_DELETED : DATA_STAT_SERIES_CREATED;
282 : }
283 2 : break;
284 :
285 1 : case CTRL_UNDO_REDO_ENTRY_TYPE_DELETE_CLASSIFIER:
286 : {
287 1 : table = DATA_STAT_TABLE_CLASSIFIER;
288 1 : series = undo ? DATA_STAT_SERIES_CREATED : DATA_STAT_SERIES_DELETED;
289 : }
290 1 : break;
291 :
292 2 : case CTRL_UNDO_REDO_ENTRY_TYPE_UPDATE_CLASSIFIER:
293 : {
294 2 : table = DATA_STAT_TABLE_CLASSIFIER;
295 2 : series = DATA_STAT_SERIES_MODIFIED;
296 : }
297 2 : break;
298 :
299 2 : case CTRL_UNDO_REDO_ENTRY_TYPE_CREATE_CLASSIFIER:
300 : {
301 2 : table = DATA_STAT_TABLE_CLASSIFIER;
302 2 : series = undo ? DATA_STAT_SERIES_DELETED : DATA_STAT_SERIES_CREATED;
303 : }
304 2 : break;
305 :
306 3 : case CTRL_UNDO_REDO_ENTRY_TYPE_DELETE_FEATURE:
307 : {
308 3 : const data_feature_t *const old_feat = &((*this_).data_before_action.feature);
309 3 : const data_feature_type_t feat_type = data_feature_get_main_type( old_feat );
310 3 : table = (feat_type == DATA_FEATURE_TYPE_LIFELINE) ? DATA_STAT_TABLE_LIFELINE : DATA_STAT_TABLE_FEATURE;
311 3 : series = undo ? DATA_STAT_SERIES_CREATED : DATA_STAT_SERIES_DELETED;
312 : }
313 3 : break;
314 :
315 4 : case CTRL_UNDO_REDO_ENTRY_TYPE_UPDATE_FEATURE:
316 : {
317 4 : const data_feature_t *const old_feat = &((*this_).data_before_action.feature);
318 4 : const data_feature_type_t feat_type = data_feature_get_main_type( old_feat );
319 4 : table = (feat_type == DATA_FEATURE_TYPE_LIFELINE) ? DATA_STAT_TABLE_LIFELINE : DATA_STAT_TABLE_FEATURE;
320 4 : series = DATA_STAT_SERIES_MODIFIED;
321 : }
322 4 : break;
323 :
324 2 : case CTRL_UNDO_REDO_ENTRY_TYPE_CREATE_FEATURE:
325 : {
326 2 : const data_feature_t *const new_feat = &((*this_).data_after_action.feature);
327 2 : const data_feature_type_t feat_type = data_feature_get_main_type( new_feat );
328 2 : table = (feat_type == DATA_FEATURE_TYPE_LIFELINE) ? DATA_STAT_TABLE_LIFELINE : DATA_STAT_TABLE_FEATURE;
329 2 : series = undo ? DATA_STAT_SERIES_DELETED : DATA_STAT_SERIES_CREATED;
330 : }
331 2 : break;
332 :
333 2 : case CTRL_UNDO_REDO_ENTRY_TYPE_DELETE_RELATIONSHIP:
334 : {
335 2 : table = DATA_STAT_TABLE_RELATIONSHIP;
336 2 : series = undo ? DATA_STAT_SERIES_CREATED : DATA_STAT_SERIES_DELETED;
337 : }
338 2 : break;
339 :
340 2 : case CTRL_UNDO_REDO_ENTRY_TYPE_UPDATE_RELATIONSHIP:
341 : {
342 2 : table = DATA_STAT_TABLE_RELATIONSHIP;
343 2 : series = DATA_STAT_SERIES_MODIFIED;
344 : }
345 2 : break;
346 :
347 2 : case CTRL_UNDO_REDO_ENTRY_TYPE_CREATE_RELATIONSHIP:
348 : {
349 2 : table = DATA_STAT_TABLE_RELATIONSHIP;
350 2 : series = undo ? DATA_STAT_SERIES_DELETED : DATA_STAT_SERIES_CREATED;
351 : }
352 2 : break;
353 :
354 0 : case CTRL_UNDO_REDO_ENTRY_TYPE_BOUNDARY:
355 : {
356 : /* nothing to count */
357 : }
358 0 : break;
359 :
360 0 : default :
361 : {
362 : /* internal error, switch-case statement incomplete */
363 0 : U8_LOG_ERROR("incomplete switch statement in ctrl_undo_redo_entry_to_statistics");
364 : }
365 0 : break;
366 : }
367 :
368 167 : data_stat_inc_count ( io_stat, table, (err ? DATA_STAT_SERIES_ERROR : series) );
369 167 : }
370 :
371 :
372 : /*
373 : Copyright 2016-2026 Andreas Warnke
374 :
375 : Licensed under the Apache License, Version 2.0 (the "License");
376 : you may not use this file except in compliance with the License.
377 : You may obtain a copy of the License at
378 :
379 : http://www.apache.org/licenses/LICENSE-2.0
380 :
381 : Unless required by applicable law or agreed to in writing, software
382 : distributed under the License is distributed on an "AS IS" BASIS,
383 : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
384 : See the License for the specific language governing permissions and
385 : limitations under the License.
386 : */
|