Salome HOME
Sources formated according to the codeing standards
[modules/shaper.git] / src / Config / Config_Common.cpp
1 /*\r
2  * Config_Common.cpp\r
3  *\r
4  *  Created on: Apr 17, 2014\r
5  *      Author: sbh\r
6  */\r
7 \r
8 #include "Config_Common.h"\r
9 #include <Config_Keywords.h>\r
10 \r
11 #include <libxml/parser.h>\r
12 #include <libxml/tree.h>\r
13 \r
14 #include <sstream> //for stringstream\r\r
15 bool isElementNode(xmlNodePtr theNode)\r
16 {\r
17   return theNode->type == XML_ELEMENT_NODE;\r
18 }\r
19 \r
20 bool isNode(xmlNodePtr theNode, const char* theNodeName, ...)\r
21 {\r
22   bool result = false;\r
23   const xmlChar* aName = theNode->name;\r
24   if (!aName || !isElementNode(theNode)) {\r
25     return false;\r
26   }\r
27   if (!xmlStrcmp(aName, (const xmlChar *) theNodeName)) {\r
28     return true;\r
29   }\r
30   va_list args;  // define argument list variable\r
31   va_start(args, theNodeName);  // init list; point to last defined argument\r
32   while (true) {\r
33     char *anArg = va_arg (args, char*);  // get next argument\r
34     if (anArg == NULL)\r
35       break;\r
36     if (!xmlStrcmp(aName, (const xmlChar *) anArg)) {\r
37       va_end(args);  // cleanup the system stack\r
38       return true;\r
39     }\r
40   }\r
41   va_end(args);  // cleanup the system stack\r
42   return false;\r
43 }\r
44 \r
45 bool hasChild(xmlNodePtr theNode)\r
46 {\r
47   xmlNodePtr aNode = theNode->children;\r
48   for (; aNode; aNode = aNode->next) {\r
49     if (isElementNode(theNode)) {\r
50       return true;\r
51     }\r
52   }\r
53   return false;\r
54 }\r
55 \r
56 bool getValidatorInfo(xmlNodePtr theNode, std::string& outValidatorId,\r
57                       std::list<std::string>& outValidatorParameters)\r
58 {\r
59   //Validator id:\r
60   char* anIdProp = (char*) xmlGetProp(theNode, BAD_CAST _ID);\r
61   if (!anIdProp || anIdProp[0] == 0) {\r
62     return false;\r
63   }\r
64   outValidatorId = std::string(anIdProp);\r
65 \r
66   //Validator parameters:\r
67   char* aParamProp = (char*) xmlGetProp(theNode, BAD_CAST VALIDATOR_PARAMETERS);\r
68   if (aParamProp && aParamProp[0] != 0) {\r
69     std::string aPropString = std::string(aParamProp);\r
70     std::stringstream aPropStringStream(aPropString);\r
71     char COMMA_DELIM = ',';\r
72     std::string aValidatorParameter;\r
73     while (std::getline(aPropStringStream, aValidatorParameter, ',')) {\r
74       outValidatorParameters.push_back(aValidatorParameter);\r
75     }\r
76   }\r
77   return true;\r
78 }\r
79 \r
80 std::string library(const std::string& theLibName)\r
81 {\r
82   std::string aLibName = theLibName;\r
83 #ifndef WIN32\r
84   static std::string aLibExt( ".so" );\r
85   if (aLibName.size() < 3 || aLibName.substr(0, 3) !="lib") {\r
86     aLibName = "lib" + aLibName;\r
87   }\r
88 #else\r
89   static std::string aLibExt(".dll");\r
90 #endif\r
91   std::string anExt = aLibName.substr(aLibName.size() - 4);\r
92   if (anExt != aLibExt)\r
93     aLibName += aLibExt;\r
94 \r
95   return aLibName;\r
96 }\r