Line data Source code
1 : /* File: data_visible_set.inl; Copyright and License: see below */
2 :
3 : #include "u8/u8_log.h"
4 : #include <assert.h>
5 :
6 : /* ================================ diagram ================================ */
7 :
8 772 : static inline const data_diagram_t *data_visible_set_get_diagram_const ( const data_visible_set_t *this_ )
9 : {
10 772 : return &((*this_).diagram);
11 : }
12 :
13 2 : static inline data_diagram_t *data_visible_set_get_diagram_ptr ( data_visible_set_t *this_ )
14 : {
15 2 : return &((*this_).diagram);
16 : }
17 :
18 1 : static inline u8_error_t data_visible_set_replace_diagram( data_visible_set_t *this_, const data_diagram_t *new_diagram )
19 : {
20 1 : assert( NULL != new_diagram );
21 1 : data_diagram_replace( &((*this_).diagram), new_diagram );
22 1 : return U8_ERROR_NONE;
23 : }
24 :
25 : /* ================================ classifiers ================================ */
26 :
27 40 : static inline uint32_t data_visible_set_get_visible_classifier_count ( const data_visible_set_t *this_ )
28 : {
29 40 : return (*this_).visible_classifier_count;
30 : }
31 :
32 2277 : static inline const data_visible_classifier_t *data_visible_set_get_visible_classifier_const ( const data_visible_set_t *this_, uint32_t index )
33 : {
34 2277 : assert( (*this_).visible_classifier_count <= DATA_VISIBLE_SET_MAX_CLASSIFIERS );
35 :
36 : const data_visible_classifier_t *result;
37 2277 : if ( index < (*this_).visible_classifier_count )
38 : {
39 2277 : result = &((*this_).visible_classifiers[index]);
40 : }
41 : else
42 : {
43 0 : result = NULL;
44 0 : U8_LOG_ERROR_INT( "index out of bounds (>=(*this_).visible_classifier_count)", index );
45 : }
46 :
47 2277 : return result;
48 : }
49 :
50 : static inline data_visible_classifier_t *data_visible_set_get_visible_classifier_ptr ( data_visible_set_t *this_, uint32_t index )
51 : {
52 : assert( (*this_).visible_classifier_count <= DATA_VISIBLE_SET_MAX_CLASSIFIERS );
53 :
54 : data_visible_classifier_t *result;
55 : if ( index < (*this_).visible_classifier_count )
56 : {
57 : result = &((*this_).visible_classifiers[index]);
58 : }
59 : else
60 : {
61 : result = NULL;
62 : U8_LOG_ERROR_INT( "index out of bounds (>=(*this_).visible_classifier_count)", index );
63 : }
64 :
65 : return result;
66 : }
67 :
68 1 : static inline const data_visible_classifier_t *data_visible_set_get_visible_classifier_by_id_const ( const data_visible_set_t *this_, data_row_t diagramelement_id )
69 : {
70 1 : assert( (*this_).visible_classifier_count <= DATA_VISIBLE_SET_MAX_CLASSIFIERS );
71 1 : const data_visible_classifier_t *result = NULL;
72 :
73 : /* iterate over all visible classifiers */
74 2 : for ( uint32_t index = 0; index < (*this_).visible_classifier_count; index ++ )
75 : {
76 : const data_visible_classifier_t *visible_classifier;
77 2 : visible_classifier = &((*this_).visible_classifiers[index]);
78 2 : assert ( data_visible_classifier_is_valid( visible_classifier ) );
79 :
80 : const data_diagramelement_t *diagramelement;
81 2 : diagramelement = data_visible_classifier_get_diagramelement_const( visible_classifier );
82 2 : if ( data_diagramelement_get_row_id( diagramelement ) == diagramelement_id )
83 : {
84 1 : result = visible_classifier;
85 1 : break;
86 : }
87 : }
88 :
89 1 : return result;
90 : }
91 :
92 1 : static inline data_visible_classifier_t *data_visible_set_get_visible_classifier_by_id_ptr ( data_visible_set_t *this_, data_row_t diagramelement_id )
93 : {
94 1 : assert( (*this_).visible_classifier_count <= DATA_VISIBLE_SET_MAX_CLASSIFIERS );
95 1 : data_visible_classifier_t *result = NULL;
96 :
97 : /* iterate over all visible classifiers */
98 1 : for ( uint32_t index = 0; index < (*this_).visible_classifier_count; index ++ )
99 : {
100 : data_visible_classifier_t *visible_classifier;
101 1 : visible_classifier = &((*this_).visible_classifiers[index]);
102 1 : assert ( data_visible_classifier_is_valid( visible_classifier ) );
103 :
104 : data_diagramelement_t *diagramelement;
105 1 : diagramelement = data_visible_classifier_get_diagramelement_ptr( visible_classifier );
106 1 : if ( data_diagramelement_get_row_id( diagramelement ) == diagramelement_id )
107 : {
108 1 : result = visible_classifier;
109 1 : break;
110 : }
111 : }
112 :
113 1 : return result;
114 : }
115 :
116 1206 : static inline const data_classifier_t *data_visible_set_get_classifier_by_id_const ( const data_visible_set_t *this_, data_row_t row_id )
117 : {
118 1206 : assert( (*this_).visible_classifier_count <= DATA_VISIBLE_SET_MAX_CLASSIFIERS );
119 1206 : const data_classifier_t *result = NULL;
120 :
121 59826 : for ( int index = 0; index < (*this_).visible_classifier_count; index ++ )
122 : {
123 : const data_visible_classifier_t *visible_classifier;
124 59791 : visible_classifier = &((*this_).visible_classifiers[index]);
125 59791 : assert ( data_visible_classifier_is_valid( visible_classifier ) );
126 :
127 : const data_classifier_t *probe;
128 59791 : probe = data_visible_classifier_get_classifier_const( visible_classifier );
129 59791 : if ( row_id == data_classifier_get_row_id( probe ) )
130 : {
131 1171 : result = probe;
132 1171 : break;
133 : }
134 : }
135 :
136 1206 : return result;
137 : }
138 :
139 1 : static inline data_classifier_t *data_visible_set_get_classifier_by_id_ptr ( data_visible_set_t *this_, data_row_t row_id )
140 : {
141 1 : assert( (*this_).visible_classifier_count <= DATA_VISIBLE_SET_MAX_CLASSIFIERS );
142 1 : data_classifier_t *result = NULL;
143 :
144 1 : for ( int index = 0; index < (*this_).visible_classifier_count; index ++ )
145 : {
146 : data_visible_classifier_t *visible_classifier;
147 1 : visible_classifier = &((*this_).visible_classifiers[index]);
148 1 : assert ( data_visible_classifier_is_valid( visible_classifier ) );
149 :
150 : data_classifier_t *probe;
151 1 : probe = data_visible_classifier_get_classifier_ptr( visible_classifier );
152 1 : if ( row_id == data_classifier_get_row_id( probe ) )
153 : {
154 1 : result = probe;
155 1 : break;
156 : }
157 : }
158 :
159 1 : return result;
160 : }
161 :
162 772 : static inline int32_t data_visible_set_get_classifier_index ( const data_visible_set_t *this_, data_row_t row_id )
163 : {
164 772 : assert( (*this_).visible_classifier_count <= DATA_VISIBLE_SET_MAX_CLASSIFIERS );
165 772 : int32_t result = -1;
166 :
167 1158 : for ( int index = 0; index < (*this_).visible_classifier_count; index ++ )
168 : {
169 : const data_classifier_t *probe;
170 1158 : probe = data_visible_classifier_get_classifier_const( &((*this_).visible_classifiers[index]) );
171 1158 : if ( row_id == data_classifier_get_row_id( probe ) )
172 : {
173 772 : result = index;
174 772 : break;
175 : }
176 : }
177 :
178 772 : return result;
179 : }
180 :
181 1 : static inline uint32_t data_visible_set_get_classifier_index_from_pointer ( const data_visible_set_t *this_,
182 : const data_visible_classifier_t *vis_classifier_ptr )
183 : {
184 1 : assert ( NULL != vis_classifier_ptr ); /* input parameters test */
185 1 : assert ( vis_classifier_ptr >= &((*this_).visible_classifiers[0]) ); /* input parameters test */
186 1 : assert ( vis_classifier_ptr < &((*this_).visible_classifiers[DATA_VISIBLE_SET_MAX_CLASSIFIERS]) ); /* input parameters test */
187 : assert ( 3 == &((*this_).visible_classifiers[3]) - (*this_).visible_classifiers ); /* compiler test */
188 1 : return ( vis_classifier_ptr - (*this_).visible_classifiers );
189 : }
190 :
191 129 : static inline u8_error_t data_visible_set_append_classifier( data_visible_set_t *this_, const data_visible_classifier_t *new_classifier )
192 : {
193 129 : assert( (*this_).visible_classifier_count <= DATA_VISIBLE_SET_MAX_CLASSIFIERS );
194 129 : assert( NULL != new_classifier );
195 129 : u8_error_t result = U8_ERROR_NONE;
196 :
197 129 : const uint32_t new_index = (*this_).visible_classifier_count;
198 129 : if ( new_index < DATA_VISIBLE_SET_MAX_CLASSIFIERS )
199 : {
200 128 : data_visible_classifier_copy( &((*this_).visible_classifiers[new_index]), new_classifier );
201 128 : (*this_).visible_classifier_count ++;
202 : }
203 : else
204 : {
205 1 : result = U8_ERROR_ARRAY_BUFFER_EXCEEDED;
206 : }
207 :
208 129 : return result;
209 : }
210 :
211 : /* ================================ features ================================ */
212 :
213 14 : static inline uint32_t data_visible_set_get_feature_count ( const data_visible_set_t *this_ )
214 : {
215 14 : return (*this_).feature_count;
216 : }
217 :
218 559 : static inline const data_feature_t *data_visible_set_get_feature_const ( const data_visible_set_t *this_, uint32_t index )
219 : {
220 559 : assert( (*this_).feature_count <= DATA_VISIBLE_SET_MAX_FEATURES );
221 :
222 : const data_feature_t *result;
223 559 : if ( index < (*this_).feature_count )
224 : {
225 559 : result = &((*this_).features[index]);
226 : }
227 : else
228 : {
229 0 : result = NULL;
230 0 : U8_LOG_ERROR_INT( "index out of bounds (>=(*this_).feature_count)", index );
231 : }
232 :
233 559 : return result;
234 : }
235 :
236 2 : static inline data_feature_t *data_visible_set_get_feature_ptr ( data_visible_set_t *this_, uint32_t index )
237 : {
238 2 : assert( (*this_).feature_count <= DATA_VISIBLE_SET_MAX_FEATURES );
239 :
240 : data_feature_t *result;
241 2 : if ( index < (*this_).feature_count )
242 : {
243 2 : result = &((*this_).features[index]);
244 : }
245 : else
246 : {
247 0 : result = NULL;
248 0 : U8_LOG_ERROR_INT( "index out of bounds (>=(*this_).feature_count)", index );
249 : }
250 :
251 2 : return result;
252 : }
253 :
254 1182 : static inline const data_feature_t *data_visible_set_get_feature_by_id_const ( const data_visible_set_t *this_, data_row_t row_id )
255 : {
256 1182 : assert( (*this_).feature_count <= DATA_VISIBLE_SET_MAX_FEATURES );
257 1182 : const data_feature_t *result = NULL;
258 :
259 238259 : for ( int index = 0; index < (*this_).feature_count; index ++ )
260 : {
261 : const data_feature_t *probe;
262 237428 : probe = &((*this_).features[index]);
263 237428 : if ( row_id == data_feature_get_row_id( probe ) )
264 : {
265 351 : result = probe;
266 351 : break;
267 : }
268 : }
269 :
270 1182 : return result;
271 : }
272 :
273 1 : static inline data_feature_t *data_visible_set_get_feature_by_id_ptr ( data_visible_set_t *this_, data_row_t row_id )
274 : {
275 1 : assert( (*this_).feature_count <= DATA_VISIBLE_SET_MAX_FEATURES );
276 1 : data_feature_t *result = NULL;
277 :
278 1 : for ( int index = 0; index < (*this_).feature_count; index ++ )
279 : {
280 : data_feature_t *probe;
281 1 : probe = &((*this_).features[index]);
282 1 : if ( row_id == data_feature_get_row_id( probe ) )
283 : {
284 1 : result = probe;
285 1 : break;
286 : }
287 : }
288 :
289 1 : return result;
290 : }
291 :
292 1 : static inline data_feature_t *data_visible_set_get_feature_list_ptr ( data_visible_set_t *this_ )
293 : {
294 1 : assert( (*this_).feature_count <= DATA_VISIBLE_SET_MAX_FEATURES );
295 1 : return (*this_).features;
296 : }
297 :
298 257 : static inline u8_error_t data_visible_set_append_feature( data_visible_set_t *this_, const data_feature_t *new_feature )
299 : {
300 257 : assert( (*this_).feature_count <= DATA_VISIBLE_SET_MAX_FEATURES );
301 257 : assert( NULL != new_feature );
302 257 : u8_error_t result = U8_ERROR_NONE;
303 :
304 257 : const uint32_t new_index = (*this_).feature_count;
305 257 : if ( new_index < DATA_VISIBLE_SET_MAX_FEATURES )
306 : {
307 256 : data_feature_copy( &((*this_).features[new_index]), new_feature );
308 256 : (*this_).feature_count ++;
309 : }
310 : else
311 : {
312 1 : result = U8_ERROR_ARRAY_BUFFER_EXCEEDED;
313 : }
314 :
315 257 : return result;
316 : }
317 :
318 : /* ================================ relationships ================================ */
319 :
320 14 : static inline uint32_t data_visible_set_get_relationship_count ( const data_visible_set_t *this_ )
321 : {
322 14 : return (*this_).relationship_count;
323 : }
324 :
325 805 : static inline const data_relationship_t *data_visible_set_get_relationship_const ( const data_visible_set_t *this_, uint32_t index )
326 : {
327 805 : assert( (*this_).relationship_count <= DATA_VISIBLE_SET_MAX_RELATIONSHIPS );
328 :
329 : const data_relationship_t *result;
330 805 : if ( index < (*this_).relationship_count )
331 : {
332 805 : result = &((*this_).relationships[index]);
333 : }
334 : else
335 : {
336 0 : result = NULL;
337 0 : U8_LOG_ERROR_INT( "index out of bounds (>=(*this_).relationship_count)", index );
338 : }
339 :
340 805 : return result;
341 : }
342 :
343 5 : static inline data_relationship_t *data_visible_set_get_relationship_ptr ( data_visible_set_t *this_, uint32_t index )
344 : {
345 5 : assert( (*this_).relationship_count <= DATA_VISIBLE_SET_MAX_RELATIONSHIPS );
346 :
347 : data_relationship_t *result;
348 5 : if ( index < (*this_).relationship_count )
349 : {
350 5 : result = &((*this_).relationships[index]);
351 : }
352 : else
353 : {
354 0 : result = NULL;
355 0 : U8_LOG_ERROR_INT( "index out of bounds (>=(*this_).relationship_count)", index );
356 : }
357 :
358 5 : return result;
359 : }
360 :
361 449 : static inline const data_relationship_t *data_visible_set_get_relationship_by_id_const ( const data_visible_set_t *this_, data_row_t row_id )
362 : {
363 449 : assert( (*this_).relationship_count <= DATA_VISIBLE_SET_MAX_RELATIONSHIPS );
364 449 : const data_relationship_t *result = NULL;
365 :
366 74679 : for ( int index = 0; index < (*this_).relationship_count; index ++ )
367 : {
368 : const data_relationship_t *probe;
369 74679 : probe = &((*this_).relationships[index]);
370 74679 : if ( row_id == data_relationship_get_row_id( probe ) )
371 : {
372 449 : result = probe;
373 449 : break;
374 : }
375 : }
376 :
377 449 : return result;
378 : }
379 :
380 1 : static inline data_relationship_t *data_visible_set_get_relationship_by_id_ptr ( data_visible_set_t *this_, data_row_t row_id )
381 : {
382 1 : assert( (*this_).relationship_count <= DATA_VISIBLE_SET_MAX_RELATIONSHIPS );
383 1 : data_relationship_t *result = NULL;
384 :
385 2 : for ( int index = 0; index < (*this_).relationship_count; index ++ )
386 : {
387 : data_relationship_t *probe;
388 2 : probe = &((*this_).relationships[index]);
389 2 : if ( row_id == data_relationship_get_row_id( probe ) )
390 : {
391 1 : result = probe;
392 1 : break;
393 : }
394 : }
395 :
396 1 : return result;
397 : }
398 :
399 4 : static inline bool data_visible_set_is_ancestor_by_index ( const data_visible_set_t *this_, uint32_t ancestor_index, uint32_t descendant_index )
400 : {
401 4 : assert( (*this_).visible_classifier_count <= DATA_VISIBLE_SET_MAX_CLASSIFIERS );
402 4 : assert( ancestor_index < (*this_).visible_classifier_count );
403 4 : assert( descendant_index < (*this_).visible_classifier_count );
404 :
405 4 : return (*this_).containment_cache[ancestor_index][descendant_index];
406 : }
407 :
408 1 : static inline uint32_t data_visible_set_count_ancestors_of_index ( const data_visible_set_t *this_, uint32_t classifier_index )
409 : {
410 1 : assert( (*this_).visible_classifier_count <= DATA_VISIBLE_SET_MAX_CLASSIFIERS );
411 1 : assert( classifier_index < (*this_).visible_classifier_count );
412 :
413 1 : uint32_t result = 0;
414 :
415 3 : for ( uint32_t ancestor_index = 0; ancestor_index < (*this_).visible_classifier_count; ancestor_index ++ )
416 : {
417 2 : if ( (*this_).containment_cache[ancestor_index][classifier_index] )
418 : {
419 1 : result ++;
420 : }
421 : }
422 :
423 1 : return result;
424 : }
425 :
426 1 : static inline uint32_t data_visible_set_count_descendants_of_index ( const data_visible_set_t *this_, uint32_t classifier_index )
427 : {
428 1 : assert( (*this_).visible_classifier_count <= DATA_VISIBLE_SET_MAX_CLASSIFIERS );
429 1 : assert( classifier_index < (*this_).visible_classifier_count );
430 :
431 1 : uint32_t result = 0;
432 :
433 3 : for ( uint32_t descendant_index = 0; descendant_index < (*this_).visible_classifier_count; descendant_index ++ )
434 : {
435 2 : if ( (*this_).containment_cache[classifier_index][descendant_index] )
436 : {
437 1 : result ++;
438 : }
439 : }
440 :
441 1 : return result;
442 : }
443 :
444 385 : static inline u8_error_t data_visible_set_append_relationship( data_visible_set_t *this_, const data_relationship_t *new_relationship )
445 : {
446 385 : assert( (*this_).relationship_count <= DATA_VISIBLE_SET_MAX_RELATIONSHIPS );
447 385 : assert( NULL != new_relationship );
448 385 : u8_error_t result = U8_ERROR_NONE;
449 :
450 385 : const uint32_t new_index = (*this_).relationship_count;
451 385 : if ( new_index < DATA_VISIBLE_SET_MAX_RELATIONSHIPS )
452 : {
453 384 : data_relationship_copy( &((*this_).relationships[new_index]), new_relationship );
454 384 : (*this_).relationship_count ++;
455 : }
456 : else
457 : {
458 1 : result = U8_ERROR_ARRAY_BUFFER_EXCEEDED;
459 : }
460 :
461 385 : return result;
462 : }
463 :
464 : /* ================================ misc ================================ */
465 :
466 30 : static inline bool data_visible_set_is_valid ( const data_visible_set_t *this_ )
467 : {
468 30 : return data_diagram_is_valid( &((*this_).diagram) );
469 : }
470 :
471 1 : static inline void data_visible_set_invalidate ( data_visible_set_t *this_ )
472 : {
473 1 : data_visible_set_reinit( this_ );
474 1 : }
475 :
476 16 : static inline void data_visible_set_private_destroy_visible_classifiers( data_visible_set_t *this_ )
477 : {
478 16 : assert( (*this_).visible_classifier_count <= DATA_VISIBLE_SET_MAX_CLASSIFIERS );
479 :
480 201 : for ( int index = 0; index < (*this_).visible_classifier_count; index ++ )
481 : {
482 185 : data_visible_classifier_destroy ( &((*this_).visible_classifiers[index]) );
483 : }
484 :
485 16 : (*this_).visible_classifier_count = 0;
486 16 : }
487 :
488 16 : static inline void data_visible_set_private_destroy_features( data_visible_set_t *this_ )
489 : {
490 16 : assert( (*this_).feature_count <= DATA_VISIBLE_SET_MAX_FEATURES );
491 :
492 277 : for ( int index = 0; index < (*this_).feature_count; index ++ )
493 : {
494 261 : data_feature_destroy ( &((*this_).features[index]) );
495 : }
496 :
497 16 : (*this_).feature_count = 0;
498 16 : }
499 :
500 16 : static inline void data_visible_set_private_destroy_relationships( data_visible_set_t *this_ )
501 : {
502 16 : assert( (*this_).relationship_count <= DATA_VISIBLE_SET_MAX_RELATIONSHIPS );
503 :
504 407 : for ( int index = 0; index < (*this_).relationship_count; index ++ )
505 : {
506 391 : data_relationship_destroy ( &((*this_).relationships[index]) );
507 : }
508 :
509 16 : (*this_).relationship_count = 0;
510 16 : }
511 :
512 :
513 : /*
514 : Copyright 2016-2025 Andreas Warnke
515 :
516 : Licensed under the Apache License, Version 2.0 (the "License");
517 : you may not use this file except in compliance with the License.
518 : You may obtain a copy of the License at
519 :
520 : http://www.apache.org/licenses/LICENSE-2.0
521 :
522 : Unless required by applicable law or agreed to in writing, software
523 : distributed under the License is distributed on an "AS IS" BASIS,
524 : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
525 : See the License for the specific language governing permissions and
526 : limitations under the License.
527 : */
|