Line data Source code
1 : /* File: data_id.inl; Copyright and License: see below */
2 :
3 : #include "u8/u8_trace.h"
4 : #include "u8/u8_log.h"
5 : #include "utf8stringbuf/utf8string.h"
6 :
7 2326 : static inline void data_id_init ( data_id_t *this_, data_table_t table, data_row_id_t row_id )
8 : {
9 2326 : (*this_).table = table;
10 2326 : (*this_).row_id = row_id;
11 2326 : }
12 :
13 0 : static inline void data_id_init_by_string ( data_id_t *this_, const char* string_to_parse )
14 : {
15 : size_t dummy_length;
16 0 : data_id_init_by_string_region ( this_, string_to_parse, 0, &dummy_length );
17 0 : }
18 :
19 12 : static inline void data_id_init_by_string_region ( data_id_t *this_,
20 : const char* string_to_parse,
21 : size_t start,
22 : size_t *out_length )
23 : {
24 12 : if ( string_to_parse == NULL )
25 : {
26 0 : (*this_).table = DATA_TABLE_VOID;
27 0 : (*this_).row_id = DATA_ROW_ID_VOID;
28 : }
29 : else
30 : {
31 12 : switch ( string_to_parse[start] )
32 : {
33 0 : case DATA_TABLE_ALPHANUM_CLASSIFIER:
34 : {
35 0 : (*this_).table = DATA_TABLE_CLASSIFIER;
36 : }
37 0 : break;
38 :
39 0 : case DATA_TABLE_ALPHANUM_FEATURE:
40 : {
41 0 : (*this_).table = DATA_TABLE_FEATURE;
42 : }
43 0 : break;
44 :
45 0 : case DATA_TABLE_ALPHANUM_RELATIONSHIP:
46 : {
47 0 : (*this_).table = DATA_TABLE_RELATIONSHIP;
48 : }
49 0 : break;
50 :
51 0 : case DATA_TABLE_ALPHANUM_DIAGRAMELEMENT:
52 : {
53 0 : (*this_).table = DATA_TABLE_DIAGRAMELEMENT;
54 : }
55 0 : break;
56 :
57 12 : case DATA_TABLE_ALPHANUM_DIAGRAM:
58 : {
59 12 : (*this_).table = DATA_TABLE_DIAGRAM;
60 : }
61 12 : break;
62 :
63 0 : default:
64 : {
65 0 : (*this_).table = DATA_TABLE_VOID;
66 : }
67 0 : break;
68 : }
69 :
70 12 : if ( (*this_).table == DATA_TABLE_VOID )
71 : {
72 0 : (*this_).row_id = DATA_ROW_ID_VOID;
73 : }
74 : else
75 : {
76 12 : const char* int_to_parse = string_to_parse+start+1;
77 : unsigned int byte_length;
78 : int64_t number;
79 12 : utf8error_t u8err = utf8string_parse_int( int_to_parse, &byte_length, &number );
80 12 : if (( u8err == UTF8ERROR_SUCCESS )&&( byte_length >= 4 )) {
81 5 : (*this_).row_id = number;
82 5 : *out_length = byte_length+1;
83 : }
84 : else {
85 7 : (*this_).table = DATA_TABLE_VOID;
86 7 : (*this_).row_id = DATA_ROW_ID_VOID;
87 7 : *out_length = 0;
88 : }
89 : }
90 : }
91 12 : }
92 :
93 1 : static inline void data_id_reinit ( data_id_t *this_, data_table_t table, data_row_id_t row_id )
94 : {
95 1 : (*this_).table = table;
96 1 : (*this_).row_id = row_id;
97 1 : }
98 :
99 1 : static inline void data_id_init_void ( data_id_t *this_ )
100 : {
101 1 : (*this_).table = DATA_TABLE_VOID;
102 1 : (*this_).row_id = DATA_ROW_ID_VOID;
103 1 : }
104 :
105 15 : static inline void data_id_reinit_void ( data_id_t *this_ )
106 : {
107 15 : (*this_).table = DATA_TABLE_VOID;
108 15 : (*this_).row_id = DATA_ROW_ID_VOID;
109 15 : }
110 :
111 0 : static inline void data_id_copy ( data_id_t *this_, const data_id_t *that )
112 : {
113 0 : (*this_) = (*that);
114 0 : }
115 :
116 0 : static inline void data_id_replace ( data_id_t *this_, const data_id_t *that )
117 : {
118 0 : (*this_) = (*that);
119 0 : }
120 :
121 2126 : static inline void data_id_destroy ( data_id_t *this_ )
122 : {
123 2126 : (*this_).table = DATA_TABLE_VOID;
124 2126 : (*this_).row_id = DATA_ROW_ID_VOID;
125 2126 : }
126 :
127 98 : static inline data_table_t data_id_get_table ( const data_id_t *this_ )
128 : {
129 98 : return (*this_).table;
130 : }
131 :
132 138 : static inline data_row_id_t data_id_get_row_id ( const data_id_t *this_ )
133 : {
134 138 : return (*this_).row_id;
135 : }
136 :
137 1924 : static inline void data_id_trace ( const data_id_t *this_ )
138 : {
139 1924 : const char prefix[] = "data_id_t: ";
140 : char id_buf[sizeof(prefix)+DATA_ID_MAX_UTF8STRING_LENGTH];
141 1924 : utf8stringbuf_t id_str = UTF8STRINGBUF( id_buf );
142 1924 : utf8stringbuf_copy_str( id_str, prefix );
143 1924 : data_id_to_utf8stringbuf( this_, id_str );
144 1924 : U8_TRACE_INFO( utf8stringbuf_get_string( id_str ) );
145 1924 : }
146 :
147 33412 : static inline bool data_id_equals ( const data_id_t *this_, const data_id_t *that )
148 : {
149 33410 : return ( ( DATA_ROW_ID_VOID != (*this_).row_id )&&( DATA_TABLE_VOID != (*this_).table )
150 66822 : &&( (*this_).row_id == (*that).row_id )&&( (*this_).table == (*that).table ) );
151 : }
152 :
153 0 : static inline bool data_id_equals_or_both_void ( const data_id_t *this_, const data_id_t *that )
154 : {
155 0 : const bool one_or_both_valid = data_id_is_valid( this_ ) || data_id_is_valid( that );
156 0 : return ( ! one_or_both_valid ) || (( (*this_).row_id == (*that).row_id )&&( (*this_).table == (*that).table ));
157 : }
158 :
159 237 : static inline bool data_id_is_valid ( const data_id_t *this_ )
160 : {
161 237 : return (( DATA_ROW_ID_VOID != (*this_).row_id )&&( DATA_TABLE_VOID != (*this_).table ));
162 : }
163 :
164 0 : static inline bool data_id_equals_id ( const data_id_t *this_, data_table_t table, data_row_id_t row_id )
165 : {
166 0 : return ( ( DATA_ROW_ID_VOID != (*this_).row_id )&&( DATA_TABLE_VOID != (*this_).table )
167 0 : &&( (*this_).row_id == row_id )&&( (*this_).table == table ) );
168 : }
169 :
170 1926 : static inline utf8error_t data_id_to_utf8stringbuf ( const data_id_t *this_, utf8stringbuf_t out_str )
171 : {
172 1926 : utf8error_t result = UTF8ERROR_SUCCESS;
173 1926 : switch ( (*this_).table )
174 : {
175 731 : case DATA_TABLE_VOID:
176 : {
177 731 : result |= utf8stringbuf_append_str( out_str, "void" );
178 : }
179 731 : break;
180 :
181 207 : case DATA_TABLE_CLASSIFIER:
182 : {
183 207 : result |= utf8stringbuf_append_str( out_str, "C" );
184 : }
185 207 : break;
186 :
187 98 : case DATA_TABLE_FEATURE:
188 : {
189 98 : result |= utf8stringbuf_append_str( out_str, "F" );
190 : }
191 98 : break;
192 :
193 68 : case DATA_TABLE_RELATIONSHIP:
194 : {
195 68 : result |= utf8stringbuf_append_str( out_str, "R" );
196 : }
197 68 : break;
198 :
199 145 : case DATA_TABLE_DIAGRAMELEMENT:
200 : {
201 145 : result |= utf8stringbuf_append_str( out_str, "E" );
202 : }
203 145 : break;
204 :
205 677 : case DATA_TABLE_DIAGRAM:
206 : {
207 677 : result |= utf8stringbuf_append_str( out_str, "D" );
208 : }
209 677 : break;
210 :
211 0 : default:
212 : {
213 0 : U8_LOG_ERROR( "data_id_to_utf8stringbuf has incomplete switch on data_table_t" );
214 : }
215 0 : break;
216 : }
217 :
218 1926 : if ( (*this_).table != DATA_TABLE_VOID )
219 : {
220 1195 : if ( 100 > (*this_).row_id )
221 : {
222 1099 : if ( 10 > (*this_).row_id )
223 : {
224 640 : if ( 0 <= (*this_).row_id )
225 : {
226 580 : result |= utf8stringbuf_append_str( out_str, "000" );
227 : }
228 : else
229 : {
230 : /* row_id is negative */
231 : }
232 : }
233 : else
234 : {
235 459 : result |= utf8stringbuf_append_str( out_str, "00" );
236 : }
237 : }
238 : else
239 : {
240 96 : if ( 1000 > (*this_).row_id )
241 : {
242 82 : result |= utf8stringbuf_append_str( out_str, "0" );
243 : }
244 : else
245 : {
246 : /* row_id is greater than 1000 */
247 : }
248 : }
249 1195 : result |= utf8stringbuf_append_int( out_str, (*this_).row_id );
250 : }
251 :
252 1926 : return result;
253 : }
254 :
255 6 : static inline u8_error_t data_id_to_utf8_writer ( const data_id_t *this_, utf8stream_writer_t *out_writer )
256 : {
257 6 : u8_error_t result = U8_ERROR_NONE;
258 6 : switch ( (*this_).table )
259 : {
260 0 : case DATA_TABLE_VOID:
261 : {
262 0 : result |= utf8stream_writer_write_str( out_writer, "void" );
263 : }
264 0 : break;
265 :
266 0 : case DATA_TABLE_CLASSIFIER:
267 : {
268 0 : result |= utf8stream_writer_write_str( out_writer, "C" );
269 : }
270 0 : break;
271 :
272 2 : case DATA_TABLE_FEATURE:
273 : {
274 2 : result |= utf8stream_writer_write_str( out_writer, "F" );
275 : }
276 2 : break;
277 :
278 4 : case DATA_TABLE_RELATIONSHIP:
279 : {
280 4 : result |= utf8stream_writer_write_str( out_writer, "R" );
281 : }
282 4 : break;
283 :
284 0 : case DATA_TABLE_DIAGRAMELEMENT:
285 : {
286 0 : result |= utf8stream_writer_write_str( out_writer, "E" );
287 : }
288 0 : break;
289 :
290 0 : case DATA_TABLE_DIAGRAM:
291 : {
292 0 : result |= utf8stream_writer_write_str( out_writer, "D" );
293 : }
294 0 : break;
295 :
296 0 : default:
297 : {
298 0 : U8_LOG_ERROR( "data_id_to_utf8_writer has incomplete switch on data_table_t" );
299 : }
300 0 : break;
301 : }
302 :
303 6 : if ( (*this_).table != DATA_TABLE_VOID )
304 : {
305 6 : if ( 100 > (*this_).row_id )
306 : {
307 6 : if ( 10 > (*this_).row_id )
308 : {
309 0 : if ( 0 <= (*this_).row_id )
310 : {
311 0 : result |= utf8stream_writer_write_str( out_writer, "000" );
312 : }
313 : else
314 : {
315 : /* row_id is negative */
316 : }
317 : }
318 : else
319 : {
320 6 : result |= utf8stream_writer_write_str( out_writer, "00" );
321 : }
322 : }
323 : else
324 : {
325 0 : if ( 1000 > (*this_).row_id )
326 : {
327 0 : result |= utf8stream_writer_write_str( out_writer, "0" );
328 : }
329 : else
330 : {
331 : /* row_id is greater than 1000 */
332 : }
333 : }
334 6 : result |= utf8stream_writer_write_int( out_writer, (*this_).row_id );
335 : }
336 :
337 6 : return result;
338 : }
339 :
340 :
341 : /*
342 : Copyright 2016-2024 Andreas Warnke
343 :
344 : Licensed under the Apache License, Version 2.0 (the "License");
345 : you may not use this file except in compliance with the License.
346 : You may obtain a copy of the License at
347 :
348 : http://www.apache.org/licenses/LICENSE-2.0
349 :
350 : Unless required by applicable law or agreed to in writing, software
351 : distributed under the License is distributed on an "AS IS" BASIS,
352 : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
353 : See the License for the specific language governing permissions and
354 : limitations under the License.
355 : */
|