Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update 'Where is the get_host_load function hidden in MSG?' according to the last...
[simgrid.git] / doc / gtut-tour-13-pointers.doc
index da841ea..f75d574 100644 (file)
@@ -1,26 +1,70 @@
 /**
 @page GRAS_tut_tour_pointers Lesson 13: Defining structure containing pointers (TODO)
 
+This lesson is a bit different from the other ones. It aims at explaining
+several features of the automatic datadesc parsing. Since it would be a bit
+long otherwise, the lesson is organized as a FAQ, with little examples of
+how to do things.
+
 \section GRAS_tut_tour_pointers_toc Table of Contents
- - \ref GRAS_tut_tour_pointers_intro
- - \ref GRAS_tut_tour_pointers_use
- - \ref GRAS_tut_tour_pointers_recap
+ - \ref GRAS_tut_tour_pointers_cste
    
 <hr>
 
-\section GRAS_tut_tour_pointers_intro Introduction
 
+\section GRAS_tut_tour_pointers_cste How to have constants in parsed structures?
+
+You can use gras_datadesc_set_const() to explain GRAS about the value of
+your \#define'd constants.
 
-\section GRAS_tut_tour_pointers_use Defining structure containing pointers
+\verbatim
+#define SIZE 12
+GRAS_DEFINE_TYPE(array,struct array {
+  int data[SIZE];
+};);
 
+void declare_ddt() {
+  gras_datadesc_type_t ddt;
+  
+  gras_datadesc_set_const("SIZE",SIZE); /* Set it before */
+  gras_datadesc_by_symbol(array); 
+}
+\endverbatim
 
-\section GRAS_tut_tour_pointers_recap Recapping everything together
 
-The program now reads:
-include 12-pointers.c
+*/
 
-Which produces the expected output:
-include 12-pointers.output
+#define COLS 16
+#define MAX_ROUTESET 10
+#define MAX_LEAFSET COLS
 
+GRAS_DEFINE_TYPE(gras_row_t,
+struct gras_row_t {         
+  int which_row;            
+  int row[COLS][MAX_ROUTESET];
+};)
+    
+typedef struct gras_row_t gras_row_t;
+    
+GRAS_DEFINE_TYPE(gras_welcome_msg_t, 
+struct gras_welcome_msg_t {
+  int id;
+  double time_sent;
+    
+  int row_count;
+  gras_row_t *rows GRAS_ANNOTE(size,row_count);
+       
+  int leaves[MAX_LEAFSET];
+};)              
 
-*/
+void declare_ddt(void) {
+  gras_datadesc_type_t ddt;
+  
+  gras_datadesc_set_const("COLS",COLS);
+  gras_datadesc_set_const("MAX_ROUTESET",MAX_ROUTESET);
+  gras_datadesc_set_const("MAX_LEAFSET",MAX_LEAFSET);
+  
+  gras_datadesc_by_symbol(gras_row_t); /* Parse it before */
+  ddt=gras_datadesc_ref("welcome_msg_t*",gras_datadesc_by_symbol(gras_welcome_msg_t));
+  gras_msgtype_declare("welcome",ddt);  
+}