+xbt_dynar_t xbt_cfg_get_dynar (xbt_cfg_t cfg, const char *name) {
+ xbt_cfgelm_t variable=NULL;
+ xbt_ex_t e;
+
+ TRY {
+ variable = xbt_dict_get((xbt_dict_t)cfg,name);
+ } CATCH(e) {
+ if (e.category == not_found_error) {
+ xbt_ex_free(e);
+ THROW1(not_found_error,0,
+ "No registered variable %s in this config set",name);
+ }
+ RETHROW;
+ }
+
+ return variable->content;
+}
+
+
+/** @brief Retrieve one of the integer value of a variable */
+int
+xbt_cfg_get_int_at(xbt_cfg_t cfg, const char *name, int pos) {
+
+ xbt_cfgelm_t variable = xbt_cfgelm_get(cfg,name,xbt_cfgelm_int);
+ return xbt_dynar_get_as(variable->content, pos, int);
+}
+
+/** @brief Retrieve one of the double value of a variable */
+double
+xbt_cfg_get_double_at(xbt_cfg_t cfg, const char *name, int pos) {
+
+ xbt_cfgelm_t variable = xbt_cfgelm_get(cfg,name,xbt_cfgelm_double);
+ return xbt_dynar_get_as(variable->content, pos, double);
+}
+
+
+/** @brief Retrieve one of the string value of a variable */
+char*
+xbt_cfg_get_string_at(xbt_cfg_t cfg, const char *name, int pos) {
+
+ xbt_cfgelm_t variable = xbt_cfgelm_get(cfg,name,xbt_cfgelm_string);
+ return xbt_dynar_get_as(variable->content, pos, char*);
+}
+
+/** @brief Retrieve one of the peer value of a variable */
+void
+xbt_cfg_get_peer_at(xbt_cfg_t cfg, const char *name, int pos,
+ char **peer, int *port) {
+
+ xbt_cfgelm_t variable = xbt_cfgelm_get(cfg,name,xbt_cfgelm_int);
+ xbt_peer_t val = xbt_dynar_get_ptr(variable->content, pos);
+
+ *port = val->port;
+ *peer = val->name;
+}
+
+
+#ifdef SIMGRID_TEST
+#include "xbt.h"
+#include "xbt/ex.h"
+
+XBT_TEST_SUITE("config","Configuration support");
+
+static xbt_cfg_t make_set(){
+ xbt_cfg_t set=NULL;
+
+ set = xbt_cfg_new();
+ xbt_cfg_register_str(set,"speed:1_to_2_int");
+ xbt_cfg_register_str(set,"peername:1_to_1_string");
+ xbt_cfg_register_str(set,"user:1_to_10_string");
+
+ return set;
+} /* end_of_make_set */
+
+XBT_TEST_UNIT("memuse",test_config_memuse,"Alloc and free a config set") {
+ xbt_cfg_t set=make_set();
+ xbt_test_add0("Alloc and free a config set");
+ xbt_cfg_set_parse(set, "peername:veloce user:mquinson\nuser:oaumage\tuser:alegrand");
+ xbt_cfg_free(&set);
+ xbt_cfg_free(&set);
+}
+
+XBT_TEST_UNIT("validation",test_config_validation,"Validation tests") {
+ xbt_cfg_t set = set=make_set();
+ xbt_ex_t e;
+
+ xbt_test_add0("Having too few elements for speed");
+ xbt_cfg_set_parse(set, "peername:veloce user:mquinson\nuser:oaumage\tuser:alegrand");
+ TRY {
+ xbt_cfg_check(set);
+ } CATCH(e) {
+ if (e.category != mismatch_error ||
+ strncmp(e.msg,"Config elem speed needs",strlen("Config elem speed needs")))
+ xbt_test_fail1("Got an exception. msg=%s",e.msg);
+ xbt_ex_free(e);
+ }
+ xbt_cfg_free(&set);
+ xbt_cfg_free(&set);
+
+
+
+ xbt_test_add0("Having too much values of 'speed'");
+ set=make_set();
+ xbt_cfg_set_parse(set,"peername:toto:42 user:alegrand");
+ TRY {
+ xbt_cfg_set_parse(set,"speed:42 speed:24 speed:34");
+ } CATCH(e) {
+ if (e.category != mismatch_error ||
+ strncmp(e.msg,"Cannot add value 34 to the config elem speed",
+ strlen("Config elem speed needs")))
+ xbt_test_fail1("Got an exception. msg=%s",e.msg);
+ xbt_ex_free(e);