Line data Source code
1 : /* File: data_feature.inl; Copyright and License: see below */
2 :
3 : #include "data_id.h"
4 : #include <assert.h>
5 :
6 78 : static inline void data_feature_init_empty ( data_feature_t *this_ )
7 : {
8 78 : (*this_).id = DATA_ROW_ID_VOID;
9 78 : (*this_).classifier_id = DATA_ROW_ID_VOID;
10 78 : (*this_).main_type = DATA_FEATURE_TYPE_PROPERTY;
11 :
12 78 : (*this_).key = utf8stringbuf_init( sizeof((*this_).private_key_buffer), (*this_).private_key_buffer );
13 78 : utf8stringbuf_clear( (*this_).key );
14 78 : (*this_).value = utf8stringbuf_init( sizeof((*this_).private_value_buffer), (*this_).private_value_buffer );
15 78 : utf8stringbuf_clear( (*this_).value );
16 78 : (*this_).description = utf8stringbuf_init( sizeof((*this_).private_description_buffer), (*this_).private_description_buffer );
17 78 : utf8stringbuf_clear( (*this_).description );
18 :
19 78 : (*this_).list_order = 0;
20 78 : data_uuid_init_new( &((*this_).uuid) );
21 78 : }
22 :
23 0 : static inline void data_feature_reinit_empty ( data_feature_t *this_ )
24 : {
25 : /* data_feature_destroy( this_ ); -- not necessary */
26 0 : data_feature_init_empty( this_ );
27 0 : }
28 :
29 18 : static inline u8_error_t data_feature_init_new ( data_feature_t *this_,
30 : data_feature_type_t feature_main_type,
31 : data_row_id_t classifier_id,
32 : const char* feature_key,
33 : const char* feature_value,
34 : const char* feature_description,
35 : int32_t list_order )
36 : {
37 18 : assert( NULL != feature_key );
38 18 : assert( NULL != feature_value );
39 18 : assert( NULL != feature_description );
40 : utf8error_t strerr;
41 18 : u8_error_t result = U8_ERROR_NONE;
42 :
43 18 : (*this_).id = DATA_ROW_ID_VOID;
44 18 : (*this_).classifier_id = classifier_id;
45 18 : (*this_).main_type = feature_main_type;
46 :
47 18 : (*this_).key = utf8stringbuf_init( sizeof((*this_).private_key_buffer), (*this_).private_key_buffer );
48 18 : strerr = utf8stringbuf_copy_str( (*this_).key, feature_key );
49 18 : if ( strerr != UTF8ERROR_SUCCESS )
50 : {
51 0 : U8_LOG_ERROR_INT( "utf8stringbuf_copy_str() failed:", strerr );
52 0 : result |= U8_ERROR_STRING_BUFFER_EXCEEDED;
53 : }
54 :
55 18 : (*this_).value = utf8stringbuf_init( sizeof((*this_).private_value_buffer), (*this_).private_value_buffer );
56 18 : strerr = utf8stringbuf_copy_str( (*this_).value, feature_value );
57 18 : if ( strerr != UTF8ERROR_SUCCESS )
58 : {
59 0 : U8_LOG_ERROR_INT( "utf8stringbuf_copy_str() failed:", strerr );
60 0 : result |= U8_ERROR_STRING_BUFFER_EXCEEDED;
61 : }
62 :
63 18 : (*this_).description = utf8stringbuf_init( sizeof((*this_).private_description_buffer), (*this_).private_description_buffer );
64 18 : strerr = utf8stringbuf_copy_str( (*this_).description, feature_description );
65 18 : if ( strerr != UTF8ERROR_SUCCESS )
66 : {
67 0 : U8_LOG_ERROR_HEX( "utf8stringbuf_copy_str() failed:", strerr );
68 0 : result |= U8_ERROR_STRING_BUFFER_EXCEEDED;
69 : }
70 :
71 18 : (*this_).list_order = list_order;
72 18 : data_uuid_init_new( &((*this_).uuid) );
73 :
74 18 : return result;
75 : }
76 :
77 1398 : static inline u8_error_t data_feature_init ( data_feature_t *this_,
78 : data_row_id_t feature_id,
79 : data_feature_type_t feature_main_type,
80 : data_row_id_t classifier_id,
81 : const char* feature_key,
82 : const char* feature_value,
83 : const char* feature_description,
84 : int32_t list_order,
85 : const char* uuid )
86 : {
87 1398 : assert( NULL != feature_key );
88 1398 : assert( NULL != feature_value );
89 1398 : assert( NULL != feature_description );
90 1398 : assert( NULL != uuid );
91 : utf8error_t strerr;
92 1398 : u8_error_t result = U8_ERROR_NONE;
93 :
94 1398 : (*this_).id = feature_id;
95 1398 : (*this_).classifier_id = classifier_id;
96 1398 : (*this_).main_type = feature_main_type;
97 :
98 1398 : (*this_).key = utf8stringbuf_init( sizeof((*this_).private_key_buffer), (*this_).private_key_buffer );
99 1398 : strerr = utf8stringbuf_copy_str( (*this_).key, feature_key );
100 1398 : if ( strerr != UTF8ERROR_SUCCESS )
101 : {
102 0 : U8_LOG_ERROR_INT( "utf8stringbuf_copy_str() failed:", strerr );
103 0 : result |= U8_ERROR_STRING_BUFFER_EXCEEDED;
104 : }
105 :
106 1398 : (*this_).value = utf8stringbuf_init( sizeof((*this_).private_value_buffer), (*this_).private_value_buffer );
107 1398 : strerr = utf8stringbuf_copy_str( (*this_).value, feature_value );
108 1398 : if ( strerr != UTF8ERROR_SUCCESS )
109 : {
110 0 : U8_LOG_ERROR_INT( "utf8stringbuf_copy_str() failed:", strerr );
111 0 : result |= U8_ERROR_STRING_BUFFER_EXCEEDED;
112 : }
113 :
114 1398 : (*this_).description = utf8stringbuf_init( sizeof((*this_).private_description_buffer), (*this_).private_description_buffer );
115 1398 : strerr = utf8stringbuf_copy_str( (*this_).description, feature_description );
116 1398 : if ( strerr != UTF8ERROR_SUCCESS )
117 : {
118 0 : U8_LOG_ERROR_HEX( "utf8stringbuf_copy_str() failed:", strerr );
119 0 : result |= U8_ERROR_STRING_BUFFER_EXCEEDED;
120 : }
121 :
122 1398 : (*this_).list_order = list_order;
123 1398 : result |= data_uuid_init( &((*this_).uuid), uuid );
124 :
125 1398 : return result;
126 : }
127 :
128 49 : static inline void data_feature_copy ( data_feature_t *this_, const data_feature_t *original )
129 : {
130 49 : assert( NULL != original );
131 :
132 49 : (*this_) = (*original);
133 : /* repair the overwritten pointers */
134 49 : (*this_).key = utf8stringbuf_init( sizeof((*this_).private_key_buffer), (*this_).private_key_buffer );
135 49 : (*this_).value = utf8stringbuf_init( sizeof((*this_).private_value_buffer), (*this_).private_value_buffer );
136 49 : (*this_).description = utf8stringbuf_init( sizeof((*this_).private_description_buffer), (*this_).private_description_buffer );
137 49 : data_uuid_copy( &((*this_).uuid), &((*original).uuid) );
138 49 : }
139 :
140 55 : static inline void data_feature_replace ( data_feature_t *this_, const data_feature_t *that )
141 : {
142 55 : assert( NULL != that );
143 :
144 55 : (*this_) = (*that);
145 : /* repair the overwritten pointers */
146 55 : (*this_).key = utf8stringbuf_init( sizeof((*this_).private_key_buffer), (*this_).private_key_buffer );
147 55 : (*this_).value = utf8stringbuf_init( sizeof((*this_).private_value_buffer), (*this_).private_value_buffer );
148 55 : (*this_).description = utf8stringbuf_init( sizeof((*this_).private_description_buffer), (*this_).private_description_buffer );
149 55 : data_uuid_replace( &((*this_).uuid), &((*that).uuid) );
150 55 : }
151 :
152 140 : static inline void data_feature_destroy ( data_feature_t *this_ )
153 : {
154 140 : (*this_).id = DATA_ROW_ID_VOID;
155 140 : data_uuid_destroy( &((*this_).uuid) );
156 140 : }
157 :
158 598971 : static inline data_row_id_t data_feature_get_row_id ( const data_feature_t *this_ )
159 : {
160 598971 : return (*this_).id;
161 : }
162 :
163 64 : static inline void data_feature_set_row_id ( data_feature_t *this_, data_row_id_t id )
164 : {
165 64 : (*this_).id = id;
166 64 : }
167 :
168 2 : static inline data_id_t data_feature_get_data_id ( const data_feature_t *this_ )
169 : {
170 : data_id_t result;
171 2 : data_id_init ( &result, DATA_TABLE_FEATURE, (*this_).id );
172 2 : return result;
173 : }
174 :
175 34411 : static inline data_row_id_t data_feature_get_classifier_row_id ( const data_feature_t *this_ )
176 : {
177 34411 : return (*this_).classifier_id;
178 : }
179 :
180 10 : static inline void data_feature_set_classifier_row_id ( data_feature_t *this_, data_row_id_t classifier_id )
181 : {
182 10 : (*this_).classifier_id = classifier_id;
183 10 : }
184 :
185 0 : static inline data_id_t data_feature_get_classifier_data_id ( const data_feature_t *this_ )
186 : {
187 : data_id_t result;
188 0 : data_id_init ( &result, DATA_TABLE_CLASSIFIER, (*this_).classifier_id );
189 0 : return result;
190 : }
191 :
192 33709 : static inline data_feature_type_t data_feature_get_main_type ( const data_feature_t *this_ )
193 : {
194 33709 : return (*this_).main_type;
195 : }
196 :
197 24 : static inline void data_feature_set_main_type ( data_feature_t *this_, data_feature_type_t main_type )
198 : {
199 24 : (*this_).main_type = main_type;
200 24 : }
201 :
202 68 : static inline const char *data_feature_get_key_const ( const data_feature_t *this_ )
203 : {
204 68 : return utf8stringbuf_get_string( (*this_).key );
205 : }
206 :
207 23 : static inline u8_error_t data_feature_set_key ( data_feature_t *this_, const char *key )
208 : {
209 23 : assert( NULL != key );
210 23 : u8_error_t result = U8_ERROR_NONE;
211 : utf8error_t strerr;
212 23 : strerr = utf8stringbuf_copy_str( (*this_).key, key );
213 23 : if ( strerr != UTF8ERROR_SUCCESS )
214 : {
215 0 : U8_LOG_ERROR_HEX( "utf8stringbuf_copy_str() failed:", strerr );
216 0 : result = U8_ERROR_STRING_BUFFER_EXCEEDED;
217 : }
218 23 : return result;
219 : }
220 :
221 70 : static inline const char *data_feature_get_value_const ( const data_feature_t *this_ )
222 : {
223 70 : return utf8stringbuf_get_string( (*this_).value );
224 : }
225 :
226 0 : static inline bool data_feature_has_value ( const data_feature_t *this_ )
227 : {
228 0 : return ( ! utf8stringbuf_equals_str( (*this_).value, "" ) );
229 : }
230 :
231 24 : static inline u8_error_t data_feature_set_value ( data_feature_t *this_, const char *value )
232 : {
233 24 : assert( NULL != value );
234 24 : u8_error_t result = U8_ERROR_NONE;
235 : utf8error_t strerr;
236 24 : strerr = utf8stringbuf_copy_str( (*this_).value, value );
237 24 : if ( strerr != UTF8ERROR_SUCCESS )
238 : {
239 0 : U8_LOG_ERROR_HEX( "utf8stringbuf_copy_str() failed:", strerr );
240 0 : result = U8_ERROR_STRING_BUFFER_EXCEEDED;
241 : }
242 24 : return result;
243 : }
244 :
245 68 : static inline const char *data_feature_get_description_const ( const data_feature_t *this_ )
246 : {
247 68 : return utf8stringbuf_get_string( (*this_).description );
248 : }
249 :
250 23 : static inline u8_error_t data_feature_set_description ( data_feature_t *this_, const char *description )
251 : {
252 23 : assert( NULL != description );
253 23 : u8_error_t result = U8_ERROR_NONE;
254 : utf8error_t strerr;
255 23 : strerr = utf8stringbuf_copy_str( (*this_).description, description );
256 23 : if ( strerr != UTF8ERROR_SUCCESS )
257 : {
258 0 : U8_LOG_ERROR_HEX( "utf8stringbuf_copy_str() failed:", strerr );
259 0 : result = U8_ERROR_STRING_BUFFER_EXCEEDED;
260 : }
261 23 : return result;
262 : }
263 :
264 : static inline u8_error_t data_feature_append_description ( data_feature_t *this_, const char *description )
265 : {
266 : assert( NULL != description );
267 : u8_error_t result = U8_ERROR_NONE;
268 : utf8error_t strerr;
269 : strerr = utf8stringbuf_append_str( (*this_).description, description );
270 : if ( strerr != UTF8ERROR_SUCCESS )
271 : {
272 : U8_LOG_ERROR_HEX( "utf8stringbuf_append_str() failed:", strerr );
273 : result = U8_ERROR_STRING_BUFFER_EXCEEDED;
274 : }
275 : return result;
276 : }
277 :
278 68 : static inline int32_t data_feature_get_list_order ( const data_feature_t *this_ )
279 : {
280 68 : return (*this_).list_order;
281 : }
282 :
283 23 : static inline void data_feature_set_list_order ( data_feature_t *this_, int32_t list_order )
284 : {
285 23 : (*this_).list_order = list_order;
286 23 : }
287 :
288 91 : static inline const char *data_feature_get_uuid_const ( const data_feature_t *this_ )
289 : {
290 91 : return data_uuid_get_string( &((*this_).uuid) );
291 : }
292 :
293 11 : static inline u8_error_t data_feature_set_uuid ( data_feature_t *this_, const char *uuid )
294 : {
295 11 : assert( NULL != uuid );
296 :
297 11 : const u8_error_t result = data_uuid_reinit( &((*this_).uuid), uuid );
298 :
299 11 : return result;
300 : }
301 :
302 35893 : static inline bool data_feature_is_valid ( const data_feature_t *this_ )
303 : {
304 35893 : return ( DATA_ROW_ID_VOID != (*this_).id );
305 : }
306 :
307 66 : static inline void data_feature_trace ( const data_feature_t *this_ )
308 : {
309 66 : U8_TRACE_INFO( "data_feature_t" );
310 66 : U8_TRACE_INFO_INT( "- id:", (*this_).id );
311 66 : U8_TRACE_INFO_INT( "- main_type:", (*this_).main_type );
312 66 : U8_TRACE_INFO_INT( "- classifier_id:", (*this_).classifier_id );
313 66 : U8_TRACE_INFO_STR( "- key:", utf8stringbuf_get_string((*this_).key) );
314 66 : U8_TRACE_INFO_STR( "- value:", utf8stringbuf_get_string((*this_).value) );
315 66 : U8_TRACE_INFO_STR( "- description:", utf8stringbuf_get_string((*this_).description) );
316 66 : U8_TRACE_INFO_INT( "- list_order:", (*this_).list_order );
317 66 : U8_TRACE_INFO_STR( "- uuid:", data_uuid_get_string( &((*this_).uuid) ) );
318 66 : }
319 :
320 :
321 : /*
322 : Copyright 2016-2024 Andreas Warnke
323 :
324 : Licensed under the Apache License, Version 2.0 (the "License");
325 : you may not use this file except in compliance with the License.
326 : You may obtain a copy of the License at
327 :
328 : http://www.apache.org/licenses/LICENSE-2.0
329 :
330 : Unless required by applicable law or agreed to in writing, software
331 : distributed under the License is distributed on an "AS IS" BASIS,
332 : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
333 : See the License for the specific language governing permissions and
334 : limitations under the License.
335 : */
|