SHAPER 9.16.0
Config_XMLReader.h
1// Copyright (C) 2014-2026 CEA, EDF
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_XMLREADER_H_
21#define CONFIG_XMLREADER_H_
22
23#include <Config_def.h>
24
25#include <cstdarg>
26#include <string>
27#include <map>
28
29//>> Forward declaration of xmlNodePtr.
30typedef struct _xmlNode xmlNode;
31typedef xmlNode *xmlNodePtr;
32struct _xmlNode;
33//<<
34
35//>> Forward declaration of xmlDocPtr.
36typedef struct _xmlDoc xmlDoc;
37typedef xmlDoc *xmlDocPtr;
38struct _xmlDoc;
39//<<
40
48{
49 public:
54 CONFIG_EXPORT Config_XMLReader(const std::string& theXmlFile, bool isXMLContent = false);
55 CONFIG_EXPORT virtual ~Config_XMLReader();
60 CONFIG_EXPORT static std::string resourcesConfigFile();
65 CONFIG_EXPORT static std::string pluginConfigFile();
71 CONFIG_EXPORT void readAll();
76 CONFIG_EXPORT xmlNodePtr findRoot(const std::string theDocumentPath = "");
77
78 CONFIG_EXPORT const char* encoding() const;
79
82 CONFIG_EXPORT static std::string
83 findConfigFile(const std::string theFileName, const int theFindIndex = 0);
84
85 protected:
90 virtual void processNode(xmlNodePtr aNode);
91
96 virtual void cleanup(xmlNodePtr aNode);
101 virtual bool processChildren(xmlNodePtr aNode);
107 void readRecursively(xmlNodePtr theParent);
111 xmlNodePtr node(void* theNode);
113 std::string getNodeName(xmlNodePtr theNode);
116 void storeAttribute(xmlNodePtr theNode, const char* theNodeAttribute, bool doClean = false);
118 std::string restoreAttribute(xmlNodePtr theNode, const char* theNodeAttribute);
120 std::string restoreAttribute(const char* theNodeName, const char* theNodeAttribute);
122 bool cleanupAttribute(xmlNodePtr theNode, const char* theNodeAttribute);
124 bool cleanupAttribute(const char* theNodeName, const char* theNodeAttribute);
125
126 protected:
127 std::string myDocumentPath;
128 xmlDocPtr myXmlDoc;
129 std::string myRootFileName;
132 std::map<std::string, std::string> myCachedAttributes;
133
134 bool isFromMemory;
135};
136
137#endif /* CONFIG_XMLREADER_H_ */
Base class for all libxml readers. Provides high-level API for all xml operations.
Definition: Config_XMLReader.h:48
xmlNodePtr node(void *theNode)
void* -> xmlNodePtr
Definition: Config_XMLReader.cpp:253
static CONFIG_EXPORT std::string findConfigFile(const std::string theFileName, const int theFindIndex=0)
Checks all possible paths to configuration file given Uses theFindIndex if several solutions can be f...
Definition: Config_XMLReader.cpp:99
CONFIG_EXPORT Config_XMLReader(const std::string &theXmlFile, bool isXMLContent=false)
Definition: Config_XMLReader.cpp:48
std::string myRootFileName
name of the root file
Definition: Config_XMLReader.h:129
virtual void cleanup(xmlNodePtr aNode)
Definition: Config_XMLReader.cpp:200
CONFIG_EXPORT void readAll()
Definition: Config_XMLReader.cpp:161
virtual void processNode(xmlNodePtr aNode)
Allows to customize reader's behavior for a node. Virtual. The default implementation process "source...
Definition: Config_XMLReader.cpp:188
std::string myDocumentPath
Path to the xml document.
Definition: Config_XMLReader.h:127
static CONFIG_EXPORT std::string resourcesConfigFile()
Definition: Config_XMLReader.cpp:66
static CONFIG_EXPORT std::string pluginConfigFile()
Definition: Config_XMLReader.cpp:82
CONFIG_EXPORT xmlNodePtr findRoot(const std::string theDocumentPath="")
Definition: Config_XMLReader.cpp:212
bool cleanupAttribute(xmlNodePtr theNode, const char *theNodeAttribute)
Cleanups attribute from cache.
Definition: Config_XMLReader.cpp:295
std::string restoreAttribute(xmlNodePtr theNode, const char *theNodeAttribute)
Restores an attribute from internal map.
Definition: Config_XMLReader.cpp:279
void readRecursively(xmlNodePtr theParent)
Definition: Config_XMLReader.cpp:234
xmlDocPtr myXmlDoc
Root of the xml document.
Definition: Config_XMLReader.h:128
virtual bool processChildren(xmlNodePtr aNode)
Defines which nodes should be processed recursively. Virtual. The default impl is to read all nodes.
Definition: Config_XMLReader.cpp:206
std::map< std::string, std::string > myCachedAttributes
A map to store all parent's attributes.
Definition: Config_XMLReader.h:132
void storeAttribute(xmlNodePtr theNode, const char *theNodeAttribute, bool doClean=false)
Stores an attribute in internal map for later use.
Definition: Config_XMLReader.cpp:269
std::string getNodeName(xmlNodePtr theNode)
Gets xml node name.
Definition: Config_XMLReader.cpp:259