Line data Source code
1 : /* File: ctrl_undo_redo_list.c; Copyright and License: see below */
2 :
3 : #include "ctrl_undo_redo_list.h"
4 : #include "u8/u8_trace.h"
5 : #include "u8/u8_log.h"
6 : #include <assert.h>
7 :
8 104 : u8_error_t ctrl_undo_redo_list_remove_boundary_from_end ( ctrl_undo_redo_list_t *this_ )
9 : {
10 104 : assert( (*this_).start < CTRL_UNDO_REDO_LIST_MAX_SIZE );
11 104 : assert( (*this_).length <= CTRL_UNDO_REDO_LIST_MAX_SIZE );
12 104 : assert( (*this_).current <= (*this_).length );
13 :
14 104 : u8_error_t result = U8_ERROR_NONE;
15 : ctrl_undo_redo_entry_t *boundary_entry;
16 :
17 104 : if ( (*this_).current == 0 )
18 : {
19 : /* there is no entry - therefore no boundary - to be removed */
20 0 : result = U8_ERROR_INVALID_REQUEST;
21 : }
22 : else
23 : {
24 : /* check if current is a boundary */
25 : uint32_t index;
26 : ctrl_undo_redo_entry_type_t action;
27 :
28 104 : index = ((*this_).start + (*this_).current + (CTRL_UNDO_REDO_LIST_MAX_SIZE-1)) % CTRL_UNDO_REDO_LIST_MAX_SIZE;
29 104 : boundary_entry = &((*this_).buffer[index]);
30 104 : action = ctrl_undo_redo_entry_get_action_type ( boundary_entry );
31 104 : if ( CTRL_UNDO_REDO_ENTRY_TYPE_BOUNDARY != action )
32 : {
33 : /* current is not a boundary */
34 0 : result = U8_ERROR_INVALID_REQUEST;
35 : }
36 : else
37 : {
38 : /* drop all list-entries newer than the current position */
39 104 : if ( (*this_).current < (*this_).length )
40 : {
41 : /* call destructor of all later entries */
42 0 : for ( uint32_t pos = (*this_).current; pos < (*this_).length; pos ++ )
43 : {
44 0 : uint32_t del_index = ((*this_).start + pos) % CTRL_UNDO_REDO_LIST_MAX_SIZE;
45 0 : ctrl_undo_redo_entry_destroy( &((*this_).buffer[del_index]) );
46 : }
47 :
48 : /* shrink the list */
49 0 : (*this_).length = (*this_).current;
50 : }
51 :
52 : /* call destructor of boundary and remove it */
53 104 : ctrl_undo_redo_entry_destroy( boundary_entry );
54 :
55 : /* remove the boundary */
56 104 : (*this_).length --;
57 104 : (*this_).current --;
58 : }
59 : }
60 :
61 104 : return result;
62 : }
63 :
64 146 : u8_error_t ctrl_undo_redo_list_undo ( ctrl_undo_redo_list_t *this_, data_stat_t *io_stat )
65 : {
66 146 : U8_TRACE_BEGIN();
67 146 : assert ( NULL != io_stat );
68 :
69 146 : u8_error_t result = U8_ERROR_NONE;
70 :
71 146 : if ( 2 > ctrl_undo_redo_list_private_count_boundaries( this_, (*this_).start, (*this_).current ) )
72 : {
73 4 : if ( (*this_).buffer_incomplete )
74 : {
75 2 : result = U8_ERROR_ARRAY_BUFFER_EXCEEDED;
76 : }
77 : else
78 : {
79 2 : result = U8_ERROR_INVALID_REQUEST;
80 : }
81 : }
82 : else
83 : {
84 142 : bool finished = false;
85 431 : for ( uint32_t pos = 0; (pos < CTRL_UNDO_REDO_LIST_MAX_SIZE) && (! finished); pos ++ )
86 : {
87 : /* move the current pointer back in the list */
88 289 : (*this_).current --;
89 :
90 : /* check if we are done */
91 289 : const uint32_t index
92 289 : = ((*this_).start + (*this_).current + (CTRL_UNDO_REDO_LIST_MAX_SIZE-1)) % CTRL_UNDO_REDO_LIST_MAX_SIZE;
93 289 : ctrl_undo_redo_entry_t *const cur_entry = &((*this_).buffer[index]);
94 :
95 289 : if ( CTRL_UNDO_REDO_ENTRY_TYPE_BOUNDARY == ctrl_undo_redo_entry_get_action_type( cur_entry ) )
96 : {
97 142 : U8_TRACE_INFO("boundary");
98 142 : finished = true;
99 : }
100 : else
101 : {
102 147 : U8_TRACE_INFO("undo");
103 147 : const uint32_t current_before = (*this_).current;
104 147 : const u8_error_t cur_err = ctrl_undo_redo_list_private_do_action( this_, cur_entry, true );
105 147 : ctrl_undo_redo_entry_to_statistics ( cur_entry, true /*=undo*/, (U8_ERROR_NONE!=cur_err), io_stat );
106 147 : result |= cur_err;
107 147 : if ( (*this_).current != current_before )
108 : {
109 0 : U8_LOG_ERROR("ctrl_undo_redo_list_t was modified while performing undo.");
110 : /* try to continue undo, this is the most likely way to get the db back to a consistent state */
111 : }
112 : }
113 : }
114 : }
115 :
116 146 : U8_TRACE_INFO_INT_INT( "current, length:", (*this_).current, (*this_).length );
117 :
118 146 : U8_TRACE_END_ERR( result );
119 146 : return result;
120 : }
121 :
122 16 : u8_error_t ctrl_undo_redo_list_redo ( ctrl_undo_redo_list_t *this_, data_stat_t *io_stat )
123 : {
124 16 : U8_TRACE_BEGIN();
125 16 : assert ( NULL != io_stat );
126 :
127 16 : u8_error_t result = U8_ERROR_NONE;
128 :
129 16 : if ( (*this_).current == (*this_).length )
130 : {
131 : /* current points already to the end of the list - no redo possible */
132 3 : result = U8_ERROR_INVALID_REQUEST;
133 : }
134 : else
135 : {
136 13 : bool finished = false;
137 : ;
138 43 : for ( uint32_t pos = 0; (pos < CTRL_UNDO_REDO_LIST_MAX_SIZE) && (! finished); pos ++ )
139 : {
140 : /* move the current pointer forward in the list */
141 30 : (*this_).current ++;
142 :
143 : /* check if we are done */
144 30 : const uint32_t index
145 30 : = ((*this_).start + (*this_).current + (CTRL_UNDO_REDO_LIST_MAX_SIZE-1)) % CTRL_UNDO_REDO_LIST_MAX_SIZE;
146 30 : ctrl_undo_redo_entry_t *const cur_entry = &((*this_).buffer[index]);
147 :
148 30 : if ( CTRL_UNDO_REDO_ENTRY_TYPE_BOUNDARY == ctrl_undo_redo_entry_get_action_type( cur_entry ) )
149 : {
150 13 : U8_TRACE_INFO("boundary");
151 13 : finished = true;
152 : }
153 17 : else if ( (*this_).current == (*this_).length )
154 : {
155 0 : U8_TRACE_INFO("boundary");
156 0 : finished = true;
157 : }
158 30 : if ( ! finished )
159 : {
160 17 : U8_TRACE_INFO("redo");
161 17 : const uint32_t current_before = (*this_).current;
162 17 : const u8_error_t cur_err = ctrl_undo_redo_list_private_do_action( this_, cur_entry, false );
163 17 : ctrl_undo_redo_entry_to_statistics ( cur_entry, false /*=undo*/, (U8_ERROR_NONE!=cur_err), io_stat );
164 17 : result |= cur_err;
165 17 : if ( (*this_).current != current_before )
166 : {
167 0 : U8_LOG_ERROR("ctrl_undo_redo_list_t was modified while performing redo.");
168 0 : result |= U8_ERROR_INVALID_REQUEST;
169 0 : finished = true;
170 : }
171 : }
172 : }
173 : }
174 :
175 16 : U8_TRACE_INFO_INT_INT( "current, length:", (*this_).current, (*this_).length );
176 :
177 16 : U8_TRACE_END_ERR( result );
178 16 : return result;
179 : }
180 :
181 : /* ================================ private ================================ */
182 :
183 682 : ctrl_undo_redo_entry_t *ctrl_undo_redo_list_private_add_entry_ptr ( ctrl_undo_redo_list_t *this_ )
184 : {
185 682 : U8_TRACE_BEGIN();
186 682 : assert( (*this_).start < CTRL_UNDO_REDO_LIST_MAX_SIZE );
187 682 : assert( (*this_).length <= CTRL_UNDO_REDO_LIST_MAX_SIZE );
188 682 : assert( (*this_).current <= (*this_).length );
189 :
190 : uint32_t index;
191 : ctrl_undo_redo_entry_t *result;
192 :
193 682 : if ( (*this_).current < (*this_).length )
194 : {
195 : /* overwrite an existing and new entry */
196 : /* (*this_).start stays untouched */
197 1 : (*this_).current ++;
198 :
199 : /* call destructor of all later entries */
200 252 : for ( uint32_t pos = (*this_).current; pos < (*this_).length; pos ++ )
201 : {
202 251 : uint32_t del_index = ((*this_).start + pos) % CTRL_UNDO_REDO_LIST_MAX_SIZE;
203 251 : ctrl_undo_redo_entry_destroy( &((*this_).buffer[del_index]) );
204 : }
205 :
206 : /* shrink the list */
207 1 : (*this_).length = (*this_).current;
208 :
209 1 : index = ((*this_).start + (*this_).current + (CTRL_UNDO_REDO_LIST_MAX_SIZE-1)) % CTRL_UNDO_REDO_LIST_MAX_SIZE;
210 1 : result = &((*this_).buffer[index]);
211 : }
212 681 : else if ( (*this_).current < CTRL_UNDO_REDO_LIST_MAX_SIZE )
213 : {
214 : /* add a new entry */
215 : /* (*this_).start stays untouched */
216 680 : (*this_).current ++;
217 680 : (*this_).length ++;
218 :
219 : /* call the constructor */
220 680 : index = ((*this_).start + (*this_).current + (CTRL_UNDO_REDO_LIST_MAX_SIZE-1)) % CTRL_UNDO_REDO_LIST_MAX_SIZE;
221 680 : result = &((*this_).buffer[index]);
222 680 : ctrl_undo_redo_entry_init_empty( result );
223 : }
224 : else
225 : {
226 : /* overwrite an existing old entry */
227 1 : (*this_).start = ((*this_).start+1) % CTRL_UNDO_REDO_LIST_MAX_SIZE;
228 : /* (*this_).current is already CTRL_UNDO_REDO_LIST_MAX_SIZE */
229 : /* (*this_).length is already CTRL_UNDO_REDO_LIST_MAX_SIZE */
230 1 : (*this_).buffer_incomplete = true;
231 :
232 1 : index = ((*this_).start + (*this_).current + (CTRL_UNDO_REDO_LIST_MAX_SIZE-1)) % CTRL_UNDO_REDO_LIST_MAX_SIZE;
233 1 : result = &((*this_).buffer[index]);
234 : }
235 :
236 682 : U8_TRACE_INFO_INT_INT( "current, length:", (*this_).current, (*this_).length );
237 :
238 682 : U8_TRACE_END();
239 682 : return result;
240 : }
241 :
242 164 : u8_error_t ctrl_undo_redo_list_private_do_action ( ctrl_undo_redo_list_t *this_, ctrl_undo_redo_entry_t *action, bool undo )
243 : {
244 164 : U8_TRACE_BEGIN();
245 :
246 164 : u8_error_t result = U8_ERROR_NONE;
247 :
248 164 : switch ( ctrl_undo_redo_entry_get_action_type( action ) )
249 : {
250 0 : case CTRL_UNDO_REDO_ENTRY_TYPE_DELETE_DIAGRAM:
251 : {
252 0 : U8_TRACE_INFO( "CTRL_UNDO_REDO_ENTRY_TYPE_DELETE_DIAGRAM" );
253 0 : data_diagram_t *diag = ctrl_undo_redo_entry_get_diagram_before_action_ptr ( action );
254 0 : if ( undo )
255 : {
256 0 : result |= (u8_error_t) data_database_writer_create_diagram ( (*this_).db_writer, diag, NULL );
257 : }
258 : else
259 : {
260 0 : data_row_id_t obj_id = data_diagram_get_row_id ( diag );
261 0 : result |= (u8_error_t) data_database_writer_delete_diagram ( (*this_).db_writer, obj_id, NULL );
262 : }
263 : }
264 0 : break;
265 :
266 4 : case CTRL_UNDO_REDO_ENTRY_TYPE_UPDATE_DIAGRAM:
267 : {
268 4 : U8_TRACE_INFO( "CTRL_UNDO_REDO_ENTRY_TYPE_UPDATE_DIAGRAM" );
269 : data_diagram_t *diag;
270 4 : if ( undo )
271 : {
272 2 : diag = ctrl_undo_redo_entry_get_diagram_before_action_ptr ( action );
273 : }
274 : else
275 : {
276 2 : diag = ctrl_undo_redo_entry_get_diagram_after_action_ptr ( action );
277 : }
278 4 : data_row_id_t diag_id = data_diagram_get_row_id ( diag );
279 4 : data_row_id_t diag_parent_id = data_diagram_get_parent_row_id ( diag );
280 4 : data_diagram_type_t diag_type = data_diagram_get_diagram_type ( diag );
281 4 : const char* diag_stereotype = data_diagram_get_stereotype_const ( diag );
282 4 : const char* diag_name = data_diagram_get_name_const ( diag );
283 4 : const char* diag_description = data_diagram_get_description_const ( diag );
284 4 : int32_t diag_list_oder = data_diagram_get_list_order ( diag );
285 4 : result |= (u8_error_t) data_database_writer_update_diagram_parent_id ( (*this_).db_writer, diag_id, diag_parent_id, NULL );
286 4 : result |= (u8_error_t) data_database_writer_update_diagram_type ( (*this_).db_writer, diag_id, diag_type, NULL );
287 4 : result |= (u8_error_t) data_database_writer_update_diagram_stereotype ( (*this_).db_writer, diag_id, diag_stereotype, NULL );
288 4 : result |= (u8_error_t) data_database_writer_update_diagram_name ( (*this_).db_writer, diag_id, diag_name, NULL );
289 4 : result |= (u8_error_t) data_database_writer_update_diagram_description ( (*this_).db_writer, diag_id, diag_description, NULL );
290 4 : result |= (u8_error_t) data_database_writer_update_diagram_list_order ( (*this_).db_writer, diag_id, diag_list_oder, NULL );
291 : }
292 4 : break;
293 :
294 134 : case CTRL_UNDO_REDO_ENTRY_TYPE_CREATE_DIAGRAM:
295 : {
296 134 : U8_TRACE_INFO( "CTRL_UNDO_REDO_ENTRY_TYPE_CREATE_DIAGRAM" );
297 134 : data_diagram_t *diag = ctrl_undo_redo_entry_get_diagram_after_action_ptr ( action );
298 134 : if ( undo )
299 : {
300 131 : data_row_id_t obj_id = data_diagram_get_row_id ( diag );
301 131 : result |= (u8_error_t) data_database_writer_delete_diagram ( (*this_).db_writer, obj_id, NULL );
302 : }
303 : else
304 : {
305 3 : result |= (u8_error_t) data_database_writer_create_diagram ( (*this_).db_writer, diag, NULL );
306 : }
307 : }
308 134 : break;
309 :
310 0 : case CTRL_UNDO_REDO_ENTRY_TYPE_DELETE_DIAGRAMELEMENT:
311 : {
312 0 : U8_TRACE_INFO( "CTRL_UNDO_REDO_ENTRY_TYPE_DELETE_DIAGRAMELEMENT" );
313 0 : data_diagramelement_t *diag_ele = ctrl_undo_redo_entry_get_diagramelement_before_action_ptr ( action );
314 0 : if ( undo )
315 : {
316 0 : result |= (u8_error_t) data_database_writer_create_diagramelement ( (*this_).db_writer, diag_ele, NULL );
317 : }
318 : else
319 : {
320 0 : data_row_id_t obj_id = data_diagramelement_get_row_id ( diag_ele );
321 0 : result |= (u8_error_t) data_database_writer_delete_diagramelement ( (*this_).db_writer, obj_id, NULL );
322 : }
323 : }
324 0 : break;
325 :
326 5 : case CTRL_UNDO_REDO_ENTRY_TYPE_UPDATE_DIAGRAMELEMENT:
327 : {
328 5 : U8_TRACE_INFO( "CTRL_UNDO_REDO_ENTRY_TYPE_UPDATE_DIAGRAMELEMENT" );
329 : data_diagramelement_t *diag_element;
330 5 : if ( undo )
331 : {
332 3 : diag_element = ctrl_undo_redo_entry_get_diagramelement_before_action_ptr ( action );
333 : }
334 : else
335 : {
336 2 : diag_element = ctrl_undo_redo_entry_get_diagramelement_after_action_ptr ( action );
337 : }
338 5 : data_row_id_t diag_elem_id = data_diagramelement_get_row_id ( diag_element );
339 5 : data_diagramelement_flag_t diag_elem_display_flags = data_diagramelement_get_display_flags ( diag_element );
340 5 : data_row_id_t diag_feature_id = data_diagramelement_get_focused_feature_row_id ( diag_element );
341 5 : result |= (u8_error_t) data_database_writer_update_diagramelement_display_flags ( (*this_).db_writer, diag_elem_id, diag_elem_display_flags, NULL );
342 5 : result |= (u8_error_t) data_database_writer_update_diagramelement_focused_feature_id ( (*this_).db_writer, diag_elem_id, diag_feature_id, NULL );
343 : }
344 5 : break;
345 :
346 2 : case CTRL_UNDO_REDO_ENTRY_TYPE_CREATE_DIAGRAMELEMENT:
347 : {
348 2 : U8_TRACE_INFO( "CTRL_UNDO_REDO_ENTRY_TYPE_CREATE_DIAGRAMELEMENT" );
349 2 : data_diagramelement_t *diag_ele = ctrl_undo_redo_entry_get_diagramelement_after_action_ptr ( action );
350 2 : if ( undo )
351 : {
352 1 : data_row_id_t obj_id = data_diagramelement_get_row_id ( diag_ele );
353 1 : result |= (u8_error_t) data_database_writer_delete_diagramelement ( (*this_).db_writer, obj_id, NULL );
354 : }
355 : else
356 : {
357 1 : result |= (u8_error_t) data_database_writer_create_diagramelement ( (*this_).db_writer, diag_ele, NULL );
358 : }
359 : }
360 2 : break;
361 :
362 0 : case CTRL_UNDO_REDO_ENTRY_TYPE_DELETE_CLASSIFIER:
363 : {
364 0 : U8_TRACE_INFO( "CTRL_UNDO_REDO_ENTRY_TYPE_DELETE_CLASSIFIER" );
365 0 : data_classifier_t *classfy = ctrl_undo_redo_entry_get_classifier_before_action_ptr ( action );
366 0 : if ( undo )
367 : {
368 0 : result |= (u8_error_t) data_database_writer_create_classifier ( (*this_).db_writer, classfy, NULL );
369 : }
370 : else
371 : {
372 0 : data_row_id_t obj_id = data_classifier_get_row_id ( classfy );
373 0 : result |= (u8_error_t) data_database_writer_delete_classifier ( (*this_).db_writer, obj_id, NULL );
374 : }
375 : }
376 0 : break;
377 :
378 2 : case CTRL_UNDO_REDO_ENTRY_TYPE_UPDATE_CLASSIFIER:
379 : {
380 2 : U8_TRACE_INFO( "CTRL_UNDO_REDO_ENTRY_TYPE_UPDATE_CLASSIFIER" );
381 : data_classifier_t *classfy;
382 2 : if ( undo )
383 : {
384 1 : classfy = ctrl_undo_redo_entry_get_classifier_before_action_ptr ( action );
385 : }
386 : else
387 : {
388 1 : classfy = ctrl_undo_redo_entry_get_classifier_after_action_ptr ( action );
389 : }
390 2 : data_row_id_t classfy_id = data_classifier_get_row_id ( classfy );
391 2 : data_classifier_type_t classfy_main_type = data_classifier_get_main_type ( classfy );
392 2 : const char* classfy_stereotype = data_classifier_get_stereotype_const ( classfy );
393 2 : const char* classfy_name = data_classifier_get_name_const ( classfy );
394 2 : const char* classfy_description = data_classifier_get_description_const ( classfy );
395 2 : int32_t classfy_x_order = data_classifier_get_x_order ( classfy );
396 2 : int32_t classfy_y_order = data_classifier_get_y_order ( classfy );
397 2 : int32_t classfy_list_order = data_classifier_get_list_order ( classfy );
398 2 : result |= (u8_error_t) data_database_writer_update_classifier_main_type ( (*this_).db_writer, classfy_id, classfy_main_type, NULL );
399 2 : result |= (u8_error_t) data_database_writer_update_classifier_stereotype ( (*this_).db_writer, classfy_id, classfy_stereotype, NULL );
400 2 : result |= (u8_error_t) data_database_writer_update_classifier_name ( (*this_).db_writer, classfy_id, classfy_name, NULL );
401 2 : result |= (u8_error_t) data_database_writer_update_classifier_description ( (*this_).db_writer, classfy_id, classfy_description, NULL );
402 2 : result |= (u8_error_t) data_database_writer_update_classifier_x_order ( (*this_).db_writer, classfy_id, classfy_x_order, NULL );
403 2 : result |= (u8_error_t) data_database_writer_update_classifier_y_order ( (*this_).db_writer, classfy_id, classfy_y_order, NULL );
404 2 : result |= (u8_error_t) data_database_writer_update_classifier_list_order ( (*this_).db_writer, classfy_id, classfy_list_order, NULL );
405 : }
406 2 : break;
407 :
408 2 : case CTRL_UNDO_REDO_ENTRY_TYPE_CREATE_CLASSIFIER:
409 : {
410 2 : U8_TRACE_INFO( "CTRL_UNDO_REDO_ENTRY_TYPE_CREATE_CLASSIFIER" );
411 2 : data_classifier_t *classfy = ctrl_undo_redo_entry_get_classifier_after_action_ptr ( action );
412 2 : if ( undo )
413 : {
414 1 : data_row_id_t obj_id = data_classifier_get_row_id ( classfy );
415 1 : result |= (u8_error_t) data_database_writer_delete_classifier ( (*this_).db_writer, obj_id, NULL );
416 : }
417 : else
418 : {
419 1 : result |= (u8_error_t) data_database_writer_create_classifier ( (*this_).db_writer, classfy, NULL );
420 : }
421 : }
422 2 : break;
423 :
424 3 : case CTRL_UNDO_REDO_ENTRY_TYPE_DELETE_FEATURE:
425 : {
426 3 : U8_TRACE_INFO( "CTRL_UNDO_REDO_ENTRY_TYPE_DELETE_FEATURE" );
427 3 : data_feature_t *feat = ctrl_undo_redo_entry_get_feature_before_action_ptr ( action );
428 3 : if ( undo )
429 : {
430 2 : result |= (u8_error_t) data_database_writer_create_feature ( (*this_).db_writer, feat, NULL );
431 : }
432 : else
433 : {
434 1 : data_row_id_t obj_id = data_feature_get_row_id ( feat );
435 1 : result |= (u8_error_t) data_database_writer_delete_feature ( (*this_).db_writer, obj_id, NULL );
436 : }
437 : }
438 3 : break;
439 :
440 4 : case CTRL_UNDO_REDO_ENTRY_TYPE_UPDATE_FEATURE:
441 : {
442 4 : U8_TRACE_INFO( "CTRL_UNDO_REDO_ENTRY_TYPE_UPDATE_FEATURE" );
443 : data_feature_t *feat;
444 4 : if ( undo )
445 : {
446 2 : feat = ctrl_undo_redo_entry_get_feature_before_action_ptr ( action );
447 : }
448 : else
449 : {
450 2 : feat = ctrl_undo_redo_entry_get_feature_after_action_ptr ( action );
451 : }
452 4 : data_row_id_t feature_id = data_feature_get_row_id ( feat );
453 4 : data_feature_type_t new_feature_type = data_feature_get_main_type ( feat );
454 4 : const char* new_feature_key = data_feature_get_key_const ( feat );
455 4 : const char* new_feature_value = data_feature_get_value_const ( feat );
456 4 : const char* new_feature_description = data_feature_get_description_const ( feat );
457 4 : int32_t new_feature_list_order = data_feature_get_list_order ( feat );
458 4 : result |= (u8_error_t) data_database_writer_update_feature_main_type ( (*this_).db_writer, feature_id, new_feature_type, NULL );
459 4 : result |= (u8_error_t) data_database_writer_update_feature_key ( (*this_).db_writer, feature_id, new_feature_key, NULL );
460 4 : result |= (u8_error_t) data_database_writer_update_feature_value ( (*this_).db_writer, feature_id, new_feature_value, NULL );
461 4 : result |= (u8_error_t) data_database_writer_update_feature_description ( (*this_).db_writer, feature_id, new_feature_description, NULL );
462 4 : result |= (u8_error_t) data_database_writer_update_feature_list_order ( (*this_).db_writer, feature_id, new_feature_list_order, NULL );
463 : }
464 4 : break;
465 :
466 2 : case CTRL_UNDO_REDO_ENTRY_TYPE_CREATE_FEATURE:
467 : {
468 2 : U8_TRACE_INFO( "CTRL_UNDO_REDO_ENTRY_TYPE_CREATE_FEATURE" );
469 2 : data_feature_t *feat = ctrl_undo_redo_entry_get_feature_after_action_ptr ( action );
470 2 : if ( undo )
471 : {
472 1 : data_row_id_t obj_id = data_feature_get_row_id ( feat );
473 1 : result |= (u8_error_t) data_database_writer_delete_feature ( (*this_).db_writer, obj_id, NULL );
474 : }
475 : else
476 : {
477 1 : result |= (u8_error_t) data_database_writer_create_feature ( (*this_).db_writer, feat, NULL );
478 : }
479 : }
480 2 : break;
481 :
482 2 : case CTRL_UNDO_REDO_ENTRY_TYPE_DELETE_RELATIONSHIP:
483 : {
484 2 : U8_TRACE_INFO( "CTRL_UNDO_REDO_ENTRY_TYPE_DELETE_RELATIONSHIP" );
485 2 : data_relationship_t *relation = ctrl_undo_redo_entry_get_relationship_before_action_ptr ( action );
486 2 : if ( undo )
487 : {
488 1 : result |= (u8_error_t) data_database_writer_create_relationship ( (*this_).db_writer, relation, NULL );
489 : }
490 : else
491 : {
492 1 : data_row_id_t obj_id = data_relationship_get_row_id ( relation );
493 1 : result |= (u8_error_t) data_database_writer_delete_relationship ( (*this_).db_writer, obj_id, NULL );
494 : }
495 : }
496 2 : break;
497 :
498 2 : case CTRL_UNDO_REDO_ENTRY_TYPE_UPDATE_RELATIONSHIP:
499 : {
500 2 : U8_TRACE_INFO( "CTRL_UNDO_REDO_ENTRY_TYPE_UPDATE_RELATIONSHIP" );
501 : data_relationship_t *relation;
502 2 : if ( undo )
503 : {
504 1 : relation = ctrl_undo_redo_entry_get_relationship_before_action_ptr ( action );
505 : }
506 : else
507 : {
508 1 : relation = ctrl_undo_redo_entry_get_relationship_after_action_ptr ( action );
509 : }
510 2 : data_row_id_t relationship_id = data_relationship_get_row_id ( relation );
511 2 : data_relationship_type_t new_relationship_type = data_relationship_get_main_type ( relation );
512 2 : const char* new_relationship_stereotype = data_relationship_get_stereotype_const ( relation );
513 2 : const char* new_relationship_name = data_relationship_get_name_const ( relation );
514 2 : const char* new_relationship_description = data_relationship_get_description_const ( relation );
515 2 : int32_t new_relationship_list_order = data_relationship_get_list_order ( relation );
516 2 : result |= (u8_error_t) data_database_writer_update_relationship_main_type ( (*this_).db_writer, relationship_id, new_relationship_type, NULL );
517 2 : result |= (u8_error_t) data_database_writer_update_relationship_stereotype ( (*this_).db_writer, relationship_id, new_relationship_stereotype, NULL );
518 2 : result |= (u8_error_t) data_database_writer_update_relationship_name ( (*this_).db_writer, relationship_id, new_relationship_name, NULL );
519 2 : result |= (u8_error_t) data_database_writer_update_relationship_description ( (*this_).db_writer, relationship_id, new_relationship_description, NULL );
520 2 : result |= (u8_error_t) data_database_writer_update_relationship_list_order ( (*this_).db_writer, relationship_id, new_relationship_list_order, NULL );
521 : }
522 2 : break;
523 :
524 2 : case CTRL_UNDO_REDO_ENTRY_TYPE_CREATE_RELATIONSHIP:
525 : {
526 2 : U8_TRACE_INFO( "CTRL_UNDO_REDO_ENTRY_TYPE_CREATE_RELATIONSHIP" );
527 2 : data_relationship_t *relation = ctrl_undo_redo_entry_get_relationship_after_action_ptr ( action );
528 2 : if ( undo )
529 : {
530 1 : data_row_id_t obj_id = data_relationship_get_row_id ( relation );
531 1 : result |= (u8_error_t) data_database_writer_delete_relationship ( (*this_).db_writer, obj_id, NULL );
532 : }
533 : else
534 : {
535 1 : result |= (u8_error_t) data_database_writer_create_relationship ( (*this_).db_writer, relation, NULL );
536 : }
537 : }
538 2 : break;
539 :
540 0 : default:
541 : {
542 0 : U8_LOG_ERROR( "unexptected ctrl_undo_redo_entry_type_t" );
543 : }
544 : }
545 :
546 164 : U8_TRACE_END_ERR( result );
547 164 : return result;
548 : }
549 :
550 :
551 : /*
552 : Copyright 2016-2024 Andreas Warnke
553 :
554 : Licensed under the Apache License, Version 2.0 (the "License");
555 : you may not use this file except in compliance with the License.
556 : You may obtain a copy of the License at
557 :
558 : http://www.apache.org/licenses/LICENSE-2.0
559 :
560 : Unless required by applicable law or agreed to in writing, software
561 : distributed under the License is distributed on an "AS IS" BASIS,
562 : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
563 : See the License for the specific language governing permissions and
564 : limitations under the License.
565 : */
|