1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
6 * Created on: Mar 14, 2014
10 #ifndef CONFIG_XMLREADER_H_
11 #define CONFIG_XMLREADER_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 * \class Config_XMLReader
34 * \brief Base class for all libxml readers. Provides high-level API
35 * for all xml operations.
37 class Config_XMLReader
42 * \param theXmlFile - full path to the xml file which will be processed by the reader
44 CONFIG_EXPORT Config_XMLReader(const std::string& theXmlFile);
45 CONFIG_EXPORT virtual ~Config_XMLReader();
47 * Read all nodes in associated xml file,
48 * recursively if processChildren(xmlNode) is true for the xmlNode.
49 * For each read node the processNode will be called.
51 CONFIG_EXPORT void readAll();
53 * Returns xmlNodePtr to the root of reader's document
54 * or NULL if not found
56 CONFIG_EXPORT xmlNodePtr findRoot();
60 * \brief Allows to customize reader's behavior for a node. Virtual.
61 * The default implementation process "source", "validator" and
62 * "selection_filter" nodes.
64 virtual void processNode(xmlNodePtr aNode);
67 * This method gives an ability to finalize processing of a node,
68 * when reader is about to leave the node (node and all it's children are processed)
70 virtual void cleanup(xmlNodePtr aNode);
72 * \brief Defines which nodes should be processed recursively. Virtual.
73 * The default impl is to read all nodes.
75 virtual bool processChildren(xmlNodePtr aNode);
77 * Calls processNode() for each child (for some - recursively)
81 void readRecursively(xmlNodePtr theParent);
83 * \brief void* -> xmlNodePtr
85 xmlNodePtr node(void* theNode);
86 /// Gets xml node name
87 std::string getNodeName(xmlNodePtr theNode);
88 /// Stores an attribute in internal map for later use.
89 /// Key is "Node_Name:Node_Attribute" and value is getProperty(theNodeAttribute)
90 void storeAttribute(xmlNodePtr theNode, const char* theNodeAttribute, bool doClean = false);
91 /// Restores an attribute from internal map.
92 std::string restoreAttribute(xmlNodePtr theNode, const char* theNodeAttribute);
93 /// Restores an attribute from internal map.
94 std::string restoreAttribute(const char* theNodeName, const char* theNodeAttribute);
95 /// Cleanups attribute from cache
96 bool cleanupAttribute(xmlNodePtr theNode, const char* theNodeAttribute);
97 /// Cleanups attribute from cache
98 bool cleanupAttribute(const char* theNodeName, const char* theNodeAttribute);
101 std::string myDocumentPath; ///< Path to the xml document
102 xmlDocPtr myXmlDoc; ///< Root of the xml document
103 /// A map to store all parent's attributes.
104 /// The key has from "Node_Name:Node_Attribute"
105 std::map<std::string, std::string> myCachedAttributes;
108 #endif /* CONFIG_XMLREADER_H_ */