ManaPlus
libxml.h
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2004-2009 The Mana World Development Team
4  * Copyright (C) 2009-2010 The Mana Developers
5  * Copyright (C) 2011-2019 The ManaPlus Developers
6  *
7  * This file is part of The ManaPlus Client.
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 #ifndef UTILS_XML_LIBXML_H
24 #define UTILS_XML_LIBXML_H
25 
26 #ifdef ENABLE_LIBXML
27 
28 #define XML_INCLUDE_DEFINE
29 
32 
33 #include "utils/xml/libxml.inc"
34 
35 #include "resources/resource.h"
36 
37 #ifndef _GLIBCXX_STRING
38 #include <string>
39 #endif // _GLIBCXX_STRING
40 
41 #include "localconsts.h"
42 
46 namespace XML
47 {
52  class Document final : public Resource
53  {
54  public:
59  Document(const std::string &filename,
60  const UseVirtFs useResman,
61  const SkipError skipError);
62 
70  Document(const char *const data, const int size);
71 
73 
74 
77  ~Document() override final;
78 
83  XmlNodePtr rootNode() A_WARN_UNUSED;
84 
85  bool isLoaded() const
86  { return mDoc != nullptr; }
87 
88  bool isValid() const
89  { return mIsValid; }
90 
91  static bool validateXml(const std::string &fileName);
92 
93  private:
94  xmlDocPtr mDoc;
95  bool mIsValid;
96  };
97 
101  float getFloatProperty(XmlNodeConstPtr node,
102  const char *const name,
103  float def) A_WARN_UNUSED;
104 
108  double getDoubleProperty(XmlNodeConstPtr node,
109  const char *const name,
110  double def) A_WARN_UNUSED;
111 
115  int getProperty(XmlNodeConstPtr node,
116  const char *const name,
117  int def) A_WARN_UNUSED;
118 
122  int getIntProperty(XmlNodeConstPtr node,
123  const char *const name,
124  int def,
125  const int min,
126  const int max) A_WARN_UNUSED;
127 
131  std::string getProperty(XmlNodeConstPtr node,
132  const char *const name,
133  const std::string &def) A_WARN_UNUSED;
134 
138  std::string langProperty(XmlNodeConstPtr node,
139  const char *const name,
140  const std::string &def) A_WARN_UNUSED;
141 
145  bool getBoolProperty(XmlNodeConstPtr node,
146  const char *const name,
147  const bool def) A_WARN_UNUSED;
148 
152  XmlNodePtr findFirstChildByName(XmlNodeConstPtrConst parent,
153  const char *const name) A_WARN_UNUSED;
154 
155  void initXML();
156 
157  void cleanupXML();
158 } // namespace XML
159 
160 #define for_each_xml_child_node(var, parent) \
161  for (XmlNodePtr var = parent->xmlChildrenNode; var; var = var->next)
162 
163 #endif // ENABLE_LIBXML
164 #endif // UTILS_XML_LIBXML_H
XML::Document::~Document
~Document()
Definition: libxml.cpp:162
XML::getFloatProperty
float getFloatProperty(const xmlNodePtr node, const char *const name, float def)
Definition: libxml.cpp:210
XML::Document::isLoaded
bool isLoaded() const
Definition: libxml.h:85
usevirtfs.h
Resource
Definition: resource.h:33
XML::initXML
void initXML()
Definition: libxml.cpp:304
A_DELETE_COPY
#define A_DELETE_COPY(func)
Definition: localconsts.h:52
skiperror.h
XML::findFirstChildByName
xmlNodePtr findFirstChildByName(const xmlNode *const parent, const char *const name)
Definition: libxml.cpp:288
localconsts.h
XML::Document
Definition: libxml.h:52
XML
Definition: libxml.cpp:84
XML::getIntProperty
int getIntProperty(const xmlNodePtr node, const char *const name, int def, const int min, const int max)
Definition: libxml.cpp:189
XML::getProperty
int getProperty(const xmlNodePtr node, const char *const name, int def)
Definition: libxml.cpp:173
bool
XML::Document::mIsValid
bool mIsValid
Definition: libxml.h:95
fileName
std::string fileName
Definition: testmain.cpp:38
XML::getBoolProperty
bool getBoolProperty(const xmlNodePtr node, const char *const name, const bool def)
Definition: libxml.cpp:268
final
#define final
Definition: localconsts.h:45
resource.h
data
uint32_t data
Definition: maptypeproperty2.h:3
XML::Document::validateXml
static bool validateXml(const std::string &fileName)
Definition: libxml.cpp:319
XML::getDoubleProperty
double getDoubleProperty(const xmlNodePtr node, const char *const name, double def)
Definition: libxml.cpp:226
XML::langProperty
std::string langProperty(const xmlNodePtr node, const char *const name, const std::string &def)
Definition: libxml.cpp:257
XML::Document::mDoc
xmlDocPtr mDoc
Definition: libxml.h:94
EmoteDB::size
int size()
Definition: emotedb.cpp:305
XML::Document::Document
Document(const std::string &filename, const UseVirtFs useResman, const SkipError skipError)
Definition: libxml.cpp:86
XML::Document::rootNode
xmlNodePtr rootNode()
Definition: libxml.cpp:168
A_WARN_UNUSED
#define A_WARN_UNUSED
Definition: localconsts.h:160
XML::Document::isValid
bool isValid() const
Definition: libxml.h:88
XML::cleanupXML
void cleanupXML()
Definition: libxml.cpp:314