Salome HOME
Make the correct order in the searching of shape by name algorithm
[modules/shaper.git] / src / Config / Config_XMLReader.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 /*
4  * Config_XMLReader.h
5  *
6  *  Created on: Mar 14, 2014
7  *      Author: sbh
8  */
9
10 #ifndef CONFIG_XMLREADER_H_
11 #define CONFIG_XMLREADER_H_
12
13 #include <Config_def.h>
14
15 #include <cstdarg>
16 #include <string>
17 #include <map>
18
19 //>> Forward declaration of xmlNodePtr.
20 typedef struct _xmlNode xmlNode;
21 typedef xmlNode *xmlNodePtr;
22 struct _xmlNode;
23 //<<
24
25 //>> Forward declaration of xmlDocPtr.
26 typedef struct _xmlDoc xmlDoc;
27 typedef xmlDoc *xmlDocPtr;
28 struct _xmlDoc;
29 //<<
30
31 /*!
32  * \class Config_XMLReader
33  * \ingroup Config
34  * \brief Base class for all libxml readers. Provides high-level API
35  * for all xml operations.
36 */
37 class Config_XMLReader
38 {
39  public:
40   /*!
41    * Constructor
42    * \param theXmlFile - full path to the xml file which will be processed by the reader
43    */
44   CONFIG_EXPORT Config_XMLReader(const std::string& theXmlFile);
45   CONFIG_EXPORT virtual ~Config_XMLReader();
46   /*!
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.
50    */
51   CONFIG_EXPORT void readAll();
52   /*!
53    * Returns xmlNodePtr to the root of reader's document
54    * or NULL if not found
55    */
56   CONFIG_EXPORT xmlNodePtr findRoot();
57
58  protected:
59   /*!
60    * \brief Allows to customize reader's behavior for a node. Virtual.
61    * The default implementation process "source", "validator" and
62    * "selection_filter" nodes.
63    */
64   virtual void processNode(xmlNodePtr aNode);
65   /*!
66    * \brief Defines which nodes should be processed recursively. Virtual.
67    * The default impl is to read all nodes.
68    */
69   virtual bool processChildren(xmlNodePtr aNode);
70   /*!
71    * Calls processNode() for each child (for some - recursively)
72    * of the given node.
73    * \sa ReadAll()
74    */
75   void readRecursively(xmlNodePtr theParent);
76   /*!
77    * \brief void* -> xmlNodePtr
78    */
79   xmlNodePtr node(void* theNode);
80   /// Gets xml node name
81   std::string getNodeName(xmlNodePtr theNode);
82   /// Stores an attribute in internal map for later use.
83   /// Key is "Node_Name:Node_Attribute" and value is getProperty(theNodeAttribute)
84   void storeAttribute(xmlNodePtr theNode, const char* theNodeAttribute);
85   /// Restores an attribute from internal map.
86   std::string restoreAttribute(xmlNodePtr theNode, const char* theNodeAttribute);
87   /// Restores an attribute from internal map.
88   std::string restoreAttribute(const char* theNodeName, const char* theNodeAttribute);
89
90  protected:
91   std::string myDocumentPath; ///< Path to the xml document
92   xmlDocPtr myXmlDoc; ///< Root of the xml document
93   /// A map to store all parent's attributes.
94   /// The key has from "Node_Name:Node_Attribute"
95   std::map<std::string, std::string> myCachedAttributes;
96 };
97
98 #endif /* CONFIG_XMLREADER_H_ */