[88] | 1 | /* |
---|
| 2 | * $Id: Instance_getParam.cpp 97 2008-12-19 15:34:00Z rosiere $ |
---|
| 3 | * |
---|
| 4 | * [ Description ] |
---|
| 5 | * |
---|
| 6 | */ |
---|
| 7 | |
---|
| 8 | #include "Behavioural/Configuration/include/Instance.h" |
---|
| 9 | |
---|
| 10 | namespace morpheo { |
---|
| 11 | namespace behavioural { |
---|
| 12 | namespace configuration { |
---|
| 13 | |
---|
| 14 | #undef FUNCTION |
---|
| 15 | #define FUNCTION "Instance::getParam" |
---|
| 16 | std::string Instance::getParam (const char * name, ...) |
---|
| 17 | { |
---|
| 18 | log_begin(Configuration,FUNCTION); |
---|
| 19 | |
---|
| 20 | std::string value = ""; |
---|
| 21 | |
---|
| 22 | // Go to the good component |
---|
| 23 | list_parameters_t * list_parameters = _list_parameters; |
---|
| 24 | list_components_t * list_components = _list_components; |
---|
| 25 | |
---|
| 26 | { |
---|
| 27 | va_list args; |
---|
| 28 | va_start(args, name); |
---|
| 29 | |
---|
| 30 | std::string component = ""; |
---|
| 31 | std::string id = ""; |
---|
| 32 | std::string tmp; |
---|
| 33 | while (((tmp = va_arg(args,const char *)) != "") and |
---|
| 34 | (value == "")) |
---|
| 35 | { |
---|
| 36 | // 2 string : |
---|
| 37 | // * first : component |
---|
| 38 | // * second : id |
---|
| 39 | |
---|
| 40 | component = tmp; |
---|
| 41 | |
---|
| 42 | if ((tmp = va_arg(args,const char *)) == "") |
---|
| 43 | throw ERRORMORPHEO(FUNCTION,_("Must have two name : first is the component's name, second is the identification\n")); |
---|
| 44 | id = tmp; |
---|
| 45 | |
---|
| 46 | list_instances_t::iterator it=((*list_components)[component]).find(id); |
---|
| 47 | |
---|
| 48 | if (it == ((*list_components)[component]).end()) |
---|
| 49 | { |
---|
[97] | 50 | //log_printf(INFO,Configuration,FUNCTION,_("Component \"%s[%s]\" is not define, take default value for parameter \"%s\"."),component.c_str(),id.c_str(),name); |
---|
[88] | 51 | |
---|
| 52 | value = _generator->getParam(name)->_default; |
---|
| 53 | } |
---|
| 54 | else |
---|
| 55 | { |
---|
| 56 | list_parameters = it->second->_list_parameters; |
---|
| 57 | list_components = it->second->_list_components; |
---|
| 58 | } |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | if (value == "") |
---|
| 62 | { |
---|
| 63 | // no default value : component is find |
---|
| 64 | |
---|
| 65 | // Test if parameters exist |
---|
| 66 | // std::map<std::string, Parameter_affectation *> |
---|
| 67 | list_parameters_t::iterator it=(*list_parameters).find(name); |
---|
| 68 | if (it == (*list_parameters).end()) |
---|
| 69 | { |
---|
[97] | 70 | //log_printf(INFO,Configuration,FUNCTION,_("Component \"%s[%s]\" is define, but parameter \"%s\" is not define. Take default value."),component.c_str(),id.c_str(),name); |
---|
[88] | 71 | |
---|
| 72 | value = _generator->getParam(name)->_default; |
---|
| 73 | } |
---|
| 74 | else |
---|
| 75 | { |
---|
| 76 | if (it->second->_use) |
---|
| 77 | throw ERRORMORPHEO(FUNCTION,toString(_("Parameter \"%s\" is already used.\n"),name)); |
---|
| 78 | |
---|
| 79 | value = it->second->_value; |
---|
| 80 | it->second->_use = true; // now, this parameters is use |
---|
| 81 | } |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | va_end(args); |
---|
| 85 | } |
---|
| 86 | |
---|
[97] | 87 | //log_printf(INFO,Configuration,FUNCTION,_("Parameters \"%s\" = %s."),name,value.c_str()); |
---|
[88] | 88 | |
---|
| 89 | log_end(Configuration,FUNCTION); |
---|
| 90 | |
---|
| 91 | return value; |
---|
| 92 | }; |
---|
| 93 | |
---|
| 94 | }; // end namespace configuration |
---|
| 95 | }; // end namespace behavioural |
---|
| 96 | }; // end namespace morpheo |
---|