+/*
+ * gras_dd_find_field:
+ *
+ * Returns the type descriptor of the given field. Abort on error.
+ */
+static gras_dd_cat_field_t
+ gras_dd_find_field(gras_datadesc_type_t type,
+ const char *field_name) {
+ xbt_dynar_t field_array;
+
+ gras_dd_cat_field_t field=NULL;
+ int field_num;
+
+ if (type->category_code == e_gras_datadesc_type_cat_union) {
+ field_array = type->category.union_data.fields;
+ } else if (type->category_code == e_gras_datadesc_type_cat_struct) {
+ field_array = type->category.struct_data.fields;
+ } else {
+ ERROR2("%s (%p) is not a struct nor an union. There is no field.", type->name,(void*)type);
+ xbt_abort();
+ }
+ xbt_dynar_foreach(field_array,field_num,field) {
+ if (!strcmp(field_name,field->name)) {
+ return field;
+ }
+ }
+ ERROR2("No field nammed %s in %s",field_name,type->name);
+ xbt_abort();
+
+}
+
+/**
+ * The given datadesc must be a struct or union (abort if not).
+ * (useful to push the sizes of the upcoming arrays, for example)
+ */
+void gras_datadesc_cb_field_send (gras_datadesc_type_t type,
+ const char *field_name,
+ gras_datadesc_type_cb_void_t send) {
+
+ gras_dd_cat_field_t field=gras_dd_find_field(type,field_name);
+ field->send = send;
+}
+
+
+/**
+ * The value, which must be an int, unsigned int, long int or unsigned long int
+ * is pushed to the stacks of sizes and can then be retrieved with
+ * \ref gras_datadesc_ref_pop_arr or directly with \ref gras_cbps_i_pop.
+ */
+void gras_datadesc_cb_field_push (gras_datadesc_type_t type,
+ const char *field_name) {
+
+ gras_dd_cat_field_t field=gras_dd_find_field(type,field_name);
+ gras_datadesc_type_t sub_type=field->type;
+
+ DEBUG3("add a PUSHy cb to '%s' field (type '%s') of '%s'",
+ field_name,sub_type->name,type->name);
+ if (!strcmp("int",sub_type->name)) {
+ field->send = gras_datadesc_cb_push_int;
+ } else if (!strcmp("unsigned int",sub_type->name)) {
+ field->send = gras_datadesc_cb_push_uint;
+ } else if (!strcmp("long int",sub_type->name)) {
+ field->send = gras_datadesc_cb_push_lint;
+ } else if (!strcmp("unsigned long int",sub_type->name)) {
+ field->send = gras_datadesc_cb_push_ulint;
+ } else {
+ ERROR1("Field %s is not an int, unsigned int, long int neither unsigned long int",
+ sub_type->name);
+ xbt_abort();
+ }
+}