* under the terms of the license (GNU LGPL) which comes with this package. */
#include "xbt/misc.h" /* min()/max() */
+#include "xbt/ex.h"
#include "gras/DataDesc/datadesc_private.h"
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ddt_create,datadesc,"Creating new datadescriptions");
res->name = (char*)strdup(name);
res->name_len = strlen(name);
- res->flags = 0;
+ res->cycle = 0;
xbt_set_add(gras_datadesc_set_local,
(xbt_set_elm_t)res,&gras_ddt_freev);
}
/**
- * This returns NULL when no type of this name can be found
+ * This returns NULL no type of this name can be found instead of throwing exceptions which would complicate the GRAS_DEFINE_TYPE macro
*/
gras_datadesc_type_t gras_datadesc_by_name(const char *name) {
-
- gras_datadesc_type_t type;
-
- XBT_IN1("(%s)",name);
- if (xbt_set_get_by_name(gras_datadesc_set_local,
- name,(xbt_set_elm_t*)&type) == no_error) {
- XBT_OUT;
- return type;
- } else {
- XBT_OUT;
- return NULL;
+ xbt_ex_t e;
+ gras_datadesc_type_t res = NULL;
+ TRY {
+ res = (gras_datadesc_type_t)xbt_set_get_by_name(gras_datadesc_set_local,name);
+ } CATCH(e) {
+ if (e.category != not_found_error)
+ RETHROW;
+ xbt_ex_free(e);
+ res = NULL;
}
+ return res;
}
/**
- * Retrieve a type from its code
+ * Retrieve a type from its code (or NULL if not found)
*/
-xbt_error_t gras_datadesc_by_id(long int code,
- gras_datadesc_type_t *type) {
- XBT_IN;
- return xbt_set_get_by_id(gras_datadesc_set_local,
- code,(xbt_set_elm_t*)type);
+gras_datadesc_type_t gras_datadesc_by_id(long int code) {
+ xbt_ex_t e;
+ gras_datadesc_type_t res=NULL;
+ TRY {
+ res = (gras_datadesc_type_t)xbt_set_get_by_id(gras_datadesc_set_local,code);
+ } CATCH(e) {
+ if (e.category != not_found_error)
+ RETHROW;
+ xbt_ex_free(e);
+ res = NULL;
+ }
+ return res;
}
/**
"Redefinition of type %s does not match", name);
VERB1("Discarding redefinition of %s",name);
return res;
- }
+ }
res = gras_ddt_new(name);
for (arch = 0; arch < gras_arch_count; arch ++) {
*/
void
gras_datadesc_cycle_set(gras_datadesc_type_t ddt) {
- ddt->flags &= gras_datadesc_flag_cycle;
+ ddt->cycle = 1;
}
/**
*/
void
gras_datadesc_cycle_unset(gras_datadesc_type_t ddt) {
- ddt->flags &= ~(gras_datadesc_flag_cycle);
+ ddt->cycle = 0;
}
/** \brief Declare a new union description */
XBT_IN1("(%s)",name);
res = gras_datadesc_by_name(name);
+
if (res) {
xbt_assert1(res->category_code == e_gras_datadesc_type_cat_ref,
"Redefinition of type %s does not match", name);
return res;
}
-xbt_error_t
+
+gras_datadesc_type_t
gras_datadesc_import_nws(const char *name,
const DataDescriptor *desc,
- unsigned long howmany,
- /* OUT */ gras_datadesc_type_t *dst) {
- RAISE_UNIMPLEMENTED;
+ unsigned long howmany) {
+ THROW_UNIMPLEMENTED;
}
/**
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
xbt_abort();
}
}
+
+/**
+ * Any previously pushed value is poped and the field value is multiplied to
+ * it. The result is then pushed back into the stack of sizes. It can then be
+ * retrieved with \ref gras_datadesc_ref_pop_arr or directly with \ref
+ * gras_cbps_i_pop.
+ *
+ * The field must be an int, unsigned int, long int or unsigned long int.
+ */
+void gras_datadesc_cb_field_push_multiplier (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 MPUSHy 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_mult;
+ } else if (!strcmp("unsigned int",sub_type->name)) {
+ field->send = gras_datadesc_cb_push_uint_mult;
+ } else if (!strcmp("long int",sub_type->name)) {
+ field->send = gras_datadesc_cb_push_lint_mult;
+ } else if (!strcmp("unsigned long int",sub_type->name)) {
+ field->send = gras_datadesc_cb_push_ulint_mult;
+ } else {
+ ERROR1("Field %s is not an int, unsigned int, long int neither unsigned long int",
+ sub_type->name);
+ xbt_abort();
+ }
+}
+
/**
* The given datadesc must be a struct or union (abort if not).
* (useful to put the function pointers to the right value, for example)