1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
\r
6 * Created on: Apr 17, 2014
\r
10 #include "Config_Common.h"
\r
11 #include <Config_Keywords.h>
\r
13 #include <libxml/parser.h>
\r
14 #include <libxml/tree.h>
\r
16 #include <sstream> // for stringstream
\r
19 #include <algorithm> // for std::transform
\r
21 bool isElementNode(xmlNodePtr theNode)
\r
25 return theNode->type == XML_ELEMENT_NODE;
\r
28 bool isNode(xmlNodePtr theNode, const char* theNodeName, ...)
\r
30 bool result = false;
\r
31 const xmlChar* aName = theNode->name;
\r
32 if (!aName || !isElementNode(theNode)) {
\r
35 if (!xmlStrcmp(aName, (const xmlChar *) theNodeName)) {
\r
38 va_list args; // define argument list variable
\r
39 va_start(args, theNodeName); // init list; point to last defined argument
\r
41 char *anArg = va_arg (args, char*); // get next argument
\r
44 if (!xmlStrcmp(aName, (const xmlChar *) anArg)) {
\r
45 va_end(args); // cleanup the system stack
\r
49 va_end(args); // cleanup the system stack
\r
53 bool isWidgetNode(xmlNodePtr theNode)
\r
55 if(!isElementNode(theNode))
\r
57 // it's parent is "feature" or "source"
\r
58 xmlNodePtr aParentNode = theNode->parent;
\r
59 if(!isNode(aParentNode, NODE_FEATURE, NODE_SOURCE, NULL))
\r
62 //it should not be a "source" or a "validator" node
\r
63 return !isNode(theNode, NODE_SOURCE, NODE_VALIDATOR, NODE_SELFILTER, NULL);
\r
66 bool hasChild(xmlNodePtr theNode)
\r
68 xmlNodePtr aNode = theNode->children;
\r
69 for (; aNode; aNode = aNode->next) {
\r
70 if (isElementNode(theNode)) {
\r
77 bool getParametersInfo(xmlNodePtr theNode, std::string& outPropertyId,
\r
78 std::list<std::string>& outValidatorParameters)
\r
81 char* anIdProp = (char*) xmlGetProp(theNode, BAD_CAST _ID);
\r
82 if (!anIdProp || anIdProp[0] == 0) {
\r
85 outPropertyId = std::string(anIdProp);
\r
87 //Property parameters:
\r
88 char* aParamProp = (char*) xmlGetProp(theNode, BAD_CAST _PARAMETERS);
\r
89 if (aParamProp && aParamProp[0] != 0) {
\r
90 std::string aPropString = std::string(aParamProp);
\r
91 std::stringstream aPropStringStream(aPropString);
\r
92 char COMMA_DELIM = ',';
\r
93 std::string aParameter;
\r
94 while (std::getline(aPropStringStream, aParameter, ',')) {
\r
95 outValidatorParameters.push_back(aParameter);
\r
101 std::string library(const std::string& theLibName)
\r
103 if(theLibName.empty())
\r
104 return std::string();
\r
105 std::string aLibName = theLibName;
\r
107 static std::string aLibExt( ".so" );
\r
108 if (aLibName.size() < 3 || aLibName.substr(0, 3) !="lib") {
\r
109 aLibName = "lib" + aLibName;
\r
112 static std::string aLibExt(".dll");
\r
114 std::string anExt = aLibName.substr(aLibName.size() - 4);
\r
115 if (anExt != aLibExt)
\r
116 aLibName += aLibExt;
\r
121 std::string getProperty(xmlNodePtr theNode, const char* thePropName)
\r
123 std::string result = "";
\r
124 char* aPropChars = (char*) xmlGetProp(theNode, BAD_CAST thePropName);
\r
125 if (!aPropChars || aPropChars[0] == 0)
\r
127 result = std::string(aPropChars);
\r
131 bool getBooleanAttribute(xmlNodePtr theNode, const char* theAttributeName, bool theDefault)
\r
133 std::string prop = normalize(getProperty(theNode, theAttributeName));
\r
134 bool result = theDefault;
\r
135 if (prop == "true" || prop == "1") {
\r
137 } else if (prop == "false" || prop == "0") {
\r
143 CONFIG_EXPORT std::string normalize(const char* theString)
\r
146 return std::string();
\r
147 return normalize(std::string(theString));
\r
150 CONFIG_EXPORT std::string normalize(const std::string& theString)
\r
152 std::string result = theString;
\r
153 std::transform(result.begin(), result.end(), result.begin(), ::tolower);
\r