zenilib  0.5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
XML.h
Go to the documentation of this file.
1 /* This file is part of the Zenipex Library (zenilib).
2  * Copyright (C) 2011 Mitchell Keith Bloch (bazald).
3  *
4  * zenilib is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * zenilib is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with zenilib. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
44 #ifndef ZENI_XML_H
45 #define ZENI_XML_H
46 
47 #include <Zeni/Error.h>
48 
49 #include <tinyxml.h>
50 
51 namespace Zeni {
52 
53  class ZENI_DLL XML_Element_c {
54  public:
56 
59  XML_Element_c operator[](const String &field) const;
60 
61  XML_Element_c first() const;
62  XML_Element_c next() const;
63 
66  bool good() const;
67  String value() const;
68 
71  bool to_bool() const;
72  int to_int() const;
73  float to_float() const;
74  double to_double() const;
75  String to_string() const;
76 
77  protected:
78  TiXmlNode * child(const String &field) const;
79  TiXmlNode * first_child() const;
80  TiXmlNode * child_element(const String &field) const;
81  TiXmlNode * first_child_element() const;
82 
84  };
85 
86  class ZENI_DLL XML_Element : public XML_Element_c {
87  public:
89 
92  XML_Element operator[](const String &field);
93 
94  XML_Element first();
95  XML_Element next();
96 
99  void create_child(const String &field);
100  void remove_child(const XML_Element &child);
101 
104  void set_bool(const bool &b);
105  void set_int(const int &i);
106  void set_float(const float &f);
107  void set_double(const double &d);
108  void set_string(const String &s);
109  };
110 
111  class ZENI_DLL XML_Document {
112  XML_Document(const XML_Document &);
113  XML_Document & operator=(const XML_Document &);
114 
115  public:
116  XML_Document();
117  XML_Document(const String &filename);
118  XML_Document(const String &filename, const String &backup);
119  ~XML_Document();
120 
123  bool good() const;
124  void load_mem(const String &data);
125  void load(const String &filename);
126  void save();
127  void save(const String &filename);
128 
129  bool try_load_mem(const String &data);
130  bool try_load(const String &filename);
131  bool try_save();
132  bool try_save(const String &filename);
133 
136  XML_Element_c operator[](const String &field) const;
137  XML_Element operator[](const String &field);
138 
139  XML_Element_c first() const;
140  XML_Element first();
141 
144  void create_root(const String &field);
145 
146  private:
147  TiXmlDocument m_xml_file;
148  XML_Element * m_root;
149  };
150 
151  struct ZENI_DLL XML_Load_Failure : public Error {
152  XML_Load_Failure() : Error("XML_Document could not be loaded.") {}
153  };
154 
155  struct ZENI_DLL XML_Save_Failure : public Error {
156  XML_Save_Failure() : Error("XML_Document could not be saved.") {}
157  };
158 
159  struct ZENI_DLL XML_Document_Ungood : public Error {
160  XML_Document_Ungood() : Error("XML_Document not good!") {}
161  };
162 
163  struct ZENI_DLL XML_Element_Ungood : public Error {
164  XML_Element_Ungood() : Error("XML_Element not good!") {}
165  };
166 
167  struct ZENI_DLL XML_Element_Nonleaf : public Error {
168  XML_Element_Nonleaf() : Error("XML_Element attempted leaf-node operation on non-leaf node!") {}
169  };
170 
171  struct ZENI_DLL XML_Create_Child_Failure : public Error {
172  XML_Create_Child_Failure() : Error("XML_Element failed to create a child node!") {}
173  };
174 
175  struct ZENI_DLL XML_Remove_Child_Failure : public Error {
176  XML_Remove_Child_Failure() : Error("XML_Element failed to remove a child node!") {}
177  };
178 
179 }
180 
181 #endif
GLdouble s
Definition: glew.h:1376
TiXmlHandle m_handle
Definition: XML.h:83
GLclampf f
Definition: glew.h:3390
return Display return Display Bool Bool int d
Definition: SDL_x11sym.h:30
GLint first
Definition: gl2ext.h:1011
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl2ext.h:848
A class to open an XML file and manage the root node.
Definition: XML.h:111
A node in an XML tree, possibly containing useful data.
Definition: XML.h:86
EGLSurface EGLint void ** value
Definition: eglext.h:301
GLdouble GLdouble GLdouble b
Definition: glew.h:8383
EGLImageKHR EGLint EGLint * handle
Definition: eglext.h:284
The Error Class.
Definition: Error.h:52
int i
Definition: pngrutil.c:1377