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 1409 : static inline const data_diagram_t *data_visible_set_get_diagram_const ( const data_visible_set_t *this_ ) 9 : { 10 1409 : return &((*this_).diagram); 11 : } 12 : 13 0 : static inline data_diagram_t *data_visible_set_get_diagram_ptr ( data_visible_set_t *this_ ) 14 : { 15 0 : return &((*this_).diagram); 16 : } 17 : 18 : static inline u8_error_t data_visible_set_set_diagram( data_visible_set_t *this_, const data_diagram_t *new_diagram ) 19 : { 20 : assert( NULL != new_diagram ); 21 : data_diagram_replace( &((*this_).diagram), new_diagram ); 22 : return U8_ERROR_NONE; 23 : } 24 : 25 : /* ================================ classifiers ================================ */ 26 : 27 32 : static inline uint32_t data_visible_set_get_visible_classifier_count ( const data_visible_set_t *this_ ) 28 : { 29 32 : return (*this_).visible_classifier_count; 30 : } 31 : 32 2124 : 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 2124 : assert( (*this_).visible_classifier_count <= DATA_VISIBLE_SET_MAX_CLASSIFIERS ); 35 : 36 : const data_visible_classifier_t *result; 37 2124 : if ( index < (*this_).visible_classifier_count ) 38 : { 39 2124 : 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 2124 : 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 0 : static inline const data_visible_classifier_t *data_visible_set_get_visible_classifier_by_id_const ( const data_visible_set_t *this_, data_row_id_t diagramelement_id ) 69 : { 70 0 : assert( (*this_).visible_classifier_count <= DATA_VISIBLE_SET_MAX_CLASSIFIERS ); 71 0 : const data_visible_classifier_t *result = NULL; 72 : 73 : /* iterate over all visible classifiers */ 74 0 : for ( uint32_t index = 0; index < (*this_).visible_classifier_count; index ++ ) 75 : { 76 : const data_visible_classifier_t *visible_classifier; 77 0 : visible_classifier = &((*this_).visible_classifiers[index]); 78 0 : assert ( data_visible_classifier_is_valid( visible_classifier ) ); 79 : 80 : const data_diagramelement_t *diagramelement; 81 0 : diagramelement = data_visible_classifier_get_diagramelement_const( visible_classifier ); 82 0 : if ( data_diagramelement_get_row_id( diagramelement ) == diagramelement_id ) 83 : { 84 0 : result = visible_classifier; 85 0 : break; 86 : } 87 : } 88 : 89 0 : return result; 90 : } 91 : 92 : static inline data_visible_classifier_t *data_visible_set_get_visible_classifier_by_id_ptr ( data_visible_set_t *this_, data_row_id_t diagramelement_id ) 93 : { 94 : assert( (*this_).visible_classifier_count <= DATA_VISIBLE_SET_MAX_CLASSIFIERS ); 95 : data_visible_classifier_t *result = NULL; 96 : 97 : /* iterate over all visible classifiers */ 98 : for ( uint32_t index = 0; index < (*this_).visible_classifier_count; index ++ ) 99 : { 100 : data_visible_classifier_t *visible_classifier; 101 : visible_classifier = &((*this_).visible_classifiers[index]); 102 : assert ( data_visible_classifier_is_valid( visible_classifier ) ); 103 : 104 : data_diagramelement_t *diagramelement; 105 : diagramelement = data_visible_classifier_get_diagramelement_ptr( visible_classifier ); 106 : if ( data_diagramelement_get_row_id( diagramelement ) == diagramelement_id ) 107 : { 108 : result = visible_classifier; 109 : break; 110 : } 111 : } 112 : 113 : return result; 114 : } 115 : 116 2485 : static inline const data_classifier_t *data_visible_set_get_classifier_by_id_const ( const data_visible_set_t *this_, data_row_id_t row_id ) 117 : { 118 2485 : assert( (*this_).visible_classifier_count <= DATA_VISIBLE_SET_MAX_CLASSIFIERS ); 119 2485 : const data_classifier_t *result = NULL; 120 : 121 128944 : for ( int index = 0; index < (*this_).visible_classifier_count; index ++ ) 122 : { 123 : const data_visible_classifier_t *visible_classifier; 124 128909 : visible_classifier = &((*this_).visible_classifiers[index]); 125 128909 : assert ( data_visible_classifier_is_valid( visible_classifier ) ); 126 : 127 : const data_classifier_t *probe; 128 128909 : probe = data_visible_classifier_get_classifier_const( visible_classifier ); 129 128909 : if ( row_id == data_classifier_get_row_id( probe ) ) 130 : { 131 2450 : result = probe; 132 2450 : break; 133 : } 134 : } 135 : 136 2485 : return result; 137 : } 138 : 139 0 : static inline data_classifier_t *data_visible_set_get_classifier_by_id_ptr ( data_visible_set_t *this_, data_row_id_t row_id ) 140 : { 141 0 : assert( (*this_).visible_classifier_count <= DATA_VISIBLE_SET_MAX_CLASSIFIERS ); 142 0 : data_classifier_t *result = NULL; 143 : 144 0 : for ( int index = 0; index < (*this_).visible_classifier_count; index ++ ) 145 : { 146 : data_visible_classifier_t *visible_classifier; 147 0 : visible_classifier = &((*this_).visible_classifiers[index]); 148 0 : assert ( data_visible_classifier_is_valid( visible_classifier ) ); 149 : 150 : data_classifier_t *probe; 151 0 : probe = data_visible_classifier_get_classifier_ptr( visible_classifier ); 152 0 : if ( row_id == data_classifier_get_row_id( probe ) ) 153 : { 154 0 : result = probe; 155 0 : break; 156 : } 157 : } 158 : 159 0 : return result; 160 : } 161 : 162 0 : static inline int32_t data_visible_set_get_classifier_index ( const data_visible_set_t *this_, data_row_id_t row_id ) 163 : { 164 0 : assert( (*this_).visible_classifier_count <= DATA_VISIBLE_SET_MAX_CLASSIFIERS ); 165 0 : int32_t result = -1; 166 : 167 0 : for ( int index = 0; index < (*this_).visible_classifier_count; index ++ ) 168 : { 169 : const data_classifier_t *probe; 170 0 : probe = data_visible_classifier_get_classifier_const( &((*this_).visible_classifiers[index]) ); 171 0 : if ( row_id == data_classifier_get_row_id( probe ) ) 172 : { 173 0 : result = index; 174 0 : break; 175 : } 176 : } 177 : 178 0 : return result; 179 : } 180 : 181 0 : static inline uint32_t data_visible_set_get_classifier_index_from_pointer ( const data_visible_set_t *this_, 182 : const data_visible_classifier_t *classifier_ptr ) 183 : { 184 0 : assert ( NULL != classifier_ptr ); /* input parameters test */ 185 0 : assert ( classifier_ptr >= &((*this_).visible_classifiers[0]) ); /* input parameters test */ 186 0 : assert ( 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 0 : return ( classifier_ptr - (*this_).visible_classifiers ); 189 : } 190 : 191 0 : static inline u8_error_t data_visible_set_append_classifier( data_visible_set_t *this_, const data_visible_classifier_t *new_classifier ) 192 : { 193 0 : assert( (*this_).visible_classifier_count <= DATA_VISIBLE_SET_MAX_CLASSIFIERS ); 194 0 : assert( NULL != new_classifier ); 195 0 : u8_error_t result = U8_ERROR_NONE; 196 : 197 0 : const uint32_t new_index = (*this_).visible_classifier_count; 198 0 : if ( new_index < DATA_VISIBLE_SET_MAX_CLASSIFIERS ) 199 : { 200 0 : data_visible_classifier_copy( &((*this_).visible_classifiers[new_index]), new_classifier ); 201 0 : (*this_).visible_classifier_count ++; 202 : } 203 : else 204 : { 205 0 : result = U8_ERROR_ARRAY_BUFFER_EXCEEDED; 206 : } 207 : 208 0 : return result; 209 : } 210 : 211 : /* ================================ features ================================ */ 212 : 213 8 : static inline uint32_t data_visible_set_get_feature_count ( const data_visible_set_t *this_ ) 214 : { 215 8 : return (*this_).feature_count; 216 : } 217 : 218 301 : static inline const data_feature_t *data_visible_set_get_feature_const ( const data_visible_set_t *this_, uint32_t index ) 219 : { 220 301 : assert( (*this_).feature_count <= DATA_VISIBLE_SET_MAX_FEATURES ); 221 : 222 : const data_feature_t *result; 223 301 : if ( index < (*this_).feature_count ) 224 : { 225 301 : 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 301 : return result; 234 : } 235 : 236 1 : static inline data_feature_t *data_visible_set_get_feature_ptr ( data_visible_set_t *this_, uint32_t index ) 237 : { 238 1 : assert( (*this_).feature_count <= DATA_VISIBLE_SET_MAX_FEATURES ); 239 : 240 : data_feature_t *result; 241 1 : if ( index < (*this_).feature_count ) 242 : { 243 1 : 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 1 : return result; 252 : } 253 : 254 2459 : static inline const data_feature_t *data_visible_set_get_feature_by_id_const ( const data_visible_set_t *this_, data_row_id_t row_id ) 255 : { 256 2459 : assert( (*this_).feature_count <= DATA_VISIBLE_SET_MAX_FEATURES ); 257 2459 : const data_feature_t *result = NULL; 258 : 259 567215 : for ( int index = 0; index < (*this_).feature_count; index ++ ) 260 : { 261 : const data_feature_t *probe; 262 565104 : probe = &((*this_).features[index]); 263 565104 : if ( row_id == data_feature_get_row_id( probe ) ) 264 : { 265 348 : result = probe; 266 348 : break; 267 : } 268 : } 269 : 270 2459 : return result; 271 : } 272 : 273 0 : static inline data_feature_t *data_visible_set_get_feature_by_id_ptr ( data_visible_set_t *this_, data_row_id_t row_id ) 274 : { 275 0 : assert( (*this_).feature_count <= DATA_VISIBLE_SET_MAX_FEATURES ); 276 0 : data_feature_t *result = NULL; 277 : 278 0 : for ( int index = 0; index < (*this_).feature_count; index ++ ) 279 : { 280 : data_feature_t *probe; 281 0 : probe = &((*this_).features[index]); 282 0 : if ( row_id == data_feature_get_row_id( probe ) ) 283 : { 284 0 : result = probe; 285 0 : break; 286 : } 287 : } 288 : 289 0 : return result; 290 : } 291 : 292 : static inline data_feature_t *data_visible_set_get_feature_list_ptr ( data_visible_set_t *this_ ) 293 : { 294 : assert( (*this_).feature_count <= DATA_VISIBLE_SET_MAX_FEATURES ); 295 : return (*this_).features; 296 : } 297 : 298 0 : static inline u8_error_t data_visible_set_append_feature( data_visible_set_t *this_, const data_feature_t *new_feature ) 299 : { 300 0 : assert( (*this_).feature_count <= DATA_VISIBLE_SET_MAX_FEATURES ); 301 0 : assert( NULL != new_feature ); 302 0 : u8_error_t result = U8_ERROR_NONE; 303 : 304 0 : const uint32_t new_index = (*this_).feature_count; 305 0 : if ( new_index < DATA_VISIBLE_SET_MAX_FEATURES ) 306 : { 307 0 : data_feature_copy( &((*this_).features[new_index]), new_feature ); 308 0 : (*this_).feature_count ++; 309 : } 310 : else 311 : { 312 0 : result = U8_ERROR_ARRAY_BUFFER_EXCEEDED; 313 : } 314 : 315 0 : return result; 316 : } 317 : 318 : /* ================================ relationships ================================ */ 319 : 320 8 : static inline uint32_t data_visible_set_get_relationship_count ( const data_visible_set_t *this_ ) 321 : { 322 8 : return (*this_).relationship_count; 323 : } 324 : 325 1059 : static inline const data_relationship_t *data_visible_set_get_relationship_const ( const data_visible_set_t *this_, uint32_t index ) 326 : { 327 1059 : assert( (*this_).relationship_count <= DATA_VISIBLE_SET_MAX_RELATIONSHIPS ); 328 : 329 : const data_relationship_t *result; 330 1059 : if ( index < (*this_).relationship_count ) 331 : { 332 1059 : 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 1059 : return result; 341 : } 342 : 343 4 : static inline data_relationship_t *data_visible_set_get_relationship_ptr ( data_visible_set_t *this_, uint32_t index ) 344 : { 345 4 : assert( (*this_).relationship_count <= DATA_VISIBLE_SET_MAX_RELATIONSHIPS ); 346 : 347 : data_relationship_t *result; 348 4 : if ( index < (*this_).relationship_count ) 349 : { 350 4 : 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 4 : return result; 359 : } 360 : 361 1084 : static inline const data_relationship_t *data_visible_set_get_relationship_by_id_const ( const data_visible_set_t *this_, data_row_id_t row_id ) 362 : { 363 1084 : assert( (*this_).relationship_count <= DATA_VISIBLE_SET_MAX_RELATIONSHIPS ); 364 1084 : const data_relationship_t *result = NULL; 365 : 366 525548 : for ( int index = 0; index < (*this_).relationship_count; index ++ ) 367 : { 368 : const data_relationship_t *probe; 369 525548 : probe = &((*this_).relationships[index]); 370 525548 : if ( row_id == data_relationship_get_row_id( probe ) ) 371 : { 372 1084 : result = probe; 373 1084 : break; 374 : } 375 : } 376 : 377 1084 : return result; 378 : } 379 : 380 0 : static inline data_relationship_t *data_visible_set_get_relationship_by_id_ptr ( data_visible_set_t *this_, data_row_id_t row_id ) 381 : { 382 0 : assert( (*this_).relationship_count <= DATA_VISIBLE_SET_MAX_RELATIONSHIPS ); 383 0 : data_relationship_t *result = NULL; 384 : 385 0 : for ( int index = 0; index < (*this_).relationship_count; index ++ ) 386 : { 387 : data_relationship_t *probe; 388 0 : probe = &((*this_).relationships[index]); 389 0 : if ( row_id == data_relationship_get_row_id( probe ) ) 390 : { 391 0 : result = probe; 392 0 : break; 393 : } 394 : } 395 : 396 0 : return result; 397 : } 398 : 399 0 : 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 0 : assert( (*this_).visible_classifier_count <= DATA_VISIBLE_SET_MAX_CLASSIFIERS ); 402 0 : assert( ancestor_index < (*this_).visible_classifier_count ); 403 0 : assert( descendant_index < (*this_).visible_classifier_count ); 404 : 405 0 : return (*this_).containment_cache[ancestor_index][descendant_index]; 406 : } 407 : 408 : static inline uint32_t data_visible_set_count_ancestors_of_index ( const data_visible_set_t *this_, uint32_t classifier_index ) 409 : { 410 : assert( (*this_).visible_classifier_count <= DATA_VISIBLE_SET_MAX_CLASSIFIERS ); 411 : assert( classifier_index < (*this_).visible_classifier_count ); 412 : 413 : uint32_t result = 0; 414 : 415 : for ( uint32_t ancestor_index = 0; ancestor_index < (*this_).visible_classifier_count; ancestor_index ++ ) 416 : { 417 : if ( (*this_).containment_cache[ancestor_index][classifier_index] ) 418 : { 419 : result ++; 420 : } 421 : } 422 : 423 : return result; 424 : } 425 : 426 0 : static inline uint32_t data_visible_set_count_descendants_of_index ( const data_visible_set_t *this_, uint32_t classifier_index ) 427 : { 428 0 : assert( (*this_).visible_classifier_count <= DATA_VISIBLE_SET_MAX_CLASSIFIERS ); 429 0 : assert( classifier_index < (*this_).visible_classifier_count ); 430 : 431 0 : uint32_t result = 0; 432 : 433 0 : for ( uint32_t descendant_index = 0; descendant_index < (*this_).visible_classifier_count; descendant_index ++ ) 434 : { 435 0 : if ( (*this_).containment_cache[classifier_index][descendant_index] ) 436 : { 437 0 : result ++; 438 : } 439 : } 440 : 441 0 : return result; 442 : } 443 : 444 0 : static inline u8_error_t data_visible_set_append_relationship( data_visible_set_t *this_, const data_relationship_t *new_relationship ) 445 : { 446 0 : assert( (*this_).relationship_count <= DATA_VISIBLE_SET_MAX_RELATIONSHIPS ); 447 0 : assert( NULL != new_relationship ); 448 0 : u8_error_t result = U8_ERROR_NONE; 449 : 450 0 : const uint32_t new_index = (*this_).relationship_count; 451 0 : if ( new_index < DATA_VISIBLE_SET_MAX_RELATIONSHIPS ) 452 : { 453 0 : data_relationship_copy( &((*this_).relationships[new_index]), new_relationship ); 454 0 : (*this_).relationship_count ++; 455 : } 456 : else 457 : { 458 0 : result = U8_ERROR_ARRAY_BUFFER_EXCEEDED; 459 : } 460 : 461 0 : return result; 462 : } 463 : 464 : /* ================================ misc ================================ */ 465 : 466 23 : static inline bool data_visible_set_is_valid ( const data_visible_set_t *this_ ) 467 : { 468 23 : return data_diagram_is_valid( &((*this_).diagram) ); 469 : } 470 : 471 : static inline void data_visible_set_invalidate ( data_visible_set_t *this_ ) 472 : { 473 : data_diagram_reinit_empty( &((*this_).diagram) ); 474 : } 475 : 476 6 : static inline void data_visible_set_private_destroy_visible_classifiers( data_visible_set_t *this_ ) 477 : { 478 6 : assert( (*this_).visible_classifier_count <= DATA_VISIBLE_SET_MAX_CLASSIFIERS ); 479 : 480 35 : for ( int index = 0; index < (*this_).visible_classifier_count; index ++ ) 481 : { 482 29 : data_visible_classifier_destroy ( &((*this_).visible_classifiers[index]) ); 483 : } 484 : 485 6 : (*this_).visible_classifier_count = 0; 486 6 : } 487 : 488 6 : static inline void data_visible_set_private_destroy_features( data_visible_set_t *this_ ) 489 : { 490 6 : assert( (*this_).feature_count <= DATA_VISIBLE_SET_MAX_FEATURES ); 491 : 492 6 : for ( int index = 0; index < (*this_).feature_count; index ++ ) 493 : { 494 0 : data_feature_destroy ( &((*this_).features[index]) ); 495 : } 496 : 497 6 : (*this_).feature_count = 0; 498 6 : } 499 : 500 6 : static inline void data_visible_set_private_destroy_relationships( data_visible_set_t *this_ ) 501 : { 502 6 : assert( (*this_).relationship_count <= DATA_VISIBLE_SET_MAX_RELATIONSHIPS ); 503 : 504 6 : for ( int index = 0; index < (*this_).relationship_count; index ++ ) 505 : { 506 0 : data_relationship_destroy ( &((*this_).relationships[index]) ); 507 : } 508 : 509 6 : (*this_).relationship_count = 0; 510 6 : } 511 : 512 : 513 : /* 514 : Copyright 2016-2024 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 : */