3 /* config - Dictionnary where the type of each variable is provided. */
5 /* This is useful to build named structs, like option or property sets. */
7 /* Copyright (c) 2001,2002,2003,2004 Martin Quinson. All rights reserved. */
9 /* This program is free software; you can redistribute it and/or modify it
10 * under the terms of the license (GNU LGPL) which comes with this package. */
13 #include "xbt/sysdep.h"
15 #include "xbt/error.h"
16 #include "xbt/dynar.h"
19 #include "xbt/config.h" /* prototypes of this module */
21 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(config,xbt,"configuration support");
23 /* xbt_cfgelm_t: the typedef corresponding to a config variable.
25 Both data and DTD are mixed, but fixing it now would prevent me to ever
29 /* Allowed type of the variable */
30 e_xbt_cfgelm_type_t type;
34 (cannot be an union because type host uses both str and i) */
36 } s_xbt_cfgelm_t,*xbt_cfgelm_t;
38 static const char *xbt_cfgelm_type_name[xbt_cfgelm_type_count]=
39 {"int","double","string","host"};
41 /* Internal stuff used in cache to free a variable */
42 static void xbt_cfgelm_free(void *data);
44 /* Retrieve the variable we'll modify */
45 static xbt_error_t xbt_cfgelm_get(xbt_cfg_t cfg, const char *name,
46 e_xbt_cfgelm_type_t type,
47 /* OUT */ xbt_cfgelm_t *whereto);
49 void xbt_cfg_str_free(void *d);
50 void xbt_cfg_host_free(void *d);
52 void xbt_cfg_str_free(void *d){
55 void xbt_cfg_host_free(void *d){
56 xbt_host_t *h=(xbt_host_t*) *(void**)d;
58 if (h->name) free(h->name);
63 /*----[ Memory management ]-----------------------------------------------*/
65 /** @brief Constructor
67 * Initialise an config set
71 xbt_cfg_t xbt_cfg_new(void) {
72 return (xbt_cfg_t)xbt_dict_new();
75 /** @brief Copy an existing configuration set
77 * \arg whereto the config set to be created
78 * \arg tocopy the source data
80 * This only copy the registrations, not the actual content
84 xbt_cfg_cpy(xbt_cfg_t tocopy,xbt_cfg_t *whereto) {
85 xbt_dict_cursor_t cursor=NULL;
86 xbt_cfgelm_t variable=NULL;
90 xbt_assert0(tocopy,"cannot copy NULL config");
92 xbt_dict_foreach((xbt_dict_t)tocopy,cursor,name,variable) {
93 xbt_cfg_register(*whereto, name, variable->type, variable->min, variable->max);
97 /** @brief Destructor */
98 void xbt_cfg_free(xbt_cfg_t *cfg) {
99 xbt_dict_free((xbt_dict_t*)cfg);
102 /** @brief Dump a config set for debuging purpose
104 * \arg name The name to give to this config set
105 * \arg indent what to write at the begining of each line (right number of spaces)
106 * \arg cfg the config set
108 void xbt_cfg_dump(const char *name,const char *indent,xbt_cfg_t cfg) {
109 xbt_dict_t dict = (xbt_dict_t) cfg;
110 xbt_dict_cursor_t cursor=NULL;
111 xbt_cfgelm_t variable=NULL;
121 printf("%s>> Dumping of the config set '%s':\n",indent,name);
122 xbt_dict_foreach(dict,cursor,key,variable) {
124 printf("%s %s:",indent,key);
126 size = xbt_dynar_length(variable->content);
127 printf("%d_to_%d_%s. Actual size=%d. List of values:\n",
128 variable->min,variable->max,xbt_cfgelm_type_name[variable->type],
131 switch (variable->type) {
134 for (i=0; i<size; i++) {
135 ival = xbt_dynar_get_as(variable->content,i,int);
136 printf ("%s %d\n",indent,ival);
140 case xbt_cfgelm_double:
141 for (i=0; i<size; i++) {
142 dval = xbt_dynar_get_as(variable->content,i,double);
143 printf ("%s %f\n",indent,dval);
147 case xbt_cfgelm_string:
148 for (i=0; i<size; i++) {
149 sval = xbt_dynar_get_as(variable->content,i,char*);
150 printf ("%s %s\n",indent,sval);
154 case xbt_cfgelm_host:
155 for (i=0; i<size; i++) {
156 hval = xbt_dynar_get_as(variable->content,i,xbt_host_t*);
157 printf ("%s %s:%d\n",indent,hval->name,hval->port);
162 printf("%s Invalid type!!\n",indent);
167 if (name) printf("%s<< End of the config set '%s'\n",indent,name);
170 xbt_dict_cursor_free(&cursor);
175 * free an config element
178 void xbt_cfgelm_free(void *data) {
179 xbt_cfgelm_t c=(xbt_cfgelm_t)data;
182 xbt_dynar_free(&(c->content));
186 /*----[ Registering stuff ]-----------------------------------------------*/
188 /** @brief Register an element within a config set
190 * @arg cfg the config set
191 * @arg type the type of the config element
192 * @arg min the minimum
193 * @arg max the maximum
197 xbt_cfg_register(xbt_cfg_t cfg,
198 const char *name, e_xbt_cfgelm_type_t type,
203 DEBUG4("Register cfg elm %s (%d to %d %s)",name,min,max,xbt_cfgelm_type_name[type]);
204 errcode = xbt_dict_get((xbt_dict_t)cfg,name,(void**)&res);
206 if (errcode == no_error) {
207 WARN1("Config elem %s registered twice.",name);
208 /* Will be removed by the insertion of the new one */
210 xbt_assert_error(mismatch_error);
212 res=xbt_new(s_xbt_cfgelm_t,1);
220 res->content = xbt_dynar_new(sizeof(int), NULL);
223 case xbt_cfgelm_double:
224 res->content = xbt_dynar_new(sizeof(double), NULL);
227 case xbt_cfgelm_string:
228 res->content = xbt_dynar_new(sizeof(char*),&xbt_cfg_str_free);
231 case xbt_cfgelm_host:
232 res->content = xbt_dynar_new(sizeof(xbt_host_t*),&xbt_cfg_host_free);
236 ERROR1("%d is an invalide type code",type);
239 xbt_dict_set((xbt_dict_t)cfg,name,res,&xbt_cfgelm_free);
242 /** @brief Unregister an element from a config set.
244 * @arg cfg the config set
245 * @arg name the name of the elem to be freed
247 * Note that it removes both the description and the actual content.
251 xbt_cfg_unregister(xbt_cfg_t cfg,const char *name) {
252 return xbt_dict_remove((xbt_dict_t)cfg,name);
256 * @brief Parse a string and register the stuff described.
258 * @arg cfg the config set
259 * @arg entry a string describing the element to register
261 * The string may consist in several variable descriptions separated by a space.
262 * Each of them must use the following syntax: \<name\>:\<min nb\>_to_\<max nb\>_\<type\>
263 * with type being one of 'string','int', 'host' or 'double'.
267 xbt_cfg_register_str(xbt_cfg_t cfg,const char *entry) {
268 char *entrycpy=xbt_strdup(entry);
272 e_xbt_cfgelm_type_t type;
274 tok=strchr(entrycpy, ':');
277 "Invalid config element descriptor: ",entry,
278 "; Should be <name>:<min nb>_to_<max nb>_<type>");
284 min=strtol(tok, &tok, 10);
286 ERROR1("Invalid minimum in config element descriptor %s",entry);
291 if (!strcmp(tok,"_to_")){
293 "Invalid config element descriptor: ",entry,
294 "; Should be <name>:<min nb>_to_<max nb>_<type>");
298 tok += strlen("_to_");
300 max=strtol(tok, &tok, 10);
302 ERROR1("Invalid maximum in config element descriptor %s",entry);
309 "Invalid config element descriptor: ",entry,
310 "; Should be <name>:<min nb>_to_<max nb>_<type>");
316 type<xbt_cfgelm_type_count && strcmp(tok,xbt_cfgelm_type_name[type]);
318 if (type == xbt_cfgelm_type_count) {
320 "Invalid type in config element descriptor: ",entry,
321 "; Should be one of 'string', 'int', 'host' or 'double'.");
326 xbt_cfg_register(cfg,entrycpy,type,min,max);
328 free(entrycpy); /* strdup'ed by dict mechanism, but cannot be const */
332 /** @brief Check that each variable have the right amount of values */
335 xbt_cfg_check(xbt_cfg_t cfg) {
336 xbt_dict_cursor_t cursor;
337 xbt_cfgelm_t variable;
341 xbt_assert0(cfg,"NULL config set.");
343 xbt_dict_foreach((xbt_dict_t)cfg,cursor,name,variable) {
344 size = xbt_dynar_length(variable->content);
345 if (variable->min > size) {
346 ERROR4("Config elem %s needs at least %d %s, but there is only %d values.",
349 xbt_cfgelm_type_name[variable->type],
351 xbt_dict_cursor_free(&cursor);
352 return mismatch_error;
355 if (variable->max < size) {
356 ERROR4("Config elem %s accepts at most %d %s, but there is %d values.",
359 xbt_cfgelm_type_name[variable->type],
361 xbt_dict_cursor_free(&cursor);
362 return mismatch_error;
367 xbt_dict_cursor_free(&cursor);
371 static xbt_error_t xbt_cfgelm_get(xbt_cfg_t cfg,
373 e_xbt_cfgelm_type_t type,
374 /* OUT */ xbt_cfgelm_t *whereto){
376 xbt_error_t errcode = xbt_dict_get((xbt_dict_t)cfg,name,
379 if (errcode == mismatch_error) {
380 ERROR1("No registered variable %s in this config set",
382 return mismatch_error;
384 if (errcode != no_error)
387 xbt_assert3((*whereto)->type == type,
388 "You tried to access to the config element %s as an %s, but its type is %s.",
390 xbt_cfgelm_type_name[type],
391 xbt_cfgelm_type_name[(*whereto)->type]);
396 /** @brief Get the type of this variable in that configuration set
398 * \arg cfg the config set
399 * \arg name the name of the element
400 * \arg type the result
405 xbt_cfg_get_type(xbt_cfg_t cfg, const char *name,
406 /* OUT */e_xbt_cfgelm_type_t *type) {
408 xbt_cfgelm_t variable;
411 TRYCATCH(mismatch_error,xbt_dict_get((xbt_dict_t)cfg,name,(void**)&variable));
413 if (errcode == mismatch_error) {
414 ERROR1("Can't get the type of '%s' since this variable does not exist",
416 return mismatch_error;
419 *type=variable->type;
424 /*----[ Setting ]---------------------------------------------------------*/
425 /** @brief va_args version of xbt_cfg_set
427 * \arg cfg config set to fill
428 * \arg varargs NULL-terminated list of pairs {(const char*)key, value}
430 * Add some values to the config set.
431 * \warning if the list isn't NULL terminated, it will segfault.
434 xbt_cfg_set_vargs(xbt_cfg_t cfg, va_list pa) {
438 e_xbt_cfgelm_type_t type;
442 while ((name=va_arg(pa,char *))) {
444 if (!xbt_cfg_get_type(cfg,name,&type)) {
445 ERROR1("Can't set the property '%s' since it's not registered",name);
446 return mismatch_error;
450 case xbt_cfgelm_host:
451 str = va_arg(pa, char *);
453 TRY(xbt_cfg_set_host(cfg,name,str,i));
456 case xbt_cfgelm_string:
457 str=va_arg(pa, char *);
458 TRY(xbt_cfg_set_string(cfg, name, str));
463 TRY(xbt_cfg_set_int(cfg,name,i));
466 case xbt_cfgelm_double:
468 TRY(xbt_cfg_set_double(cfg,name,d));
472 RAISE1(unknown_error,"Config element variable %s not valid.",name);
478 /** @brief Add a NULL-terminated list of pairs {(char*)key, value} to the set
480 * \arg cfg config set to fill
481 * \arg varargs NULL-terminated list of pairs {(const char*)key, value}
483 * \warning if the list isn't NULL terminated, it will segfault.
485 xbt_error_t xbt_cfg_set(xbt_cfg_t cfg, ...) {
490 errcode=xbt_cfg_set_vargs(cfg,pa);
495 /** @brief Add values parsed from a string into a config set
497 * \arg cfg config set to fill
498 * \arg options a string containing the content to add to the config set. This
499 * is a '\\t',' ' or '\\n' separated list of variables. Each individual variable is
500 * like "[name]:[value]" where [name] is the name of an already registred
501 * variable, and [value] conforms to the data type under which this variable was
504 * @todo This is a crude manual parser, it should be a proper lexer.
508 xbt_cfg_set_parse(xbt_cfg_t cfg, const char *options) {
513 xbt_cfgelm_t variable;
514 char *optionlist_cpy;
515 char *option, *name,*val;
521 if (!options || !strlen(options)) { /* nothing to do */
524 optionlist_cpy=xbt_strdup(options);
526 DEBUG1("List to parse and set:'%s'",options);
527 option=optionlist_cpy;
528 while (1) { /* breaks in the code */
534 DEBUG3("Still to parse and set: '%s'. len=%d; option-name=%ld",
535 name,len,(long)(option-name));
538 while (option-name<=(len-1) && *option != ' ' && *option != '\n' && *option != '\t') {
539 DEBUG1("Take %c.\n",*option);
542 if (option-name == len) {
543 DEBUG0("Boundary=EOL\n");
544 option=NULL; /* don't do next iteration */
547 DEBUG3("Boundary on '%c'. len=%d;option-name=%d\n",
548 *option,len,option-name);
550 /* Pass the following blank chars */
552 while (option-name<(len-1) &&
553 (*option == ' ' || *option == '\n' || *option == '\t')) {
554 /* fprintf(stderr,"Ignore a blank char.\n");*/
557 if (option-name == len-1)
558 option=NULL; /* don't do next iteration */
560 DEBUG2("parse now:'%s'; parse later:'%s'",name,option);
562 if (name[0] == ' ' || name[0] == '\n' || name[0] == '\t')
567 val=strchr(name,':');
569 free(optionlist_cpy);
571 "Malformated option: '%s'; Should be of the form 'name:value'",
576 DEBUG2("name='%s';val='%s'",name,val);
578 errcode=xbt_dict_get((xbt_dict_t)cfg,name,(void**)&variable);
583 ERROR1("No registrated variable corresponding to '%s'.",name);
584 free(optionlist_cpy);
585 return mismatch_error;
588 free(optionlist_cpy);
592 switch (variable->type) {
593 case xbt_cfgelm_string:
594 errcode = xbt_cfg_set_string(cfg, name, val);
595 if (errcode != no_error) {
596 free(optionlist_cpy);
602 i=strtol(val, &val, 0);
604 free(optionlist_cpy);
606 "Value of option %s not valid. Should be an integer",
610 errcode = xbt_cfg_set_int(cfg,name,i);
611 if (errcode != no_error) {
612 free(optionlist_cpy);
617 case xbt_cfgelm_double:
620 free(optionlist_cpy);
622 "Value of option %s not valid. Should be a double",
626 errcode = xbt_cfg_set_double(cfg,name,d);
627 if (errcode != no_error) {
628 free(optionlist_cpy);
633 case xbt_cfgelm_host:
637 free(optionlist_cpy);
639 "Value of option %s not valid. Should be an host (machine:port)",
644 i=strtol(val, &val, 0);
646 free(optionlist_cpy);
648 "Value of option %s not valid. Should be an host (machine:port)",
652 errcode = xbt_cfg_set_host(cfg,name,str,i);
653 if (errcode != no_error) {
654 free(optionlist_cpy);
660 free(optionlist_cpy);
661 RAISE1(unknown_error,"Type of config element %s is not valid.",name);
665 free(optionlist_cpy);
669 /** @brief Set or add an integer value to \a name within \a cfg
671 * \arg cfg the config set
672 * \arg name the name of the variable
673 * \arg val the value of the variable
676 xbt_cfg_set_int(xbt_cfg_t cfg,const char*name, int val) {
677 xbt_cfgelm_t variable;
680 VERB2("Configuration setting: %s=%d",name,val);
681 TRY (xbt_cfgelm_get(cfg,name,xbt_cfgelm_int,&variable));
683 if (variable->max > 1) {
684 xbt_dynar_push(variable->content,&val);
686 xbt_dynar_set(variable->content,0,&val);
691 /** @brief Set or add a double value to \a name within \a cfg
693 * \arg cfg the config set
694 * \arg name the name of the variable
695 * \arg val the doule to set
699 xbt_cfg_set_double(xbt_cfg_t cfg,const char*name, double val) {
700 xbt_cfgelm_t variable;
703 VERB2("Configuration setting: %s=%f",name,val);
704 TRY (xbt_cfgelm_get(cfg,name,xbt_cfgelm_double,&variable));
706 if (variable->max > 1) {
707 xbt_dynar_push(variable->content,&val);
709 xbt_dynar_set(variable->content,0,&val);
714 /** @brief Set or add a string value to \a name within \a cfg
716 * \arg cfg the config set
717 * \arg name the name of the variable
718 * \arg val the value to be added
723 xbt_cfg_set_string(xbt_cfg_t cfg,const char*name, const char*val) {
724 xbt_cfgelm_t variable;
726 char *newval = xbt_strdup(val);
728 VERB2("Configuration setting: %s=%s",name,val);
729 TRY (xbt_cfgelm_get(cfg,name,xbt_cfgelm_string,&variable));
731 if (variable->max > 1) {
732 xbt_dynar_push(variable->content,&newval);
734 xbt_dynar_set(variable->content,0,&newval);
739 /** @brief Set or add an host value to \a name within \a cfg
741 * \arg cfg the config set
742 * \arg name the name of the variable
744 * \arg port the port number
746 * \e host values are composed of a string (hostname) and an integer (port)
750 xbt_cfg_set_host(xbt_cfg_t cfg,const char*name,
751 const char *host,int port) {
752 xbt_cfgelm_t variable;
754 xbt_host_t *val=xbt_new(xbt_host_t,1);
756 VERB3("Configuration setting: %s=%s:%d",name,host,port);
758 val->name = xbt_strdup(name);
761 TRY (xbt_cfgelm_get(cfg,name,xbt_cfgelm_host,&variable));
763 if (variable->max > 1) {
764 xbt_dynar_push(variable->content,&val);
766 xbt_dynar_set(variable->content,0,&val);
771 /* ---- [ Removing ] ---- */
773 /** @brief Remove the provided \e val integer value from a variable
775 * \arg cfg the config set
776 * \arg name the name of the variable
777 * \arg val the value to be removed
779 xbt_error_t xbt_cfg_rm_int(xbt_cfg_t cfg,const char*name, int val) {
781 xbt_cfgelm_t variable;
785 TRY (xbt_cfgelm_get(cfg,name,xbt_cfgelm_int,&variable));
787 xbt_dynar_foreach(variable->content,cpt,seen) {
789 xbt_dynar_cursor_rm(variable->content,&cpt);
794 ERROR2("Can't remove the value %d of config element %s: value not found.",
796 return mismatch_error;
799 /** @brief Remove the provided \e val double value from a variable
801 * \arg cfg the config set
802 * \arg name the name of the variable
803 * \arg val the value to be removed
806 xbt_error_t xbt_cfg_rm_double(xbt_cfg_t cfg,const char*name, double val) {
807 xbt_cfgelm_t variable;
812 TRY (xbt_cfgelm_get(cfg,name,xbt_cfgelm_double,&variable));
814 xbt_dynar_foreach(variable->content,cpt,seen) {
816 xbt_dynar_cursor_rm(variable->content,&cpt);
821 ERROR2("Can't remove the value %f of config element %s: value not found.",
823 return mismatch_error;
826 /** @brief Remove the provided \e val string value from a variable
828 * \arg cfg the config set
829 * \arg name the name of the variable
830 * \arg val the value of the string which will be removed
833 xbt_cfg_rm_string(xbt_cfg_t cfg,const char*name, const char *val) {
834 xbt_cfgelm_t variable;
839 TRY (xbt_cfgelm_get(cfg,name,xbt_cfgelm_string,&variable));
841 xbt_dynar_foreach(variable->content,cpt,seen) {
842 if (!strcpy(seen,val)) {
843 xbt_dynar_cursor_rm(variable->content,&cpt);
848 ERROR2("Can't remove the value %s of config element %s: value not found.",
850 return mismatch_error;
853 /** @brief Remove the provided \e val host value from a variable
855 * \arg cfg the config set
856 * \arg name the name of the variable
857 * \arg host the hostname
858 * \arg port the port number
862 xbt_cfg_rm_host(xbt_cfg_t cfg,const char*name, const char *host,int port) {
863 xbt_cfgelm_t variable;
868 TRY (xbt_cfgelm_get(cfg,name,xbt_cfgelm_host,&variable));
870 xbt_dynar_foreach(variable->content,cpt,seen) {
871 if (!strcpy(seen->name,host) && seen->port == port) {
872 xbt_dynar_cursor_rm(variable->content,&cpt);
877 ERROR3("Can't remove the value %s:%d of config element %s: value not found.",
879 return mismatch_error;
882 /** @brief Remove all the values from a variable
884 * \arg cfg the config set
885 * \arg name the name of the variable
889 xbt_cfg_empty(xbt_cfg_t cfg,const char*name) {
890 xbt_cfgelm_t variable;
894 TRYCATCH(mismatch_error,
895 xbt_dict_get((xbt_dict_t)cfg,name,(void**)&variable));
896 if (errcode == mismatch_error) {
897 ERROR1("Can't empty '%s' since this config element does not exist",
899 return mismatch_error;
903 xbt_dynar_reset(variable->content);
908 /*----[ Getting ]---------------------------------------------------------*/
910 /** @brief Retrieve an integer value of a variable (get a warning if not uniq)
912 * \arg cfg the config set
913 * \arg name the name of the variable
914 * \arg val the wanted value
916 * Returns the first value from the config set under the given name.
917 * If there is more than one value, it will issue a warning. Consider using
918 * xbt_cfg_get_dynar() instead.
920 * \warning the returned value is the actual content of the config set
923 xbt_cfg_get_int (xbt_cfg_t cfg,
926 xbt_cfgelm_t variable;
929 TRY (xbt_cfgelm_get(cfg,name,xbt_cfgelm_int,&variable));
931 if (xbt_dynar_length(variable->content) > 1) {
932 WARN2("You asked for the first value of the config element '%s', but there is %lu values",
933 name, xbt_dynar_length(variable->content));
936 *val = xbt_dynar_get_as(variable->content, 0, int);
940 /** @brief Retrieve a double value of a variable (get a warning if not uniq)
942 * \arg cfg the config set
943 * \arg name the name of the variable
944 * \arg val the wanted value
946 * Returns the first value from the config set under the given name.
947 * If there is more than one value, it will issue a warning. Consider using
948 * xbt_cfg_get_dynar() instead.
950 * \warning the returned value is the actual content of the config set
954 xbt_cfg_get_double(xbt_cfg_t cfg,
957 xbt_cfgelm_t variable;
960 TRY (xbt_cfgelm_get(cfg,name,xbt_cfgelm_double,&variable));
962 if (xbt_dynar_length(variable->content) > 1) {
963 WARN2("You asked for the first value of the config element '%s', but there is %lu values\n",
964 name, xbt_dynar_length(variable->content));
967 *val = xbt_dynar_get_as(variable->content, 0, double);
971 /** @brief Retrieve a string value of a variable (get a warning if not uniq)
973 * \arg th the config set
974 * \arg name the name of the variable
975 * \arg val the wanted value
977 * Returns the first value from the config set under the given name.
978 * If there is more than one value, it will issue a warning. Consider using
979 * xbt_cfg_get_dynar() instead.
981 * \warning the returned value is the actual content of the config set
984 xbt_error_t xbt_cfg_get_string(xbt_cfg_t cfg,
987 xbt_cfgelm_t variable;
992 TRY (xbt_cfgelm_get(cfg,name,xbt_cfgelm_string,&variable));
994 if (xbt_dynar_length(variable->content) > 1) {
995 WARN2("You asked for the first value of the config element '%s', but there is %lu values\n",
996 name, xbt_dynar_length(variable->content));
999 *val = xbt_dynar_get_as(variable->content, 0, char *);
1003 /** @brief Retrieve an host value of a variable (get a warning if not uniq)
1005 * \arg cfg the config set
1006 * \arg name the name of the variable
1007 * \arg host the host
1008 * \arg port the port number
1010 * Returns the first value from the config set under the given name.
1011 * If there is more than one value, it will issue a warning. Consider using
1012 * xbt_cfg_get_dynar() instead.
1014 * \warning the returned value is the actual content of the config set
1017 xbt_error_t xbt_cfg_get_host (xbt_cfg_t cfg,
1021 xbt_cfgelm_t variable;
1022 xbt_error_t errcode;
1025 TRY (xbt_cfgelm_get(cfg,name,xbt_cfgelm_host,&variable));
1027 if (xbt_dynar_length(variable->content) > 1) {
1028 WARN2("You asked for the first value of the config element '%s', but there is %lu values\n",
1029 name, xbt_dynar_length(variable->content));
1032 val = xbt_dynar_get_as(variable->content, 0, xbt_host_t*);
1039 /** @brief Retrieve the dynar of all the values stored in a variable
1041 * \arg cfg where to search in
1042 * \arg name what to search for
1045 * Get the data stored in the config set.
1047 * \warning the returned value is the actual content of the config set
1049 xbt_error_t xbt_cfg_get_dynar (xbt_cfg_t cfg,
1051 xbt_dynar_t *dynar) {
1052 xbt_cfgelm_t variable;
1053 xbt_error_t errcode = xbt_dict_get((xbt_dict_t)cfg,name,
1056 if (errcode == mismatch_error) {
1057 ERROR1("No registered variable %s in this config set",
1059 return mismatch_error;
1061 if (errcode != no_error)
1064 *dynar = variable->content;