Salome HOME
0998a6b73d6899c269951560757ee9fb559172c0
[modules/shaper.git] / src / Config / Config_Common.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 /*
4  * Config_Common.h
5  *
6  *  Created on: Apr 17, 2014
7  *      Author: sbh
8  */
9
10 #ifndef CONFIG_COMMON_H_
11 #define CONFIG_COMMON_H_
12
13 #include "Config_def.h"
14
15 #include <string>
16 #include <list>
17 #include <stdarg.h>
18
19 //>> Forward declaration of xmlNodePtr.
20 typedef struct _xmlNode xmlNode;
21 typedef xmlNode *xmlNodePtr;
22 struct _xmlNode;
23 //<<
24
25 //>> Forward declaration of xmlDocPtr.
26 typedef struct _xmlDoc xmlDoc;
27 typedef xmlDoc *xmlDocPtr;
28 struct _xmlDoc;
29 //<<
30
31 /*!
32  * Returns true if theNode is XML ELEMENT node (not a "text" node ie).
33  */
34 CONFIG_EXPORT bool isElementNode(xmlNodePtr theNode);
35
36 /*!
37  * Returns true if theNode is XML node with a given name.
38
39  * Please note that this function should be called with NULL last argument.
40  * In example: isNode(aNode, "type1", ["type2", ...], NULL);
41  * ", NULL" is required to use unlimited number of arguments.
42  * TODO(sbh): find a way to simplify calling this method.
43  */
44 CONFIG_EXPORT bool isNode(xmlNodePtr theNode, const char* theNodeName, ...);
45
46 //#define isNode(p) _isNode(p, NULL)
47
48 /*!
49  * Checks if the given node is attribute node.
50  * Attribute node represents a widget, that is able to store/restore
51  * values from the model. Actually it's every widget, displayed
52  * in the XGUI_PropertyPanel, except paged containers (toolbox, switch/case).
53  */
54 CONFIG_EXPORT bool isAttributeNode(xmlNodePtr theNode);
55
56 /*!
57  * Checks if the given node is widget node.
58  * Widget nodes are attribute node + paged containers nodes.
59  */
60 CONFIG_EXPORT bool isWidgetNode(xmlNodePtr theNode);
61
62 CONFIG_EXPORT bool isCaseNode(xmlNodePtr theNode);
63
64 /*!
65  * Every xml node has child. Even if there is no explicit
66  * child nodes libxml gives the "Text node" as child.
67  *
68  * This method checks if real child nodes exist in the
69  * given node.
70  */
71 CONFIG_EXPORT bool hasChild(xmlNodePtr theNode);
72
73
74 /*!
75  * Checks if the given node has a valid parent.
76  */
77 CONFIG_EXPORT bool hasParent(xmlNodePtr theNode);
78
79 /*!
80  * Checks if the given node has a valid parent with any of the given node names.
81  */
82 CONFIG_EXPORT bool hasParent(xmlNodePtr theNode, const char* theNodeName, ...);
83
84 /*!
85  * Checks if the given node has any valid parent in hierarchy with any of the given node names.
86  */
87 CONFIG_EXPORT bool hasParentRecursive(xmlNodePtr theNode, const char* theNodeName, ...);
88
89
90 /*!
91  * Returns named property for an id node as std::string and the parameters of the node.
92  */
93 CONFIG_EXPORT bool getParametersInfo(xmlNodePtr theNode, std::string& outPropertyId,
94                                      std::list<std::string>& outValidatorParameters);
95
96 /*!
97  \brief Convert the given parameter to the platform-specific library name.
98
99  The function appends platform-specific prefix (lib) and suffix (.dll/.so)
100  to the library file name.
101  For example, if \a str = "mylib", "libmylib.so" is returned for Linux and
102  mylib.dll for Windows.
103
104  \param str short library name
105  \return full library name
106  */
107 CONFIG_EXPORT std::string library(const std::string& theLibName);
108
109 /*!
110  * Returns named property for a given node as std::string.
111  */
112 CONFIG_EXPORT std::string getProperty(xmlNodePtr theNode, const char* thePropName);
113
114 /*!
115  * Returns content of the node as std::string if it is exists.
116  */
117 CONFIG_EXPORT std::string getContent(xmlNodePtr theNode);
118
119 /*!
120  * Returns normalized (lower case) named property for a given node as std::string.
121  */
122 std::string getNormalizedProperty(xmlNodePtr theNode, const char* thePropName);
123
124 /*!
125  * Checks if the given XML node has the given attribute,
126  * if yes - returns it's bool value, if no, or if the value can not
127  * be converted to bool - returns theDefault value.
128  * \param theAttributeName attribute to check
129  * \param theDefault default value on bad data
130  * \return the boolean result
131  */
132 CONFIG_EXPORT bool getBooleanAttribute(xmlNodePtr theNode,
133                                        const char* theAttributeName,
134                                        bool theDefault);
135
136 /*!
137  * Returns normalized (lower case) version of string.
138  * Should be used for case insensitive string matching.
139  */
140 CONFIG_EXPORT std::string normalize(const char* theString);
141 /*!
142  * Returns normalized (lower case) version of string.
143  * Should be used for case insensitive string matching.
144  */
145 CONFIG_EXPORT std::string normalize(const std::string& theString);
146
147 #endif