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