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