[88] | 1 | /* |
---|
| 2 | * $Id: Parameter_definition_test.cpp 88 2008-12-10 18:31:39Z rosiere $ |
---|
| 3 | * |
---|
| 4 | * [ Description ] |
---|
| 5 | * |
---|
| 6 | */ |
---|
| 7 | |
---|
| 8 | #include "Behavioural/Configuration/include/Parameter_definition.h" |
---|
| 9 | #include "Behavioural/include/Stat_binary_tree.h" |
---|
| 10 | #include "Common/include/FromString.h" |
---|
| 11 | |
---|
| 12 | namespace morpheo { |
---|
| 13 | namespace behavioural { |
---|
| 14 | namespace configuration { |
---|
| 15 | |
---|
| 16 | #undef FUNCTION |
---|
| 17 | #define FUNCTION "Parameter_definition::test" |
---|
| 18 | void Parameter_definition::test (std::string x) |
---|
| 19 | { |
---|
| 20 | log_begin(Configuration,FUNCTION); |
---|
| 21 | |
---|
| 22 | std::map<std::string, counter_t*> * operand = new std::map<std::string, counter_t*>; |
---|
| 23 | |
---|
| 24 | std::string expr = _step+" "+_name; |
---|
| 25 | std::string expr_str = _name + "(n+1) = "+_step+" "+_name+"(n)"; |
---|
| 26 | |
---|
| 27 | counter_t value; |
---|
| 28 | (*operand)[_name] = &value; |
---|
| 29 | |
---|
| 30 | Stat_binary_tree * tree; |
---|
| 31 | try |
---|
| 32 | { |
---|
| 33 | tree = new Stat_binary_tree(expr,operand); |
---|
| 34 | } |
---|
| 35 | catch (morpheo::ErrorMorpheo & error) |
---|
| 36 | { |
---|
| 37 | throw (ERRORMORPHEO (FUNCTION,toString(_("step make an invalid infix expression : \"%s\"\n"),expr_str.c_str()))); |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | counter_t min = fromString<counter_t>(_min); |
---|
| 41 | counter_t max = fromString<counter_t>(_max); |
---|
| 42 | |
---|
| 43 | value = min; |
---|
| 44 | while ((value != fromString<counter_t>(x)) and (value <= max)) |
---|
| 45 | { |
---|
| 46 | counter_t tmp = tree->eval(); |
---|
| 47 | |
---|
| 48 | // warning, can have infinite loop |
---|
| 49 | value = (tmp == value)?(max+1):tmp; |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | if (value > max) |
---|
| 53 | { |
---|
| 54 | throw (ERRORMORPHEO (FUNCTION,toString(_("With the expression \"%s\" and \"%s(0) = %s\" and value between [%s:%s], \"%s(n) = %s\" is not a valid value.\n"),expr_str.c_str(),_name.c_str(),_min.c_str(),_min.c_str(),_max.c_str(),_name.c_str(),x.c_str()))); |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | delete tree; |
---|
| 58 | |
---|
| 59 | log_end(Configuration,FUNCTION); |
---|
| 60 | }; |
---|
| 61 | |
---|
| 62 | }; // end namespace configuration |
---|
| 63 | }; // end namespace behavioural |
---|
| 64 | }; // end namespace morpheo |
---|