Salome HOME
Merge branch 'master' of newgeom:newgeom
[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
10 #include <libxml/parser.h>
11 #include <libxml/tree.h>
12
13 bool isElementNode(xmlNodePtr theNode)
14 {
15   return theNode->type == XML_ELEMENT_NODE;
16 }
17
18 bool isNode(xmlNodePtr theNode, const char* theNodeName, ...)
19 {
20   bool result = false;
21   const xmlChar* aName = theNode->name;
22   if (!aName || !isElementNode(theNode)) {
23     return false;
24   }
25   if (!xmlStrcmp(aName, (const xmlChar *) theNodeName)) {
26     return true;
27   }
28   va_list args; // define argument list variable
29   va_start(args, theNodeName); // init list; point to last defined argument
30   while(true) {
31     char *anArg = va_arg (args, char*); // get next argument
32     if (anArg == NULL)
33       break;
34     if (!xmlStrcmp(aName, (const xmlChar *) anArg)) {
35       va_end(args); // cleanup the system stack
36       return true;
37     }
38   }
39   va_end(args); // cleanup the system stack
40   return false;
41 }
42
43 bool hasChild(xmlNodePtr theNode)
44 {
45   xmlNodePtr aNode = theNode->children;
46   for( ; aNode; aNode = aNode->next) {
47     if (isElementNode(theNode)) {
48       return true;
49     }
50   }
51   return false;
52 }
53
54 std::string library(const std::string& theLibName)
55 {
56   std::string aLibName = theLibName;
57 #ifndef WIN32
58   static std::string aLibExt( ".so" );
59   if (aLibName.size() < 3 || aLibName.substr(0, 3) !="lib") {
60     aLibName = "lib" + aLibName;
61   }
62 #else
63   static std::string aLibExt(".dll");
64 #endif
65   std::string anExt = aLibName.substr(aLibName.size() - 4);
66   if (anExt != aLibExt)
67     aLibName += aLibExt;
68
69   return aLibName;
70 }