ManaPlus
tinyxml2.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  * Copyright (C) 2019-2021 Andrei Karas
7  *
8  * This file is part of The ManaPlus Client.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 #ifndef UTILS_XML_TINYXML2_H
25 #define UTILS_XML_TINYXML2_H
26 
27 #ifdef ENABLE_TINYXML2
28 
29 #define XML_INCLUDE_DEFINE
30 
33 
34 #include "utils/xml/tinyxml2.inc"
35 
36 #include "resources/resource.h"
37 
38 #ifndef _GLIBCXX_STRING
39 #include <string>
40 #endif // _GLIBCXX_STRING
41 
42 #include "localconsts.h"
43 
47 namespace XML
48 {
53  class Document final : public Resource
54  {
55  public:
60  Document(const std::string &filename,
61  const UseVirtFs useResman,
62  const SkipError skipError);
63 
71  Document(const char *const data, const int size);
72 
74 
75 
79 
84  XmlNodePtr rootNode() A_WARN_UNUSED;
85 
86  bool isLoaded() const
87  { return mDoc.Error() == false; }
88 
89  bool isValid() const
90  { return mIsValid; }
91 
92  static bool validateXml(const std::string &fileName);
93 
94  private:
95  tinyxml2::XMLDocument mDoc;
96  char *mData;
97  bool mIsValid;
98  };
99 
103  float getFloatProperty(XmlNodeConstPtr node,
104  const char *const name,
105  float def) A_WARN_UNUSED;
106 
110  double getDoubleProperty(XmlNodeConstPtr node,
111  const char *const name,
112  double def) A_WARN_UNUSED;
113 
117  int getProperty(XmlNodeConstPtr node,
118  const char *const name,
119  int def) A_WARN_UNUSED;
120 
124  int getIntProperty(XmlNodeConstPtr node,
125  const char *const name,
126  int def,
127  const int min,
128  const int max) A_WARN_UNUSED;
129 
133  std::string getProperty(XmlNodeConstPtr node,
134  const char *const name,
135  const std::string &def) A_WARN_UNUSED;
136 
140  std::string langProperty(XmlNodeConstPtr node,
141  const char *const name,
142  const std::string &def) A_WARN_UNUSED;
143 
147  bool getBoolProperty(XmlNodeConstPtr node,
148  const char *const name,
149  const bool def) A_WARN_UNUSED;
150 
154  XmlNodeConstPtr findFirstChildByName(XmlNodeConstPtrConst parent,
155  const char *const name)
157 
158  void initXML();
159 
160  void cleanupXML();
161 } // namespace XML
162 
163 #define for_each_xml_child_node(var, parent) \
164  for (const tinyxml2::XMLElement *var = parent->FirstChildElement(); \
165  var != nullptr; \
166  var = var->NextSiblingElement())
167 
168 #endif // ENABLE_TINYXML2
169 #endif // UTILS_XML_TINYXML2_H
bool isLoaded() const
Definition: libxml.h:86
xmlNodePtr rootNode()
Definition: libxml.cpp:169
bool mIsValid
Definition: libxml.h:96
static bool validateXml(const std::string &fileName)
Definition: libxml.cpp:320
bool isValid() const
Definition: libxml.h:89
Document(const std::string &filename, const UseVirtFs useResman, const SkipError skipError)
Definition: libxml.cpp:87
xmlDocPtr mDoc
Definition: libxml.h:95
#define override
Definition: localconsts.h:47
#define A_WARN_UNUSED
Definition: localconsts.h:161
#define final
Definition: localconsts.h:46
#define A_DELETE_COPY(func)
Definition: localconsts.h:53
uint32_t data
int size()
Definition: emotedb.cpp:306
PlayerInfoBackend mData
Definition: playerinfo.cpp:56
Definition: libxml.cpp:86
void initXML()
Definition: libxml.cpp:305
std::string langProperty(const xmlNodePtr node, const char *const name, const std::string &def)
Definition: libxml.cpp:258
float getFloatProperty(const xmlNodePtr node, const char *const name, float def)
Definition: libxml.cpp:211
bool getBoolProperty(const xmlNodePtr node, const char *const name, const bool def)
Definition: libxml.cpp:269
int getProperty(const xmlNodePtr node, const char *const name, int def)
Definition: libxml.cpp:174
int getIntProperty(const xmlNodePtr node, const char *const name, int def, const int min, const int max)
Definition: libxml.cpp:190
void cleanupXML()
Definition: libxml.cpp:315
xmlNodePtr findFirstChildByName(const xmlNode *const parent, const char *const name)
Definition: libxml.cpp:289
double getDoubleProperty(const xmlNodePtr node, const char *const name, double def)
Definition: libxml.cpp:227
bool SkipError
Definition: skiperror.h:30
std::string fileName
Definition: testmain.cpp:39
bool UseVirtFs
Definition: usevirtfs.h:30