2 @page GRAS_tut_tour_pointers Lesson 13: Defining structure containing pointers (TODO)
4 This lesson is a bit different from the other ones. It aims at explaining
5 several features of the automatic datadesc parsing. Since it would be a bit
6 long otherwise, the lesson is organized as a FAQ, with little examples of
9 \section GRAS_tut_tour_pointers_toc Table of Contents
10 - \ref GRAS_tut_tour_pointers_cste
15 \section GRAS_tut_tour_pointers_cste How to have constants in parsed structures?
17 You can use gras_datadesc_set_const() to explain GRAS about the value of
18 your \#define'd constants.
22 GRAS_DEFINE_TYPE(array,struct array {
27 gras_datadesc_type_t ddt;
29 gras_datadesc_set_const("SIZE",SIZE); /* Set it before */
30 gras_datadesc_by_symbol(array);
37 and the this example do use structures as payload,
38 so we have to declare it to GRAS. Hopefully, this can be done easily by enclosing
39 the structure declaration within a \ref GRAS_DEFINE_TYPE macro call. It will then copy this
40 declaration into an hidden string variable, which can be automatically parsed at
41 run time. Of course, the declaration is also copied unmodified by this macro, so that it
42 gets parsed by the compiler also.
44 There is some semantic that GRAS cannot guess alone and you need to <i>annotate</i>
45 your declaration to add some. For example, the ctn pointer can be a reference to an
46 object or a whole array (in which case you also has to specify its size). This is done
47 with the GRAS_ANNOTE call. It is removed from the text passed to the compiler, but it helps
48 GRAS getting some information about the semantic of your data. Here, it says that \a ctn is an
49 array, which size is the result of the operation \a rows * \a cols (with \a rows and \a cols
50 being the other fields of the structure).
52 Please note that this annotation mechanism is not as robust and cool as this example seems to
53 imply. If you want to use it yourself, you'd better use the exact right syntax, which is
54 detailed in the \ref GRAS_dd section.
56 \skip GRAS_DEFINE_TYPE
62 #define MAX_ROUTESET 10
63 #define MAX_LEAFSET COLS
65 GRAS_DEFINE_TYPE(gras_row_t,
68 int row[COLS][MAX_ROUTESET];
71 typedef struct gras_row_t gras_row_t;
73 GRAS_DEFINE_TYPE(gras_welcome_msg_t,
74 struct gras_welcome_msg_t {
79 gras_row_t *rows GRAS_ANNOTE(size,row_count);
81 int leaves[MAX_LEAFSET];
84 void declare_ddt(void) {
85 gras_datadesc_type_t ddt;
87 gras_datadesc_set_const("COLS",COLS);
88 gras_datadesc_set_const("MAX_ROUTESET",MAX_ROUTESET);
89 gras_datadesc_set_const("MAX_LEAFSET",MAX_LEAFSET);
91 gras_datadesc_by_symbol(gras_row_t); /* Parse it before */
92 ddt=gras_datadesc_ref("welcome_msg_t*",gras_datadesc_by_symbol(gras_welcome_msg_t));
93 gras_msgtype_declare("welcome",ddt);