Line data Source code
1 : /* File: data_node_set.c; Copyright and License: see below */ 2 : 3 : #include "set/data_node_set.h" 4 : #include "u8/u8_trace.h" 5 : #include <stdio.h> 6 : #include <stdlib.h> 7 : #include <assert.h> 8 : 9 3 : void data_node_set_init( data_node_set_t *this_ ) 10 : { 11 3 : U8_TRACE_BEGIN(); 12 3 : U8_TRACE_INFO_INT( "sizeof(data_node_set_t):", sizeof(data_node_set_t) ); 13 : 14 3 : data_classifier_init_empty( &((*this_).classifier) ); 15 3 : (*this_).feature_count = 0; 16 3 : (*this_).relationship_count = 0; 17 : 18 3 : U8_TRACE_END(); 19 3 : } 20 : 21 2 : void data_node_set_destroy( data_node_set_t *this_ ) 22 : { 23 2 : U8_TRACE_BEGIN(); 24 : 25 2 : data_classifier_destroy( &((*this_).classifier) ); 26 2 : data_node_set_private_destroy_features( this_ ); 27 2 : data_node_set_private_destroy_relationships( this_ ); 28 : 29 2 : U8_TRACE_END(); 30 2 : } 31 : 32 3 : u8_error_t data_node_set_load( data_node_set_t *this_, data_row_id_t classifier_id, data_database_reader_t *db_reader ) 33 : { 34 3 : U8_TRACE_BEGIN(); 35 3 : assert( NULL != db_reader ); 36 3 : u8_error_t result = U8_ERROR_NONE; 37 : 38 3 : if ( DATA_ROW_ID_VOID == classifier_id ) 39 : { 40 : /* re-init */ 41 0 : data_classifier_reinit_empty( &((*this_).classifier) ); 42 : 43 0 : data_node_set_private_destroy_features( this_ ); 44 0 : data_node_set_private_destroy_relationships( this_ ); 45 : } 46 : else 47 : { 48 : u8_error_t db_err; 49 : 50 3 : data_classifier_destroy( &((*this_).classifier) ); 51 3 : data_node_set_private_destroy_features( this_ ); 52 3 : data_node_set_private_destroy_relationships( this_ ); 53 : 54 : /* load classifier */ 55 3 : db_err = data_database_reader_get_classifier_by_id ( db_reader, classifier_id, &((*this_).classifier) ); 56 : 57 3 : if ( u8_error_contains(db_err, U8_ERROR_STRING_BUFFER_EXCEEDED ) ) 58 : { 59 0 : U8_LOG_ERROR( "U8_ERROR_STRING_BUFFER_EXCEEDED at loading visible classifiers of a diagram" ); 60 : } 61 3 : if ( u8_error_contains( db_err, U8_ERROR_ARRAY_BUFFER_EXCEEDED ) ) 62 : { 63 0 : U8_LOG_ERROR( "U8_ERROR_ARRAY_BUFFER_EXCEEDED at loading visible classifiers of a diagram" ); 64 : } 65 3 : if ( u8_error_more_than( db_err, U8_ERROR_STRING_BUFFER_EXCEEDED|U8_ERROR_ARRAY_BUFFER_EXCEEDED ) ) 66 : { 67 : /* error at loading */ 68 1 : data_classifier_reinit_empty( &((*this_).classifier) ); 69 : } 70 3 : result |= db_err; /* collect error flags */ 71 : 72 : /* load features */ 73 3 : db_err = data_database_reader_get_features_by_classifier_id ( db_reader, 74 : classifier_id, 75 : DATA_NODE_SET_MAX_FEATURES, 76 3 : &((*this_).features), 77 : &((*this_).feature_count) 78 : ); 79 : 80 3 : if ( u8_error_contains( db_err, U8_ERROR_STRING_BUFFER_EXCEEDED ) ) 81 : { 82 0 : U8_LOG_ERROR( "U8_ERROR_STRING_BUFFER_EXCEEDED at loading features of a diagram" ); 83 : } 84 3 : if ( u8_error_contains( db_err, U8_ERROR_ARRAY_BUFFER_EXCEEDED ) ) 85 : { 86 1 : U8_LOG_ERROR( "U8_ERROR_ARRAY_BUFFER_EXCEEDED at loading features of a diagram" ); 87 : } 88 3 : if ( u8_error_more_than( db_err, U8_ERROR_STRING_BUFFER_EXCEEDED|U8_ERROR_ARRAY_BUFFER_EXCEEDED ) ) 89 : { 90 : /* error at loading */ 91 0 : (*this_).feature_count = 0; 92 : } 93 3 : result |= db_err; /* collect error flags */ 94 : 95 : /* load relationships */ 96 3 : db_err = data_database_reader_get_relationships_by_classifier_id ( db_reader, 97 : classifier_id, 98 : DATA_NODE_SET_MAX_RELATIONSHIPS, 99 3 : &((*this_).relationships), 100 : &((*this_).relationship_count) 101 : ); 102 : 103 3 : if ( u8_error_contains( db_err, U8_ERROR_STRING_BUFFER_EXCEEDED ) ) 104 : { 105 0 : U8_LOG_ERROR( "U8_ERROR_STRING_BUFFER_EXCEEDED at loading relationships of a diagram" ); 106 : } 107 3 : if ( u8_error_contains( db_err, U8_ERROR_ARRAY_BUFFER_EXCEEDED ) ) 108 : { 109 1 : U8_LOG_ERROR( "U8_ERROR_ARRAY_BUFFER_EXCEEDED at loading relationships of a diagram" ); 110 : } 111 3 : if ( u8_error_more_than( db_err, U8_ERROR_STRING_BUFFER_EXCEEDED|U8_ERROR_ARRAY_BUFFER_EXCEEDED ) ) 112 : { 113 : /* error at loading */ 114 0 : (*this_).relationship_count = 0; 115 : } 116 3 : result |= db_err; /* collect error flags */ 117 : } 118 : 119 3 : U8_TRACE_END_ERR(result); 120 3 : return result; 121 : } 122 : 123 : 124 : /* 125 : Copyright 2020-2024 Andreas Warnke 126 : 127 : Licensed under the Apache License, Version 2.0 (the "License"); 128 : you may not use this file except in compliance with the License. 129 : You may obtain a copy of the License at 130 : 131 : http://www.apache.org/licenses/LICENSE-2.0 132 : 133 : Unless required by applicable law or agreed to in writing, software 134 : distributed under the License is distributed on an "AS IS" BASIS, 135 : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 136 : See the License for the specific language governing permissions and 137 : limitations under the License. 138 : */