SuperTuxKart
xml_node.hpp
1 //
2 // SuperTuxKart - a fun racing game with go-kart
3 // Copyright (C) 2009-2015 Joerg Henrichs
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 3
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 
19 #ifndef HEADER_XML_NODE_HPP
20 #define HEADER_XML_NODE_HPP
21 
22 #include <string>
23 #include <map>
24 #include <vector>
25 
26 #include <irrString.h>
27 #include <IXMLReader.h>
28 #include <SColor.h>
29 #include <vector2d.h>
30 #include <vector3d.h>
31 #include <path.h>
32 using namespace irr;
33 
34 #include "utils/leak_check.hpp"
35 #include "utils/no_copy.hpp"
36 #include "utils/time.hpp"
37 #include "utils/types.hpp"
38 
39 
40 class InterpolationArray;
41 class Vec3;
42 
47 class XMLNode : public NoCopy
48 {
49 private:
51  std::string m_name;
53  std::map<std::string, core::stringw> m_attributes;
55  std::vector<XMLNode *> m_nodes;
56 
57  void readXML(io::IXMLReader *xml);
58 
59  std::string m_file_name;
60 
61 public:
62  LEAK_CHECK();
63  XMLNode(io::IXMLReader *xml);
64 
66  XMLNode(const std::string &filename);
67 
68  ~XMLNode();
69 
70  const std::string &getName() const {return m_name; }
71  const XMLNode *getNode(const std::string &name) const;
72  const void getNodes(const std::string &s, std::vector<XMLNode*>& out) const;
73  const XMLNode *getNode(unsigned int i) const;
74  unsigned int getNumNodes() const {return (unsigned int) m_nodes.size(); }
75  int get(const std::string &attribute, std::string *value) const;
76  int get(const std::string &attribute, core::stringw *value) const;
77  int getAndDecode(const std::string &attribute, core::stringw *value) const;
78  int get(const std::string &attribute, int32_t *value) const;
79  int get(const std::string &attribute, uint16_t *value) const;
80  int get(const std::string &attribute, uint32_t *value) const;
81  int get(const std::string &attribute, int64_t *value) const;
82  int get(const std::string &attribute, uint64_t *value) const;
83  int get(const std::string &attribute, float *value) const;
84  int get(const std::string &attribute, double *value) const;
85  int get(const std::string &attribute, bool *value) const;
86  int get(const std::string &attribute, Vec3 *value) const;
87  int get(const std::string &attribute, core::vector2df *value) const;
88  int get(const std::string &attribute, core::vector3df *value) const;
89  int get(const std::string &attribute, video::SColorf *value) const;
90  int get(const std::string &attribute, video::SColor *value) const;
91  int get(const std::string &attribute, std::vector<std::string> *value) const;
92  int get(const std::string &attribute, std::vector<float> *value) const;
93  int get(const std::string &attribute, std::vector<int> *value) const;
94  int get(const std::string &attribute, InterpolationArray *value) const;
95  int get(core::vector3df *value) const;
96  int getXYZ(core::vector3df *value) const;
97  int getXYZ(Vec3 *vaslue) const;
98  int getHPR(core::vector3df *value) const;
99  int getHPR(Vec3 *value) const;
100 
101  bool hasChildNamed(const char* name) const;
102  const std::string& getFilename() const { return m_file_name; }
103 
105  static bool hasX(int b) { return (b&1)==1; }
106  static bool hasY(int b) { return (b&2)==2; }
107  static bool hasZ(int b) { return (b&4)==4; }
108  static bool hasH(int b) { return (b&1)==1; }
109  static bool hasP(int b) { return (b&2)==2; }
110  static bool hasR(int b) { return (b&4)==4; }
111 }; // XMLNode
112 
113 #endif
This class manages a set of (x_i,y_i) points, x_i must be sorted.
Definition: interpolation_array.hpp:32
Utility class, you can inherit from this class to disallow the assignment operator and copy construct...
Definition: no_copy.hpp:26
A wrapper around bullets btVector3 to include conventient conversion functions (e....
Definition: vec3.hpp:35
utility class used to parse XML files
Definition: xml_node.hpp:48
std::map< std::string, core::stringw > m_attributes
List of all attributes.
Definition: xml_node.hpp:53
std::vector< XMLNode * > m_nodes
List of all sub nodes.
Definition: xml_node.hpp:55
std::string m_name
Name of this element.
Definition: xml_node.hpp:51
static bool hasX(int b)
Handy functions to test the bit pattern returned by get(vector3df*).
Definition: xml_node.hpp:105
Declares the general types that are used by the network.