libmetaref
metaref.h
Go to the documentation of this file.
1 
13 #ifndef __COUNTER__
14  #error This library is not supported with this compiler. Use any compiler with __COUNTER__ macro declared
15  #include <metaref_not_supported_with_no___COUNTER__>
16 #endif
17 
18 #ifndef EXOTIC_METAREF_STRUCT
19 #ifdef __STRUCT_FILE__
20 #ifndef __STRUCT_NAME__
21  #error You need to declare the struct name value before including metaref.h
22 #endif
23 #define EXOTIC_METAREF_STRUCT
24 
25 #ifndef __cplusplus
26 #ifndef __STDC_VERSION__
27  #error This library is not supported in C version less than C99.
28  #include <metaref_not_supported_in_standard_less_than_C99>
29 #endif
30 #endif
31 
32 #ifdef __cplusplus
33 #if __cplusplus <= 199711L
34  #error This library is not supported in C++ version less than C++11.
35  #include <metaref_not_supported_in_standard_less_than_C++11>
36 #endif
37 #endif
38 
39 #ifdef METAREF_PREPROCESSING_DONE
40 #undef METAREF_PREPROCESSING_DONE
41 #endif
42 
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46 
47 #ifndef METAREF_FIELD_PTR_ADDRESS_TYPE
48 #define METAREF_FIELD_PTR_ADDRESS_TYPE void **
49 #endif
50 
51 #ifndef METAREF_STRUCTS_DECLARED
52 #define METAREF_STRUCTS_DECLARED
53 
57 #define METAREF_CONCAT_IMPL(x,y ) x##y
58 
62 #define METAREF_CONCAT(x,y) METAREF_CONCAT_IMPL(x,y)
63 
69 typedef void *(*func_ptr_)(const void *);
70 
71 typedef enum metaref_annotation_type_ {
72  METAREF_ANNOTATION_STRING,
73  METAREF_ANNOTATION_INT,
74  METAREF_ANNOTATION_LONG,
75  METAREF_ANNOTATION_FUNCTION,
76  METAREF_ANNOTATION_TERMINATOR
77 } AnnotationType;
78 
79 // TODO Use union for the multiple value instead of fields
83 typedef struct annotation_struct_ {
84  const size_t line_num;
85  const AnnotationType type;
86  const char *name;
87  const char *str_value;
88  int int_value;
89  long long long_value;
90  func_ptr_ func_ptr;
91 } Annotation;
92 
135 typedef struct field_struct_ {
136  const size_t line_num;
137  const char *type;
138  const char *name;
139  METAREF_FIELD_PTR_ADDRESS_TYPE ptr_address;
140  const Annotation annotations[10];
141 } Field;
142 
146 typedef struct metaref_struct_ {
147  const char *name;
148  const char *file_name;
149  size_t line_num;
150  const Field *fields_array;
151  const Annotation *annotations_array;
152 } Struct;
153 
157 static unsigned metaref_str_equals(const char* arg, const char* arg1) {
158  unsigned i = 0;
159  if (arg == NULL || arg1 == NULL) {
160  return 0;
161  }
162  while (1) {
163  if (arg[i] == '\0' && arg1[i] == '\0') {
164  break;
165  }
166  if (arg[i] != arg1[i]) {
167  return 0;
168  }
169  ++i;
170  }
171  return 1;
172 }
173 
174 static Annotation inline metaref_get_field_annotation(Field field, const char *name) {
175  for(int _iter_index = 0; field.annotations[_iter_index].line_num != 0; ++_iter_index) {
176  if (metaref_str_equals(field.annotations[_iter_index].name, name)) {
177  return field.annotations[_iter_index];
178  }
179  }
180  Annotation METAREF_sub_annotation__ = {0, METAREF_ANNOTATION_TERMINATOR, NULL, NULL, -1, -1, NULL};
181  return METAREF_sub_annotation__ ;
182 }
183 
184 static Field metaref_struct_get_field(Struct *the_struct, const char *name) {
185  for(size_t i = 0; the_struct->fields_array[i].type != NULL; ++i) {
186  if (metaref_str_equals(the_struct->fields_array[i].name, name)) {
187  return the_struct->fields_array[i];
188  }
189  }
190  Field METAREF_sub_fields1__ = {0, NULL, NULL, NULL, {}};
191  return METAREF_sub_fields1__;
192 }
193 #endif
194 
195 /* FIRST EXAPNSION
196  -------------------
197 
198  Declare the struct meta fields for
199  introspection.
200 */
201 #ifdef STRUCT
202  #undef STRUCT
203  #undef FIELD
204  #undef _S
205  #undef _I
206  #undef _L
207  #undef _F
208  #undef _FS
209  #undef _FI
210  #undef _FL
211  #undef _FF
212 #endif
213 
220 #define STRUCT(struct_name, ...) \
221  typedef struct METAREF_##struct_name { \
222  __VA_ARGS__ \
223  Struct *metaref_obj; \
224  } struct_name;\
225 
226 
229 #define FIELD(annotations, type_v, identifier) \
230  type_v identifier;
231 
250 #define _S(annotation_name, annotation_value)
251 
271 #define _I(annotation_name, annotation_value)
272 
292 #define _L(annotation_name, annotation_value)
293 
319 #define _F(annotation_name, annotation_value)
320 
321 #define _FS(annotation_name, annotation_value)
322 #define _FI(annotation_name, annotation_value)
323 #define _FL(annotation_name, annotation_value)
324 #define _FF(annotation_name, annotation_value)
325 
326 #include __STRUCT_FILE__
327 
328 /* SECOND EXAPNSION
329  -------------------
330 
331  Store the annotations for the struct
332  in a static const array.
333 */
334 
335 #undef STRUCT
336 #undef FIELD
337 #undef _S
338 #undef _I
339 #undef _L
340 #undef _F
341 #undef _FS
342 #undef _FI
343 #undef _FL
344 #undef _FF
345 
346 #define STRUCT(struct_name, ...)
347 
348 #define FIELD(annotations, type_v, identifier)
349 
350 #define _S(annotation_name, annotation_value)\
351  {__LINE__, METAREF_ANNOTATION_STRING, #annotation_name, annotation_value, -1, -1, NULL},
352 
353 #define _I(annotation_name, annotation_value)\
354  {__LINE__, METAREF_ANNOTATION_INT, #annotation_name, NULL, annotation_value, -1, NULL},
355 
356 #define _L(annotation_name, annotation_value)\
357  {__LINE__, METAREF_ANNOTATION_LONG, #annotation_name, NULL, -1, annotation_value, NULL},
358 
359 #define _F(annotation_name, annotation_value)\
360  {__LINE__, METAREF_ANNOTATION_FUNCTION, #annotation_name, NULL, -1, -1, annotation_value},
361 
362 #define _FS(annotation_name, annotation_value)
363 
364 #define _FI(annotation_name, annotation_value)
365 
366 #define _FL(annotation_name, annotation_value)
367 
368 #define _FF(annotation_name, annotation_value)
369 
370 #ifdef __cplusplus
371 }
372 #endif
373 const static Annotation METAREF_CONCAT(METAREF_, METAREF_CONCAT(__STRUCT_NAME__, _annotations))[] = {
374 #include __STRUCT_FILE__
375 {0, METAREF_ANNOTATION_TERMINATOR, NULL, NULL, -1, -1, NULL}
376 };
377 #ifdef __cplusplus
378 extern "C" {
379 #endif
380 
381 /* THIRD EXAPNSION
382  -------------------
383 
384  Store the name of each fields in the
385  struct in a static array for introspection.
386 */
387 
388 #undef STRUCT
389 #undef FIELD
390 #undef _S
391 #undef _I
392 #undef _L
393 #undef _F
394 #undef _FS
395 #undef _FI
396 #undef _FL
397 #undef _FF
398 
399 #define STRUCT(struct_name, ...) \
400  static Field METAREF_##struct_name##_fields[] = { \
401  __VA_ARGS__ \
402  {0, NULL, NULL, NULL, {}}, \
403  };
404 
405 #define FIELD(annotations, type_v, identifier) \
406  {__LINE__, #type_v, #identifier, NULL, annotations},
407 
408 #define _S(annotation_name, annotation_value)
409 
410 #define _I(annotation_name, annotation_value)
411 
412 #define _L(annotation_name, annotation_value)
413 
414 #define _F(annotation_name, annotation_value)
415 
416 #define _FS(annotation_name, annotation_value)\
417  {__LINE__, METAREF_ANNOTATION_STRING, #annotation_name, annotation_value, -1, -1, NULL},
418 
419 #define _FI(annotation_name, annotation_value)\
420  {__LINE__, METAREF_ANNOTATION_INT, #annotation_name, NULL, annotation_value, -1, NULL},
421 
422 #define _FL(annotation_name, annotation_value)\
423  {__LINE__, METAREF_ANNOTATION_LONG, #annotation_name, NULL, -1, annotation_value, NULL},
424 
425 #define _FF(annotation_name, annotation_value)\
426  {__LINE__, METAREF_ANNOTATION_FUNCTION, #annotation_name, NULL, -1, -1, annotation_value},
427 
428 #include __STRUCT_FILE__
429 
430 /* FOURTH EXAPNSION
431  -------------------
432 
433  Store the name of each fields in the
434  struct in a static array for introspection.
435 */
436 #undef STRUCT
437 #undef FIELD
438 #undef _S
439 #undef _I
440 #undef _L
441 #undef _F
442 #undef _FS
443 #undef _FI
444 #undef _FL
445 #undef _FF
446 
447 #define STRUCT(struct_name, ...) \
448  Annotation METAREF_##struct_name##_get_annotation(const char *name) {\
449  for(size_t i = 0; METAREF_##struct_name##_annotations[i].type != METAREF_ANNOTATION_TERMINATOR; ++i) {\
450  if (metaref_str_equals(METAREF_##struct_name##_annotations[i].name, name)) {\
451  return METAREF_##struct_name##_annotations[i];\
452  }\
453  }\
454  Annotation METAREF_sub_fields__ = {0, METAREF_ANNOTATION_TERMINATOR, NULL, NULL, -1, -1, NULL};\
455  return METAREF_sub_fields__;\
456  }\
457  Field METAREF_##struct_name##_get_field_name(const char *name) {\
458  for(size_t i = 0; METAREF_##struct_name##_fields[i].type != NULL; ++i) {\
459  if (metaref_str_equals(METAREF_##struct_name##_fields[i].name, name)) {\
460  return METAREF_##struct_name##_fields[i];\
461  }\
462  }\
463  Field METAREF_sub_fields1__ = {0, NULL, NULL, NULL, {}};\
464  return METAREF_sub_fields1__;\
465  }\
466 
467 #define FIELD(annotations, type_v, identifier)
468 
469 #define _S(annotation_name, annotation_value)
470 
471 #define _I(annotation_name, annotation_value)
472 
473 #define _L(annotation_name, annotation_value)
474 
475 #define _F(annotation_name, annotation_value)
476 
477 #define _FS(annotation_name, annotation_value)
478 
479 #define _FI(annotation_name, annotation_value)
480 
481 #define _FL(annotation_name, annotation_value)
482 
483 #define _FF(annotation_name, annotation_value)
484 
485 #include __STRUCT_FILE__
486 
487 /* FIFTH EXAPNSION
488  -------------------
489 
490  Store the name of each fields in the
491  struct in a static array for introspection.
492 */
493 #undef STRUCT
494 #undef FIELD
495 #undef _S
496 #undef _I
497 #undef _L
498 #undef _F
499 #undef _FS
500 #undef _FI
501 #undef _FL
502 #undef _FF
503 
504 #define STRUCT(struct_name, ...) \
505  Struct *METAREF_##struct_name##_Struct; \
506  Struct *METAREF_##struct_name##_Struct_init(const struct_name *the_meta_struct) { \
507  if (METAREF_##struct_name##_Struct == NULL) {\
508  for(size_t i = 0; METAREF_##struct_name##_fields[i].type != NULL && the_meta_struct != NULL; ++i) {\
509  Field metaref_field___ = METAREF_##struct_name##_fields[i];\
510  __VA_ARGS__\
511  METAREF_##struct_name##_fields[i].ptr_address = metaref_field___.ptr_address;\
512  }\
513  METAREF_##struct_name##_Struct = (Struct *) malloc(sizeof(Struct));\
514  METAREF_##struct_name##_Struct->name = #struct_name;\
515  METAREF_##struct_name##_Struct->file_name = __FILE__;\
516  METAREF_##struct_name##_Struct->line_num = __LINE__;\
517  METAREF_##struct_name##_Struct->fields_array = METAREF_##struct_name##_fields;\
518  METAREF_##struct_name##_Struct->annotations_array = METAREF_##struct_name##_annotations;\
519  }\
520  return METAREF_##struct_name##_Struct;\
521  }
522 
523 #define FIELD(annotations, type_v, identifier) \
524  if (metaref_str_equals(metaref_field___.name, #identifier) == 1) {\
525  metaref_field___.ptr_address = (METAREF_FIELD_PTR_ADDRESS_TYPE)&the_meta_struct->identifier;\
526  }
527 
528 #define _S(annotation_name, annotation_value)
529 
530 #define _I(annotation_name, annotation_value)
531 
532 #define _L(annotation_name, annotation_value)
533 
534 #define _F(annotation_name, annotation_value)
535 
536 #define _FS(annotation_name, annotation_value)
537 
538 #define _FI(annotation_name, annotation_value)
539 
540 #define _FL(annotation_name, annotation_value)
541 
542 #define _FF(annotation_name, annotation_value)
543 
544 #include __STRUCT_FILE__
545 
546 /* SIXTH EXAPNSION
547  -------------------
548 
549  Suplement expansion templates
550 */
551 #undef STRUCT
552 #undef FIELD
553 #undef _S
554 #undef _I
555 #undef _L
556 #undef _F
557 #undef _FS
558 #undef _FI
559 #undef _FL
560 #undef _FF
561 
562 #define STRUCT(struct_name, ...)
563 
564 #define FIELD(annotations, type_v, identifier)
565 
566 #define _S(annotation_name, annotation_value)
567 
568 #define _I(annotation_name, annotation_value)
569 
570 #define _L(annotation_name, annotation_value)
571 
572 #define _F(annotation_name, annotation_value)
573 
574 #define _FS(annotation_name, annotation_value)
575 
576 #define _FI(annotation_name, annotation_value)
577 
578 #define _FL(annotation_name, annotation_value)
579 
580 #define _FF(annotation_name, annotation_value)
581 
582 #ifdef __STRUCT_FILE__
583 #include __STRUCT_FILE__
584 #undef __STRUCT_FILE__
585 #undef __STRUCT_NAME__
586 #endif
587 
588 #ifdef METAREF_FIELD_PTR_ADDRESS_TYPE
589 #undef METAREF_FIELD_PTR_ADDRESS_TYPE
590 #endif
591 
592 #ifndef METAREF_HELPER_MACROS
593 #define METAREF_HELPER_MACROS
594 
595 /* inspection helper macros */
596 
601 #define METAREF_GET_NAME(struct_name) METAREF_##struct_name
602 
628 #define METAREF_GET_STRUCT(struct_name, struct_object)\
629  METAREF_##struct_name##_Struct_init(struct_object);
630 
639 #define METAREF_FREE_STRUCT(struct_name)\
640  if (METAREF_##struct_name##_Struct != NULL) {\
641  free(METAREF_##struct_name##_Struct);\
642  METAREF_##struct_name##_Struct = NULL;\
643  }
644 
651 #define METAREF_STRUCT_GET_ANNOTATION(struct_name, annotation_name)\
652  METAREF_##struct_name##_get_annotation(annotation_name)
653 
660 #define METAREF_STRUCT_GET_ANNOTATION2(struct_name, annotation_name)\
661  METAREF_STRUCT_GET_ANNOTATION(struct_name, #annotation_name)
662 
669 #define METAREF_STRUCT_HAS_ANNOTATION(struct_name, annotation_name)\
670  (METAREF_STRUCT_GET_ANNOTATION(struct_name, annotation_name).type != METAREF_ANNOTATION_TERMINATOR)
671 
680 #define METAREF_STRUCT_ANNOTATION_IS_STRING(struct_name, annotation_name)\
681  (METAREF_STRUCT_GET_ANNOTATION(struct_name, annotation_name).type == METAREF_ANNOTATION_STRING)
682 
690 #define METAREF_STRUCT_ANNOTATION_STR_VALUE(struct_name, annotation_name)\
691  (METAREF_STRUCT_GET_ANNOTATION(struct_name, annotation_name).type == METAREF_ANNOTATION_STRING ? \
692  METAREF_STRUCT_GET_ANNOTATION(struct_name, annotation_name).str_value\
693  : "")
694 
703 #define METAREF_STRUCT_ANNOTATION_IS_INT(struct_name, annotation_name)\
704  (METAREF_STRUCT_GET_ANNOTATION(struct_name, annotation_name).type == METAREF_ANNOTATION_INT)
705 
713 #define METAREF_STRUCT_ANNOTATION_INT_VALUE(struct_name, annotation_name)\
714  (METAREF_STRUCT_GET_ANNOTATION(struct_name, annotation_name).type == METAREF_ANNOTATION_INT ? \
715  METAREF_STRUCT_GET_ANNOTATION(struct_name, annotation_name).int_value\
716  : -1)
717 
726 #define METAREF_STRUCT_ANNOTATION_IS_LONG(struct_name, annotation_name)\
727  (METAREF_STRUCT_GET_ANNOTATION(struct_name, annotation_name).type == METAREF_ANNOTATION_LONG)
728 
736 #define METAREF_STRUCT_ANNOTATION_LONG_VALUE(struct_name, annotation_name)\
737  (METAREF_STRUCT_GET_ANNOTATION(struct_name, annotation_name).type == METAREF_ANNOTATION_LONG ? \
738  METAREF_STRUCT_GET_ANNOTATION(struct_name, annotation_name).long_value\
739  : -1)
740 
749 #define METAREF_STRUCT_ANNOTATION_IS_FUNCTION(struct_name, annotation_name)\
750  (METAREF_STRUCT_GET_ANNOTATION(struct_name, annotation_name).type == METAREF_ANNOTATION_FUNCTION)
751 
759 #define METAREF_STRUCT_ANNOTATION_FUNC_VALUE(struct_name, annotation_name)\
760  (METAREF_STRUCT_GET_ANNOTATION(struct_name, annotation_name).type == METAREF_ANNOTATION_FUNCTION ? \
761  METAREF_STRUCT_GET_ANNOTATION(struct_name, annotation_name).func_ptr\
762  : NULL)
763 
771 #define FOREACH_STRUCT_ANNOTATION(struct_name, annotation, body)\
772  for(size_t i = 0; METAREF_##struct_name##_annotations[i].type != METAREF_ANNOTATION_TERMINATOR; ++i) {\
773  Annotation annotation = METAREF_##struct_name##_annotations[i]; \
774  body \
775  }
776 
784 #define FOREACH_ANNOTATION(the_struct, annotation, body)\
785  for(size_t i = 0; the_struct->annotations_array[i].type != METAREF_ANNOTATION_TERMINATOR; ++i) {\
786  Annotation annotation = the_struct->annotations_array[i]; \
787  body \
788  }
789 
798 #define FOREACH_STRUCT_ANNOTATION_INDEX(struct_name, index, annotation, body)\
799  for(size_t i = 0; METAREF_##struct_name##_annotations[i].type != METAREF_ANNOTATION_TERMINATOR; ++i) {\
800  size_t index = i;\
801  Annotation annotation = METAREF_##struct_name##_annotations[index]; \
802  body \
803  }
804 
813 #define FOREACH_ANNOTATION_INDEX(the_struct, index, annotation, body)\
814  for(size_t i = 0; the_struct->annotations_array[i].type != METAREF_ANNOTATION_TERMINATOR; ++i) {\
815  size_t index = i;\
816  Annotation annotation = the_struct->annotations_array[index]; \
817  body \
818  }
819 
825 #define METAREF_STRUCT_FIELD_COUNT(struct_name)\
826  ((sizeof(METAREF_##struct_name##_fields) / sizeof(METAREF_##struct_name##_fields[0])) - 1)
827 
834 #define METAREF_GET_STRUCT_FIELD(struct_name, field_name)\
835  METAREF_##struct_name##_get_field_name(field_name)
836 
843 #define METAREF_HAS_FIELD(struct_name, field_name)\
844  (METAREF_GET_STRUCT_FIELD(struct_name, field_name).type != NULL)
845 
853 #define FOREACH_STRUCT_FIELD(struct_name, field, body)\
854  for(size_t i = 0; METAREF_##struct_name##_fields[i].type != NULL; ++i) {\
855  Field field = METAREF_##struct_name##_fields[i]; \
856  body \
857  }
858 
867 #define FOREACH_STRUCT_FIELD_INDEX(struct_name, index, field, body)\
868  for(size_t i = 0; METAREF_##struct_name##_fields[i].type != NULL; ++i) {\
869  size_t index = i; \
870  Field field = METAREF_##struct_name##_fields[index]; \
871  body \
872  }
873 
897 #define METAREF_FIELD_IS_CHAR_ARRAY(field)\
898  (metaref_str_equals(field.type, "char *") == 1 || \
899  metaref_str_equals(field.type, "char*") == 1)
900 
901 #define METAREF_STRUCT_FIELD_IS_CHAR_ARRAY(struct_name, field_name)\
902  (METAREF_FIELD_IS_CHAR_ARRAY(METAREF_GET_STRUCT_FIELD(struct_name, field_name)))
903 
927 #define METAREF_FIELD_IS_CHAR(field)\
928  (metaref_str_equals(field.type, "char") == 1 || \
929  metaref_str_equals(field.type, "signed char") == 1)
930 
931 #define METAREF_STRUCT_FIELD_IS_CHAR(struct_name, field_name)\
932  (METAREF_FIELD_IS_CHAR(METAREF_GET_STRUCT_FIELD(struct_name, field_name)))
933 
956 #define METAREF_FIELD_IS_UCHAR(field)\
957  (metaref_str_equals(field.type, "unsigned char") == 1)
958 
959 #define METAREF_STRUCT_FIELD_IS_UCHAR(struct_name, field_name)\
960  (METAREF_FIELD_IS_UCHAR(METAREF_GET_STRUCT_FIELD(struct_name, field_name)))
961 
986 #define METAREF_FIELD_IS_INT(field)\
987  (metaref_str_equals(field.type, "int") == 1 || \
988  metaref_str_equals(field.type, "signed") == 1 || \
989  metaref_str_equals(field.type, "signed int") == 1)
990 
991 #define METAREF_STRUCT_FIELD_IS_INT(struct_name, field_name)\
992  (METAREF_FIELD_IS_INT(METAREF_GET_STRUCT_FIELD(struct_name, field_name)))
993 
1017 #define METAREF_FIELD_IS_UINT(field)\
1018  (metaref_str_equals(field.type, "unsigned") == 1 || \
1019  metaref_str_equals(field.type, "unsigned int") == 1)
1020 
1021 #define METAREF_STRUCT_FIELD_IS_UINT(struct_name, field_name)\
1022  (METAREF_FIELD_IS_UINT(METAREF_GET_STRUCT_FIELD(struct_name, field_name)))
1023 
1049 #define METAREF_FIELD_IS_SHORT(field)\
1050  (metaref_str_equals(field.type, "short") == 1 || \
1051  metaref_str_equals(field.type, "short int") == 1 || \
1052  metaref_str_equals(field.type, "signed short") == 1 || \
1053  metaref_str_equals(field.type, "signed short int") == 1)
1054 
1055 #define METAREF_STRUCT_FIELD_IS_SHORT(struct_name, field_name)\
1056  (METAREF_FIELD_IS_SHORT(METAREF_GET_STRUCT_FIELD(struct_name, field_name)))
1057 
1081 #define METAREF_FIELD_IS_USHORT(field)\
1082  (metaref_str_equals(field.type, "unsigned short") == 1 || \
1083  metaref_str_equals(field.type, "unsigned short int") == 1)
1084 
1085 #define METAREF_STRUCT_FIELD_IS_USHORT(struct_name, field_name)\
1086  (METAREF_FIELD_IS_USHORT(METAREF_GET_STRUCT_FIELD(struct_name, field_name)))
1087 
1113 #define METAREF_FIELD_IS_LONG(field)\
1114  (metaref_str_equals(field.type,"long") == 1 || \
1115  metaref_str_equals(field.type,"long int") == 1 || \
1116  metaref_str_equals(field.type,"signed long") == 1 || \
1117  metaref_str_equals(field.type,"signed long int") == 1)
1118 
1119 #define METAREF_STRUCT_FIELD_IS_LONG(struct_name, field_name)\
1120  (METAREF_FIELD_IS_LONG(METAREF_GET_STRUCT_FIELD(struct_name, field_name)))
1121 
1145 #define METAREF_FIELD_IS_ULONG(field)\
1146  (metaref_str_equals(field.type, "unsigned long") == 1 || \
1147  metaref_str_equals(field.type, "unsigned long int") == 1)
1148 
1149 #define METAREF_STRUCT_FIELD_IS_ULONG(struct_name, field_name)\
1150  (METAREF_FIELD_IS_ULONG(METAREF_GET_STRUCT_FIELD(struct_name, field_name)))
1151 
1174 #define METAREF_FIELD_IS_FLOAT(field)\
1175  (metaref_str_equals(field.type,"float") == 1)
1176 
1177 #define METAREF_STRUCT_FIELD_IS_FLOAT(struct_name, field_name)\
1178  (METAREF_FIELD_IS_FLOAT(METAREF_GET_STRUCT_FIELD(struct_name, field_name)))
1179 
1202 #define METAREF_FIELD_IS_DOUBLE(field)\
1203  (metaref_str_equals(field.type,"double") == 1)
1204 
1205 #define METAREF_STRUCT_FIELD_IS_DOUBLE(struct_name, field_name)\
1206  (METAREF_FIELD_IS_DOUBLE(METAREF_GET_STRUCT_FIELD(struct_name, field_name)) == 1)
1207 
1230 #define METAREF_FIELD_IS_LONG_DOUBLE(field)\
1231  (metaref_str_equals(field.type,"long double") == 1)
1232 
1233 #define METAREF_STRUCT_FIELD_IS_LONG_DOUBLE(struct_name, field_name)\
1234  (METAREF_FIELD_IS_LONG_DOUBLE(METAREF_GET_STRUCT_FIELD(struct_name, field_name)))
1235 
1241 #define METAREF_GET_FIELD_ANNOTATIONS(field) field.annotations
1242 
1251 #define FOREACH_FIELD_ANNOTATION(field, annotation, body)\
1252  for(size_t mr_i_ = 0; field.annotations[mr_i_].line_num != 0; ++mr_i_) {\
1253  Annotation annotation = field.annotations[mr_i_]; \
1254  body \
1255  }
1256 
1263 #define METAREF_FIELD_GET_ANNOTATION(field, annotation_name)\
1264  metaref_get_field_annotation(field, annotation_name)
1265 
1272 #define METAREF_FIELD_GET_ANNOTATION2(field, annotation_name)\
1273  METAREF_FIELD_GET_ANNOTATION(field, #annotation_name)
1274 
1281 #define METAREF_FIELD_HAS_ANNOTATION(field, annotation_name)\
1282  (METAREF_FIELD_GET_ANNOTATION(field, annotation_name).type != METAREF_ANNOTATION_TERMINATOR)
1283 
1292 #define METAREF_FIELD_ANNOTATION_IS_STRING(field, annotation_name)\
1293  (METAREF_FIELD_GET_ANNOTATION(field, annotation_name).type == METAREF_ANNOTATION_STRING)
1294 
1302 #define METAREF_FIELD_ANNOTATION_STR_VALUE(field, annotation_name)\
1303  (METAREF_FIELD_GET_ANNOTATION(field, annotation_name).type == METAREF_ANNOTATION_STRING ? \
1304  METAREF_FIELD_GET_ANNOTATION(field, annotation_name).str_value\
1305  : "")
1306 
1315 #define METAREF_FIELD_ANNOTATION_IS_INT(field, annotation_name)\
1316  (METAREF_FIELD_GET_ANNOTATION(field, annotation_name).type == METAREF_ANNOTATION_INT)
1317 
1325 #define METAREF_FIELD_ANNOTATION_INT_VALUE(field, annotation_name)\
1326  (METAREF_FIELD_GET_ANNOTATION(field, annotation_name).type == METAREF_ANNOTATION_INT ? \
1327  METAREF_FIELD_GET_ANNOTATION(field, annotation_name).int_value\
1328  : -1)
1329 
1338 #define METAREF_FIELD_ANNOTATION_IS_LONG(field, annotation_name)\
1339  (METAREF_FIELD_GET_ANNOTATION(field, annotation_name).type == METAREF_ANNOTATION_LONG)
1340 
1348 #define METAREF_FIELD_ANNOTATION_LONG_VALUE(field, annotation_name)\
1349  (METAREF_FIELD_GET_ANNOTATION(field, annotation_name).type == METAREF_ANNOTATION_LONG ? \
1350  METAREF_FIELD_GET_ANNOTATION(field, annotation_name).long_value\
1351  : -1)
1352 
1361 #define METAREF_FIELD_ANNOTATION_IS_FUNCTION(field, annotation_name)\
1362  (METAREF_FIELD_GET_ANNOTATION(field, annotation_name).type == METAREF_ANNOTATION_FUNCTION)
1363 
1371 #define METAREF_FIELD_ANNOTATION_FUNC_VALUE(field, annotation_name)\
1372  (METAREF_FIELD_GET_ANNOTATION(field, annotation_name).type == METAREF_ANNOTATION_FUNCTION ? \
1373  METAREF_FIELD_GET_ANNOTATION(field, annotation_name).func_ptr\
1374  : NULL)
1375 
1390 #define METAREF_GET_FIELD(the_meta_struct, field_name)\
1391  metaref_struct_get_field(the_meta_struct, field_name)
1392 
1404 #define FOREACH_FIELD(struct_name, obj, field, body)\
1405  for(size_t i = 0; the_struct->fields_array[i].type != NULL; ++i) {\
1406  Field field = the_struct->fields_array[i]; \
1407  body \
1408  }
1409 
1422 #define FOREACH_FIELD_INDEX(the_struct, index, field, body)\
1423  for(size_t i = 0; the_struct->fields_array[i].type != NULL; ++i) {\
1424  size_t index = i; \
1425  Field field = the_struct->fields_array[index]; \
1426  body \
1427  }
1428 
1438 #define METAREF_FIELD_VALUE_IS_NULL(field)\
1439  (field.ptr_address == NULL || *field.ptr_address == NULL)
1440 
1450 #define METAREF_FIELD_VALUE_PTR(field)\
1451  (*field.ptr_address)
1452 
1463 #define METAREF_FIELD_VALUE_PTR_AS(type, field)\
1464  ((type*)field.ptr_address)
1465 
1471 #define METAREF_SET_FIELD_VALUE(field, value)\
1472  *field.ptr_address = (void*)value
1473 
1474 #endif
1475 
1476 #define METAREF_PREPROCESSING_DONE
1477 #undef EXOTIC_METAREF_STRUCT
1478 
1479 #ifdef __cplusplus
1480 }
1481 #endif
1482 
1483 #endif
1484 #endif