+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D\r
+\r
/*\r
* Config_Common.cpp\r
*\r
#include <sstream> // for stringstream\r
\r
#include <string>\r
-#include <algorithm> // for std::transform\r\r
+#include <algorithm> // for std::transform\r
+\r
bool isElementNode(xmlNodePtr theNode)\r
{\r
+ if (!theNode)\r
+ return false;\r
return theNode->type == XML_ELEMENT_NODE;\r
}\r
\r
bool isNode(xmlNodePtr theNode, const char* theNodeName, ...)\r
{\r
- bool result = false;\r
const xmlChar* aName = theNode->name;\r
if (!aName || !isElementNode(theNode)) {\r
return false;\r
return false;\r
}\r
\r
+bool isAttributeNode(xmlNodePtr theNode)\r
+{\r
+ if(!isElementNode(theNode))\r
+ return false;\r
+ // it's parent is "feature" or "source" or page ("case" or "box")\r
+ if(!hasParent(theNode, NODE_FEATURE, NODE_SOURCE, \r
+ WDG_TOOLBOX_BOX, WDG_SWITCH_CASE, NULL))\r
+ return false;\r
+\r
+ //it should not be a "source" or a "validator" node\r
+ bool isLogical = isNode(theNode, NODE_SOURCE, NODE_VALIDATOR, NODE_SELFILTER, NULL);\r
+ bool isPagedContainer = isNode(theNode, WDG_TOOLBOX, WDG_TOOLBOX_BOX,\r
+ WDG_SWITCH, WDG_SWITCH_CASE, NULL);\r
+ return !isLogical && !isPagedContainer;\r
+}\r
+\r
bool isWidgetNode(xmlNodePtr theNode)\r
{\r
if(!isElementNode(theNode))\r
return false;\r
- // it's parent is "feature" or "source"\r
- xmlNodePtr aParentNode = theNode->parent;\r
- if(!isNode(aParentNode, NODE_FEATURE, NODE_SOURCE, NULL))\r
+ // it's parent is "feature" or "source" or a page ("box", "case")\r
+ if(!hasParent(theNode, NODE_FEATURE, NODE_SOURCE, WDG_GROUP,\r
+ WDG_TOOLBOX_BOX, WDG_SWITCH_CASE, NULL))\r
return false;\r
\r
//it should not be a "source" or a "validator" node\r
- return !isNode(theNode, NODE_SOURCE, NODE_VALIDATOR, NULL);\r
+ return !isNode(theNode, NODE_SOURCE, NODE_VALIDATOR, NODE_SELFILTER, NULL);\r
+}\r
+\r
+// widget api?\r
+bool isCaseNode(xmlNodePtr theNode)\r
+{\r
+ if(!isElementNode(theNode))\r
+ return false;\r
+\r
+ return isNode(theNode, WDG_SWITCH_CASE, WDG_TOOLBOX_BOX, NULL);\r
}\r
\r
bool hasChild(xmlNodePtr theNode)\r
return false;\r
}\r
\r
-bool getValidatorInfo(xmlNodePtr theNode, std::string& outValidatorId,\r
+bool hasParent(xmlNodePtr theNode)\r
+{\r
+ xmlNodePtr aNode = theNode->parent;\r
+ if (!aNode) {\r
+ return false;\r
+ }\r
+ for (; aNode; aNode = aNode->next) {\r
+ if (isElementNode(theNode)) {\r
+ return true;\r
+ }\r
+ }\r
+ return false;\r
+}\r
+\r
+bool hasParent(xmlNodePtr theNode, const char* theNodeName, ...)\r
+{\r
+ if (!hasParent(theNode)) {\r
+ return false; // have no parents at all\r
+ }\r
+ xmlNodePtr aNode = theNode->parent;\r
+ const xmlChar* aName = aNode->name;\r
+ if (!aName || !isElementNode(aNode)) {\r
+ return false;\r
+ }\r
+ if (!xmlStrcmp(aName, (const xmlChar *) theNodeName)) {\r
+ return true;\r
+ }\r
+ va_list args; // define argument list variable\r
+ va_start(args, theNodeName); // init list; point to last defined argument\r
+ while (true) {\r
+ char *anArg = va_arg (args, char*); // get next argument\r
+ if (anArg == NULL)\r
+ break;\r
+ if (!xmlStrcmp(aName, (const xmlChar *) anArg)) {\r
+ va_end(args); // cleanup the system stack\r
+ return true;\r
+ }\r
+ }\r
+ va_end(args); // cleanup the system stack\r
+ return false;\r
+}\r
+\r
+bool getParametersInfo(xmlNodePtr theNode, std::string& outPropertyId,\r
std::list<std::string>& outValidatorParameters)\r
{\r
- //Validator id:\r
+ //Property id:\r
char* anIdProp = (char*) xmlGetProp(theNode, BAD_CAST _ID);\r
if (!anIdProp || anIdProp[0] == 0) {\r
return false;\r
}\r
- outValidatorId = std::string(anIdProp);\r
+ outPropertyId = std::string(anIdProp);\r
\r
- //Validator parameters:\r
- char* aParamProp = (char*) xmlGetProp(theNode, BAD_CAST VALIDATOR_PARAMETERS);\r
+ //Property parameters:\r
+ char* aParamProp = (char*) xmlGetProp(theNode, BAD_CAST _PARAMETERS);\r
if (aParamProp && aParamProp[0] != 0) {\r
std::string aPropString = std::string(aParamProp);\r
std::stringstream aPropStringStream(aPropString);\r
char COMMA_DELIM = ',';\r
- std::string aValidatorParameter;\r
- while (std::getline(aPropStringStream, aValidatorParameter, ',')) {\r
- outValidatorParameters.push_back(aValidatorParameter);\r
+ std::string aParameter;\r
+ while (std::getline(aPropStringStream, aParameter, ',')) {\r
+ outValidatorParameters.push_back(aParameter);\r
}\r
}\r
return true;\r
\r
std::string library(const std::string& theLibName)\r
{\r
+ if(theLibName.empty())\r
+ return std::string();\r
std::string aLibName = theLibName;\r
#ifndef WIN32\r
static std::string aLibExt( ".so" );\r
return result;\r
}\r
\r
+std::string getNormalizedProperty(xmlNodePtr theNode, const char* thePropName)\r
+{\r
+ return normalize(getProperty(theNode, thePropName));\r
+}\r
+\r
bool getBooleanAttribute(xmlNodePtr theNode, const char* theAttributeName, bool theDefault)\r
{\r
- std::string prop = getProperty(theNode, theAttributeName);\r
- std::transform(prop.begin(), prop.end(), prop.begin(), ::tolower);\r
+ std::string prop = normalize(getProperty(theNode, theAttributeName));\r
bool result = theDefault;\r
if (prop == "true" || prop == "1") {\r
result = true;\r
}\r
return result;\r
}\r
+\r
+CONFIG_EXPORT std::string normalize(const char* theString)\r
+{\r
+ if (!theString)\r
+ return std::string();\r
+ return normalize(std::string(theString));\r
+}\r
+\r
+CONFIG_EXPORT std::string normalize(const std::string& theString)\r
+{\r
+ std::string result = theString;\r
+ std::transform(result.begin(), result.end(), result.begin(), ::tolower);\r
+ return result;\r
+}\r