[88] | 1 | /* |
---|
| 2 | * $Id: Simulator_fromFile.cpp 118 2009-05-20 22:01:32Z rosiere $ |
---|
| 3 | * |
---|
| 4 | * [ Description ] |
---|
| 5 | * |
---|
| 6 | */ |
---|
| 7 | |
---|
| 8 | #include "Behavioural/Configuration/include/Simulator.h" |
---|
[112] | 9 | #include "Behavioural/include/Simulation.h" |
---|
[88] | 10 | #include "Common/include/FromString.h" |
---|
| 11 | #include <fstream> |
---|
| 12 | |
---|
| 13 | namespace morpheo { |
---|
| 14 | namespace behavioural { |
---|
| 15 | namespace configuration { |
---|
| 16 | |
---|
| 17 | using namespace XMLUtils; |
---|
| 18 | |
---|
| 19 | #undef FUNCTION |
---|
| 20 | #define FUNCTION "Simulator::fromFile" |
---|
| 21 | void Simulator::fromFile (std::string filename) |
---|
| 22 | { |
---|
| 23 | log_begin(Configuration,FUNCTION); |
---|
| 24 | |
---|
| 25 | msg_printf(INFORMATION,_("Read file \"%s\"."),filename.c_str()); |
---|
| 26 | |
---|
| 27 | std::ifstream file (filename.c_str()); |
---|
| 28 | |
---|
| 29 | // Test the file open |
---|
| 30 | if (!file) |
---|
| 31 | throw ERRORMORPHEO(FUNCTION,toString(_("Error opening \"%s\" file.\n"),filename.c_str())); |
---|
| 32 | |
---|
| 33 | XML_t * _xml = new FileXMLLight<char,ClassicReferenceCounter>(file); |
---|
| 34 | |
---|
| 35 | // Test root node : Root name, must not a singleton, have none attribute |
---|
| 36 | testNodeName (_xml,"parameters"); |
---|
| 37 | testSingleton (_xml,false); |
---|
| 38 | testNoAttribute(_xml); |
---|
| 39 | |
---|
| 40 | XMLLightVector<XML_t> vect = _xml->getNodes(); |
---|
| 41 | |
---|
| 42 | // std::cout << vect << std::endl; |
---|
| 43 | |
---|
| 44 | for (uint32_t i=0; i<vect.size(); ++i) |
---|
| 45 | { |
---|
| 46 | XML_t * xml = vect[i]; |
---|
| 47 | |
---|
[108] | 48 | std::string child_name = xml->getName(); |
---|
[88] | 49 | |
---|
[108] | 50 | //-------------------------------------------- |
---|
| 51 | // Child : Parameter |
---|
| 52 | //-------------------------------------------- |
---|
| 53 | if (child_name == "parameter") |
---|
| 54 | { |
---|
| 55 | // testNodeName (xml,"parameter"); |
---|
| 56 | testSingleton (xml,true); |
---|
| 57 | |
---|
| 58 | // Take attributes of this tag |
---|
| 59 | |
---|
| 60 | attributes_t attributes = xml->getAttributes(); |
---|
| 61 | |
---|
| 62 | // std::cout << "Node [" << name << "]" << std::endl; |
---|
| 63 | // std::cout << " * nb attributes : " << xml->getAttributes().size() << std::endl; |
---|
| 64 | |
---|
| 65 | attribute_t value_name = getAttribute(xml,attributes,"name" ); |
---|
| 66 | attribute_t value = getAttribute(xml,attributes,"value"); |
---|
| 67 | |
---|
| 68 | testAttributesEmpty(xml,attributes); |
---|
| 69 | |
---|
| 70 | // Insert in array |
---|
| 71 | Parameter_affectation * param = new Parameter_affectation(value_name, |
---|
| 72 | value ); |
---|
| 73 | |
---|
| 74 | insert(param); |
---|
| 75 | } |
---|
| 76 | //-------------------------------------------- |
---|
[110] | 77 | // Child : Component |
---|
[108] | 78 | //-------------------------------------------- |
---|
| 79 | else |
---|
| 80 | { |
---|
[110] | 81 | testNodeName (xml,"component"); |
---|
[108] | 82 | testSingleton (xml,true); |
---|
[112] | 83 | |
---|
[118] | 84 | attributes_t attributes = xml->getAttributes(); |
---|
[112] | 85 | |
---|
[118] | 86 | std::string value_name = getAttribute(xml,attributes,"name" ); |
---|
| 87 | model_type_t value_model = fromString<model_type_t >(getAttribute(xml,attributes,"model")); |
---|
| 88 | bool value_debug = fromString<bool>(getAttribute(xml,attributes,"debug")); |
---|
[112] | 89 | |
---|
| 90 | testAttributesEmpty(xml,attributes); |
---|
| 91 | |
---|
| 92 | _model.set_model(value_name, value_model, value_debug); |
---|
[108] | 93 | } |
---|
[88] | 94 | } |
---|
| 95 | |
---|
| 96 | delete _xml; |
---|
| 97 | |
---|
| 98 | log_end(Configuration,FUNCTION); |
---|
| 99 | }; |
---|
| 100 | |
---|
| 101 | }; // end namespace configuration |
---|
| 102 | }; // end namespace behavioural |
---|
| 103 | }; // end namespace morpheo |
---|