33 #include <Rcs_parser.h> 34 #include <Rcs_stlParser.h> 35 #include <Rcs_macros.h> 36 #include <Rcs_resourcePath.h> 48 char filename[256] =
"";
49 bool fileExists = Rcs_getAbsoluteFileName(configFile, filename);
52 RMSG(
"Resource path is:");
53 Rcs_printResourcePath();
54 RFATAL(
"Experiment configuration file \"%s\" not found in " 55 "ressource path - exiting", configFile ? configFile :
"NULL");
59 node = parseXMLFile(filename,
"Experiment", &
doc);
72 if (it.second !=
empty()) {
77 for (
auto le : it.second) {
96 if (!getXMLNodeProperty(
node, property)) {
100 getXMLNodePropertySTLString(
node, property, out);
107 if (!getXMLNodeProperty(
node, property)) {
110 getXMLNodePropertyVecSTLString(
node, property, out);
117 if (!getXMLNodeProperty(
node, property)) {
121 if (!getXMLNodePropertyDouble(
node, property, &out)) {
122 std::ostringstream os;
123 os <<
"Invalid double value: ";
125 getXMLNodePropertySTLString(
node, property, value);
127 throw std::invalid_argument(os.str());
135 if (!getXMLNodeProperty(
node, property)) {
139 if (!getXMLNodePropertyInt(
node, property, &out)) {
140 std::ostringstream os;
141 os <<
"Invalid double value: ";
143 getXMLNodePropertySTLString(
node, property, value);
145 throw std::invalid_argument(os.str());
153 if (!getXMLNodeProperty(
node, property)) {
157 std::vector<std::string> entries;
158 getXMLNodePropertyVecSTLString(
node, property, entries);
161 out = MatNd_create(entries.size(), 1);
164 for (std::size_t i = 0; i < entries.size(); ++i) {
166 std::istringstream is(entries[i]);
167 is.imbue(std::locale(
"C"));
169 if (!(is >> out->ele[i])) {
176 std::ostringstream os;
177 os <<
"Invalid matrix entry value # " << i <<
": " << entries[i];
178 throw std::invalid_argument(os.str());
187 if (!getXMLNodeProperty(
node, property)) {
192 getXMLNodePropertyBoolString(
node, property, &res);
198 std::string prefixStr = prefix;
200 auto iter =
children.find(prefixStr);
205 xmlNodePtr childNode = getXMLChildByName(
node, prefix);
208 if (childNode == NULL) {
220 std::string prefixStr = prefix;
230 xmlNodePtr child =
node->children;
232 if (STRCASEEQ((
const char*) BAD_CAST child->name, prefix)) {
244 xmlDocPtr cpdoc = xmlNewDoc(NULL);
245 xmlNodePtr cpnode = xmlDocCopyNode(
node, cpdoc, 1);
246 xmlDocSetRootElement(cpdoc, cpnode);
255 xmlDocPtr writeDoc =
doc;
256 if (writeDoc == NULL || !isXMLNodeName(
node, rootNodeName)) {
258 writeDoc = xmlNewDoc(NULL);
259 xmlNodePtr cpnode = xmlDocCopyNode(
node, writeDoc, 1);
260 xmlNodeSetName(cpnode, BAD_CAST rootNodeName);
261 xmlDocSetRootElement(writeDoc, cpnode);
265 xmlIndentTreeOutput = 1;
266 xmlSaveFormatFile(fileName, writeDoc, 1);
269 if (writeDoc !=
doc) {
270 xmlFreeDoc(writeDoc);
virtual const std::vector< PropertySource * > & getChildList(const char *prefix)
std::map< std::string, PropertySource * > children
virtual void saveXML(const char *fileName, const char *rootNodeName)
virtual bool getProperty(std::string &out, const char *property)
static PropertySource * empty()
virtual PropertySource * clone() const
virtual PropertySource * getChild(const char *prefix)
std::map< std::string, std::vector< PropertySource * > > listChildren
PropertySourceXml(xmlNodePtr node, xmlDocPtr doc=NULL)
virtual ~PropertySourceXml()
virtual bool getPropertyBool(const char *property, bool def=false)