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