5#ifndef _TARCH_CONFIGURATION_PARSECONFIGURATION_H_
6#define _TARCH_CONFIGURATION_PARSECONFIGURATION_H_
7#include "tarch/la/Vector.h"
8#include "tarch/tinyxml2/tinyxml2.h"
26 class XMLConfiguration {
45 static XMLConfiguration
load(
const std::string filename) {
51 std::cout <<
"No root node <scenario-configuration> found in configuration file. (Using legacy format without XML root node.)" << std::endl;
67 std::cout <<
"Could not read input file " << filename <<
" (missing or invalid)" << std::endl;
82 std::cout <<
"Error while reading mandatory argument " << tag <<
" of XML element " << node->
Name() << std::endl;
99 if (result == tinyxml2::XML_NO_ATTRIBUTE) {
101 }
else if (result == tinyxml2::XML_WRONG_ATTRIBUTE_TYPE) {
102 std::cout <<
"Error while reading optional argument " << tag <<
" of XML element " << node->
Name() << std::endl;
118 std::cout <<
"Error while reading mandatory argument " << tag <<
" of XML element " << node->
Name() << std::endl;
135 if (result == tinyxml2::XML_NO_ATTRIBUTE) {
137 }
else if (result == tinyxml2::XML_WRONG_ATTRIBUTE_TYPE) {
138 std::cout <<
"Error while reading optional argument " << tag <<
" of XML element " << node->
Name() << std::endl;
152 const char* myTextChar = node->
Attribute(tag.c_str());
153 if (myTextChar == NULL) {
154 std::cout <<
"Error: mandatory bool " << tag <<
" could not be found!" << std::endl;
157 std::string myText(myTextChar);
158 if (myText ==
"yes") {
160 }
else if (myText ==
"no") {
163 std::cout <<
"Error while reading bool optional argument: Argument can "
178 const char* myTextChar = node->
Attribute(tag.c_str());
179 if (myTextChar == NULL) {
182 std::string myText(myTextChar);
183 if (myText ==
"yes") {
185 }
else if (myText ==
"no") {
188 std::cout <<
"Error while reading bool optional argument: Argument can "
202 const char* myText = node->
Attribute(tag.c_str());
203 if (myText == NULL) {
204 std::cout <<
"Error while reading mandatory argument " << tag <<
" of XML element " << node->
Name() << std::endl;
207 storage = std::string(myText);
219 const char* myText = node->
Attribute(tag.c_str());
220 if (myText != NULL) {
221 storage = std::string(myText);
233 std::string input(myText);
234 for (
unsigned int i = 0; i < size; i++) {
236 std::size_t first = input.find_first_not_of(
" ");
239 std::size_t last = input.find_first_of(
";");
242 if ((i == size - 1) && (last == std::string::npos)) {
246 std::stringstream ss(input.substr(first, last - first));
251 input = input.substr(last + 1, input.size() - last - 1);
265 const char* myText = node->
Attribute(tag.c_str());
266 if (myText == NULL) {
267 std::cout <<
"Error while reading mandatory argument " << tag <<
" of XML element " << node->
Name() << std::endl;
283 const char* myText = node->
Attribute(tag.c_str());
284 if (myText != NULL) {
Definition Configuration.h:22
virtual void parseSubtag(tinyxml2::XMLElement *node)=0
Definition ParseConfiguration.h:26
static XMLConfiguration load(const std::string filename)
Definition ParseConfiguration.h:45
tinyxml2::XMLError const error
Definition ParseConfiguration.h:39
tinyxml2::XMLNode *const root
Definition ParseConfiguration.h:34
Definition ParseConfiguration.h:20
static void readBoolMandatory(bool &storage, tinyxml2::XMLElement *node, std::string tag)
Definition ParseConfiguration.h:151
static void readStringMandatory(std::string &storage, tinyxml2::XMLElement *node, std::string tag)
Definition ParseConfiguration.h:201
static void readVectorMandatory(tarch::la::Vector< size, T > &result, tinyxml2::XMLElement *node, std::string tag)
Definition ParseConfiguration.h:264
static void readStringOptional(std::string &storage, tinyxml2::XMLElement *node, std::string tag)
Definition ParseConfiguration.h:218
static void readIntOptional(int &storage, tinyxml2::XMLElement *node, std::string tag)
Definition ParseConfiguration.h:132
static void parseConfiguration(const std::string filename, const std::string topleveltag, Configuration &config)
Definition ParseConfiguration.h:63
static void readIntMandatory(int &storage, tinyxml2::XMLElement *node, std::string tag)
Definition ParseConfiguration.h:115
static void readVectorOptional(tarch::la::Vector< size, T > &result, tinyxml2::XMLElement *node, std::string tag)
Definition ParseConfiguration.h:282
static void readDoubleOptional(double &storage, tinyxml2::XMLElement *node, std::string tag)
Definition ParseConfiguration.h:96
static void readDoubleMandatory(double &storage, tinyxml2::XMLElement *node, std::string tag)
Definition ParseConfiguration.h:79
static void readVector(tarch::la::Vector< size, T > &result, const char *myText)
Definition ParseConfiguration.h:232
static void readBoolOptional(bool &storage, tinyxml2::XMLElement *node, std::string tag)
Definition ParseConfiguration.h:177
Definition tinyxml2.h:1721
XMLError LoadFile(const char *filename)
Definition tinyxml2.h:1268
const char * Attribute(const char *name, const char *value=0) const
XMLError QueryDoubleAttribute(const char *name, double *value) const
See QueryIntAttribute()
Definition tinyxml2.h:1390
XMLError QueryIntAttribute(const char *name, int *value) const
Definition tinyxml2.h:1346
const char * Name() const
Get the name of an element (which is the Value() of the node.)
Definition tinyxml2.h:1272
Definition tinyxml2.h:672
const XMLElement * FirstChildElement(const char *name=0) const
const XMLDocument * GetDocument() const
Get the XMLDocument that owns this XMLNode.
Definition tinyxml2.h:678
Definition Configuration.h:13
Definition Configuration.h:11