X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FConfig%2FConfig_Common.cpp;h=9c4df7f57c539174f1496979685e7d8b48c113e9;hb=d77e6639d89abdcbf327cc73d13bf955064b8524;hp=a6a9ee512e055782f0b7ff46968d63088633ab44;hpb=cd9217d7e87997ec8bc150a6d8c389e742ca0f84;p=modules%2Fshaper.git diff --git a/src/Config/Config_Common.cpp b/src/Config/Config_Common.cpp index a6a9ee512..9c4df7f57 100644 --- a/src/Config/Config_Common.cpp +++ b/src/Config/Config_Common.cpp @@ -1,3 +1,5 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + /* * Config_Common.cpp * @@ -11,9 +13,15 @@ #include #include -#include //for stringstream +#include // for stringstream + +#include +#include // for std::transform + bool isElementNode(xmlNodePtr theNode) { + if (!theNode) + return false; return theNode->type == XML_ELEMENT_NODE; } @@ -42,6 +50,19 @@ bool isNode(xmlNodePtr theNode, const char* theNodeName, ...) return false; } +bool isWidgetNode(xmlNodePtr theNode) +{ + if(!isElementNode(theNode)) + return false; + // it's parent is "feature" or "source" + xmlNodePtr aParentNode = theNode->parent; + if(!isNode(aParentNode, NODE_FEATURE, NODE_SOURCE, NULL)) + return false; + + //it should not be a "source" or a "validator" node + return !isNode(theNode, NODE_SOURCE, NODE_VALIDATOR, NODE_SELFILTER, NULL); +} + bool hasChild(xmlNodePtr theNode) { xmlNodePtr aNode = theNode->children; @@ -53,25 +74,25 @@ bool hasChild(xmlNodePtr theNode) return false; } -bool getValidatorInfo(xmlNodePtr theNode, std::string& outValidatorId, +bool getParametersInfo(xmlNodePtr theNode, std::string& outPropertyId, std::list& outValidatorParameters) { - //Validator id: + //Property id: char* anIdProp = (char*) xmlGetProp(theNode, BAD_CAST _ID); if (!anIdProp || anIdProp[0] == 0) { return false; } - outValidatorId = std::string(anIdProp); + outPropertyId = std::string(anIdProp); - //Validator parameters: - char* aParamProp = (char*) xmlGetProp(theNode, BAD_CAST VALIDATOR_PARAMETERS); + //Property parameters: + char* aParamProp = (char*) xmlGetProp(theNode, BAD_CAST _PARAMETERS); if (aParamProp && aParamProp[0] != 0) { std::string aPropString = std::string(aParamProp); std::stringstream aPropStringStream(aPropString); char COMMA_DELIM = ','; - std::string aValidatorParameter; - while (std::getline(aPropStringStream, aValidatorParameter, ',')) { - outValidatorParameters.push_back(aValidatorParameter); + std::string aParameter; + while (std::getline(aPropStringStream, aParameter, ',')) { + outValidatorParameters.push_back(aParameter); } } return true; @@ -79,6 +100,8 @@ bool getValidatorInfo(xmlNodePtr theNode, std::string& outValidatorId, std::string library(const std::string& theLibName) { + if(theLibName.empty()) + return std::string(); std::string aLibName = theLibName; #ifndef WIN32 static std::string aLibExt( ".so" ); @@ -94,3 +117,44 @@ std::string library(const std::string& theLibName) return aLibName; } + +std::string getProperty(xmlNodePtr theNode, const char* thePropName) +{ + std::string result = ""; + char* aPropChars = (char*) xmlGetProp(theNode, BAD_CAST thePropName); + if (!aPropChars || aPropChars[0] == 0) + return result; + result = std::string(aPropChars); + return result; +} + +std::string getNormalizedProperty(xmlNodePtr theNode, const char* thePropName) +{ + return normalize(getProperty(theNode, thePropName)); +} + +bool getBooleanAttribute(xmlNodePtr theNode, const char* theAttributeName, bool theDefault) +{ + std::string prop = normalize(getProperty(theNode, theAttributeName)); + bool result = theDefault; + if (prop == "true" || prop == "1") { + result = true; + } else if (prop == "false" || prop == "0") { + result = false; + } + return result; +} + +CONFIG_EXPORT std::string normalize(const char* theString) +{ + if (!theString) + return std::string(); + return normalize(std::string(theString)); +} + +CONFIG_EXPORT std::string normalize(const std::string& theString) +{ + std::string result = theString; + std::transform(result.begin(), result.end(), result.begin(), ::tolower); + return result; +}