Salome HOME
Union of validator and filter functionalities.
[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
18 //>> Forward declaration of xmlNodePtr.
19 typedef struct _xmlNode xmlNode;
20 typedef xmlNode *xmlNodePtr;
21 struct _xmlNode;
22 //<<
23
24 //>> Forward declaration of xmlDocPtr.
25 typedef struct _xmlDoc xmlDoc;
26 typedef xmlDoc *xmlDocPtr;
27 struct _xmlDoc;
28 //<<
29
30 /*!
31  * \class Config_XMLReader
32  * \ingroup Config
33  * \brief Base class for all libxml readers. Provides high-level API
34  * for all xml operations.
35 */
36 class Config_XMLReader
37 {
38  public:
39   /*!
40    * Constructor
41    * \param theXmlFile - full path to the xml file which will be processed by the reader
42    */
43   CONFIG_EXPORT Config_XMLReader(const std::string& theXmlFile);
44   CONFIG_EXPORT virtual ~Config_XMLReader();
45   /*!
46    * Read all nodes in associated xml file,
47    * recursively if processChildren(xmlNode) is true for the xmlNode.
48    * For each read node the processNode will be called.
49    */
50   CONFIG_EXPORT void readAll();
51   /*!
52    * Returns xmlNodePtr to the root of reader's document
53    * or NULL if not found
54    */
55   CONFIG_EXPORT xmlNodePtr findRoot();
56
57  protected:
58   /*!
59    * \brief Allows to customize reader's behavior for a node. Virtual.
60    * The default implementation process "source", "validator" and
61    * "selection_filter" nodes.
62    */
63   virtual void processNode(xmlNodePtr aNode);
64
65   /*!
66    * This method gives an ability to finalize processing of a node,
67    * when reader is about to leave the node (node and all it's children are processed)
68    */
69   virtual void cleanup(xmlNodePtr aNode);
70   /*!
71    * \brief Defines which nodes should be processed recursively. Virtual.
72    * The default impl is to read all nodes.
73    */
74   virtual bool processChildren(xmlNodePtr aNode);
75   /*!
76    * Calls processNode() for each child (for some - recursively)
77    * of the given node.
78    * \sa ReadAll()
79    */
80   void readRecursively(xmlNodePtr theParent);
81   /*!
82    * \brief void* -> xmlNodePtr
83    */
84   xmlNodePtr node(void* theNode);
85   /// Gets xml node name
86   std::string getNodeName(xmlNodePtr theNode);
87   /*!
88    * \brief Retrieves all the necessary info from the validator node.
89    * Sends ValidatorLoaded event
90    */
91   void processValidator(xmlNodePtr theNode);
92   /*!
93    * \brief Retrieves all the necessary info from the SelectionFilter node.
94    * Sends SelectionFilterLoaded event
95    */
96   void processSelectionFilter(xmlNodePtr theNode);
97
98  protected:
99   std::string myCurrentFeature; ///< Name of currently processed feature
100   std::string myDocumentPath; ///< Path to the xml document
101   xmlDocPtr myXmlDoc; ///< Root of the xml document
102 };
103
104 #endif /* CONFIG_XMLREADER_H_ */