1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
6 * Created on: Apr 17, 2014
10 #ifndef CONFIG_COMMON_H_
11 #define CONFIG_COMMON_H_
13 #include "Config_def.h"
19 //>> Forward declaration of xmlNodePtr.
20 typedef struct _xmlNode xmlNode;
21 typedef xmlNode *xmlNodePtr;
25 //>> Forward declaration of xmlDocPtr.
26 typedef struct _xmlDoc xmlDoc;
27 typedef xmlDoc *xmlDocPtr;
32 * Returns true if theNode is XML ELEMENT node (not a "text" node ie).
34 CONFIG_EXPORT bool isElementNode(xmlNodePtr theNode);
37 * Returns true if theNode is XML node with a given name.
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.
44 CONFIG_EXPORT bool isNode(xmlNodePtr theNode, const char* theNodeName, ...);
47 * Checks if the given node is attribute node.
48 * Attribute node represents a widget, that is able to store/restore
49 * values from the model. Actually it's every widget, displayed
50 * in the XGUI_PropertyPanel, except paged containers (toolbox, switch/case).
52 CONFIG_EXPORT bool isAttributeNode(xmlNodePtr theNode);
55 * Checks if the given node is widget node.
56 * Widget nodes are attribute node + paged containers nodes.
58 CONFIG_EXPORT bool isWidgetNode(xmlNodePtr theNode);
60 CONFIG_EXPORT bool isCaseNode(xmlNodePtr theNode);
63 * Every xml node has child. Even if there is no explicit
64 * child nodes libxml gives the "Text node" as child.
66 * This method checks if real child nodes exist in the
69 CONFIG_EXPORT bool hasChild(xmlNodePtr theNode);
73 * Checks if the given node has a valid parent.
75 CONFIG_EXPORT bool hasParent(xmlNodePtr theNode);
78 * Checks if the given node has a valid parent with any of the given node names.
80 CONFIG_EXPORT bool hasParent(xmlNodePtr theNode, const char* theNodeName, ...);
83 * Returns named property for an id node as std::string and the parameters of the node.
85 CONFIG_EXPORT bool getParametersInfo(xmlNodePtr theNode, std::string& outPropertyId,
86 std::list<std::string>& outValidatorParameters);
89 \brief Convert the given parameter to the platform-specific library name.
91 The function appends platform-specific prefix (lib) and suffix (.dll/.so)
92 to the library file name.
93 For example, if \a str = "mylib", "libmylib.so" is returned for Linux and
94 mylib.dll for Windows.
96 \param str short library name
97 \return full library name
99 CONFIG_EXPORT std::string library(const std::string& theLibName);
102 * Returns named property for a given node as std::string.
104 CONFIG_EXPORT std::string getProperty(xmlNodePtr theNode, const char* thePropName);
107 * Returns normalized (lower case) named property for a given node as std::string.
109 std::string getNormalizedProperty(xmlNodePtr theNode, const char* thePropName);
112 * Checks if the given XML node has the given attribute,
113 * if yes - returns it's bool value, if no, or if the value can not
114 * be converted to bool - returns theDefault value.
115 * \param theAttributeName attribute to check
116 * \param theDefault default value on bad data
117 * \return the boolean result
119 CONFIG_EXPORT bool getBooleanAttribute(xmlNodePtr theNode,
120 const char* theAttributeName,
124 * Returns normalized (lower case) version of string.
125 * Should be used for case insensitive string matching.
127 CONFIG_EXPORT std::string normalize(const char* theString);
129 * Returns normalized (lower case) version of string.
130 * Should be used for case insensitive string matching.
132 CONFIG_EXPORT std::string normalize(const std::string& theString);