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