*
* \warning Since GRAS_DEFINE_TYPE is a macro, you shouldn't put any comma in your type definition
* (comma separates macro args). For example, change \verbatim int a, b;\endverbatim to \verbatim int a;
- int b;\endverbatim
+int b;\endverbatim
*
- * <h3>Defining multidimentional arrays</h3>
+ * \section gras_dd_define \#define and fixed size array
+ *
+ * If you want to exchange arrays which size is given at compilation time by a
+ * \#defined constant, you need to keep GRAS informed. It would be done the
+ * following way:
+
+\verbatim #define BLOCK_SIZE 32
+GRAS_DEFINE_TYPE(s_toto,
+struct {
+ double data[BLOCK_SIZE];
+} s_toto;)
+
+void register_messages() {
+ gras_datadesc_type_t toto_type;
+
+ gras_datadesc_set_const("BLOCK_SIZE",BLOCK_SIZE);
+ toto_type = gras_datadesc_by_symbol(s_toto);
+}\endverbatim
+ *
+ * The form <tt>gras_datadesc_set_const("BLOCK_SIZE",BLOCK_SIZE);</tt> ensures
+ * that when you change the definition of the constant, GRAS keeps informed of
+ * the right value. Passing the numerical value of the constant as second
+ * argument would be a bad idea to that regard. Of course, the call to
+ * gras_datadesc_set_const() should come before any gras_datadesc_by_symbol()
+ * containing references to it.
+ *
+ * \section GRAS_dd_multidim Defining multidimentional arrays
*
* The mecanism for multidimensional arrays is known to be fragile and cumbersome. If you want to use it,
* you have to understand how it is implemented: the multiplication is performed using the sizes stack. In previous example,
* If you cannot express your datadescs with this mechanism, you'll have to use the more advanced
* (and somehow complex) one described in the \ref GRAS_dd_cb_full.
*
- * <h3>Projects spanning over multiple files</h3>
+ * \section GRAS_dd_multifile Projects spanning over multiple files
*
* GRAS_DEFINE_TYPE declares some symbols to work, it needs some special
* care when used in several files. In such case, you want the regular type
* @brief Add an annotation to a type to be automatically parsed
*/
#define GRAS_ANNOTE(key,val)
+
+/** @brief Defines the value of a define to the datatype parsing infrastructure
+ */
+void gras_datadesc_set_const(const char*name, int value);
/* @} */
char *end;
long int size=strtol(gras_ddt_parse_text, &end, 10);
- if (end == gras_ddt_parse_text || *end != '\0')
- PARSE_ERROR1("Unparsable size of array (found '%c', expected number)",*end);
+ if (end == gras_ddt_parse_text || *end != '\0') {
+ /* Not a number. Get the constant value, if any */
+ int *storage=xbt_dict_get_or_null(gras_dd_constants,gras_ddt_parse_text);
+ if (storage) {
+ size = *storage;
+ } else {
+ PARSE_ERROR1("Unparsable size of array. Found '%s', expected number or known constant. Need to use gras_datadesc_set_const(), huh?",
+ gras_ddt_parse_text);
+ }
+ }
/* replace the previously pushed type to an array of it */
change_to_fixed_array(identifiers,size);
XBT_OUT;
return res;
}
+
+xbt_dict_t gras_dd_constants;
+/** \brief Declare a constant to the parsing mecanism. See the "\#define and fixed size array" section */
+void gras_datadesc_set_const(const char*name, int value) {
+ int *stored = xbt_new(int, 1);
+ *stored=value;
+
+ xbt_dict_set(gras_dd_constants,name, stored, free);
+}