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  * 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_LIBXML_H
25 #define UTILS_XML_LIBXML_H
26 
27 #ifdef ENABLE_LIBXML
28 
29 #define XML_INCLUDE_DEFINE
30 
33 
34 #include "utils/xml/libxml.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 
78  ~Document() override final;
79 
84  XmlNodePtr rootNode() A_WARN_UNUSED;
85 
86  bool isLoaded() const
87  { return mDoc != nullptr; }
88 
89  bool isValid() const
90  { return mIsValid; }
91 
92  static bool validateXml(const std::string &fileName);
93 
94  private:
95  xmlDocPtr mDoc;
96  bool mIsValid;
97  };
98 
102  float getFloatProperty(XmlNodeConstPtr node,
103  const char *const name,
104  float def) A_WARN_UNUSED;
105 
109  double getDoubleProperty(XmlNodeConstPtr node,
110  const char *const name,
111  double def) A_WARN_UNUSED;
112 
116  int getProperty(XmlNodeConstPtr node,
117  const char *const name,
118  int def) A_WARN_UNUSED;
119 
123  int getIntProperty(XmlNodeConstPtr node,
124  const char *const name,
125  int def,
126  const int min,
127  const int max) A_WARN_UNUSED;
128 
132  std::string getProperty(XmlNodeConstPtr node,
133  const char *const name,
134  const std::string &def) A_WARN_UNUSED;
135 
139  std::string langProperty(XmlNodeConstPtr node,
140  const char *const name,
141  const std::string &def) A_WARN_UNUSED;
142 
146  bool getBoolProperty(XmlNodeConstPtr node,
147  const char *const name,
148  const bool def) A_WARN_UNUSED;
149 
153  XmlNodePtr findFirstChildByName(XmlNodeConstPtrConst parent,
154  const char *const name) A_WARN_UNUSED;
155 
156  void initXML();
157 
158  void cleanupXML();
159 } // namespace XML
160 
161 #define for_each_xml_child_node(var, parent) \
162  for (XmlNodePtr var = parent->xmlChildrenNode; var; var = var->next)
163 
164 #endif // ENABLE_LIBXML
165 #endif // UTILS_XML_LIBXML_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 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
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