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_intro
11 - \ref GRAS_tut_tour_pointers_use
12 - \ref GRAS_tut_tour_pointers_recap
13 - \ref GRAS_tut_tour_pointers_cste
16 \section GRAS_tut_tour_pointers_intro Introduction to pointers in datadesc
17 \section GRAS_tut_tour_pointers_use Using pointers in datadesc
18 \section GRAS_tut_tour_pointers_recap Recapping everything
21 \section GRAS_tut_tour_pointers_cste How to have constants in parsed structures?
23 You can use gras_datadesc_set_const() to explain GRAS about the value of
24 your \#define'd constants.
28 GRAS_DEFINE_TYPE(array,struct array {
33 gras_datadesc_type_t ddt;
35 gras_datadesc_set_const("SIZE",SIZE); /* Set it before */
36 gras_datadesc_by_symbol(array);
43 and the this example do use structures as payload,
44 so we have to declare it to GRAS. Hopefully, this can be done easily by enclosing
45 the structure declaration within a \ref GRAS_DEFINE_TYPE macro call. It will then copy this
46 declaration into an hidden string variable, which can be automatically parsed at
47 run time. Of course, the declaration is also copied unmodified by this macro, so that it
48 gets parsed by the compiler also.
50 There is some semantic that GRAS cannot guess alone and you need to <i>annotate</i>
51 your declaration to add some. For example, the ctn pointer can be a reference to an
52 object or a whole array (in which case you also has to specify its size). This is done
53 with the GRAS_ANNOTE call. It is removed from the text passed to the compiler, but it helps
54 GRAS getting some information about the semantic of your data. Here, it says that \a ctn is an
55 array, which size is the result of the operation \a rows * \a cols (with \a rows and \a cols
56 being the other fields of the structure).
58 Please note that this annotation mechanism is not as robust and cool as this example seems to
59 imply. If you want to use it yourself, you'd better use the exact right syntax, which is
60 detailed in the \ref GRAS_dd section.
62 \skip GRAS_DEFINE_TYPE
68 #define MAX_ROUTESET 10
69 #define MAX_LEAFSET COLS
71 GRAS_DEFINE_TYPE(gras_row_t,
74 int row[COLS][MAX_ROUTESET];
77 typedef struct gras_row_t gras_row_t;
79 GRAS_DEFINE_TYPE(gras_welcome_msg_t,
80 struct gras_welcome_msg_t {
85 gras_row_t *rows GRAS_ANNOTE(size,row_count);
87 int leaves[MAX_LEAFSET];
90 void declare_ddt(void) {
91 gras_datadesc_type_t ddt;
93 gras_datadesc_set_const("COLS",COLS);
94 gras_datadesc_set_const("MAX_ROUTESET",MAX_ROUTESET);
95 gras_datadesc_set_const("MAX_LEAFSET",MAX_LEAFSET);
97 gras_datadesc_by_symbol(gras_row_t); /* Parse it before */
98 ddt=gras_datadesc_ref("welcome_msg_t*",gras_datadesc_by_symbol(gras_welcome_msg_t));
99 gras_msgtype_declare("welcome",ddt);