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