xoreos  0.0.5
xml.h
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 #ifndef COMMON_XML_H
26 #define COMMON_XML_H
27 
28 #include <list>
29 #include <map>
30 
31 #include <boost/noncopyable.hpp>
32 
33 #include "src/common/scopedptr.h"
34 #include "src/common/ptrlist.h"
35 #include "src/common/ustring.h"
36 
37 struct _xmlNode;
38 
39 namespace Common {
40 
41 class ReadStream;
42 
44 void initXML();
46 void deinitXML();
47 
48 class XMLNode;
49 
51 class XMLParser : boost::noncopyable {
52 public:
59  XMLParser(ReadStream &stream, bool makeLower = false, const UString &fileName = "stream.xml");
60  ~XMLParser();
61 
63  const XMLNode &getRoot() const;
64 
65 private:
67 };
68 
69 class XMLNode : boost::noncopyable {
70 public:
71  typedef std::map<UString, UString> Properties;
73 
74  const UString &getName() const;
75  const UString &getContent() const;
76 
78  const XMLNode *getParent() const;
79 
81  const Children &getChildren() const;
82 
84  const XMLNode *findChild(const UString &name) const;
85 
87  const Properties &getProperties() const;
89  UString getProperty(const UString &name, const UString &def = "") const;
90 
91 
92 private:
93  typedef std::map<UString, const XMLNode *, UString::iless> ChildMap;
94 
97 
99 
102 
104 
105 
106  XMLNode(_xmlNode &node, bool makeLower = false, XMLNode *parent = 0);
107  ~XMLNode();
108 
109  void load(_xmlNode &node, bool makeLower);
110 
111 
112  friend class XMLParser;
113 
114  template<typename T>
115  friend void DeallocatorDefault::destroy(T *);
116 };
117 
118 } // End of namespace Common
119 
120 #endif // COMMON_XML_H
UString _content
Definition: xml.h:96
Generic interface for a readable data stream.
Definition: readstream.h:64
Definition: 2dafile.h:39
A class holding an UTF-8 string.
Definition: ustring.h:48
Class to parse a ReadStream into a simple XML tree.
Definition: xml.h:51
const UString & getName() const
Definition: xml.cpp:120
const XMLNode * getParent() const
Return the parent node, or 0 if this is the root node.
Definition: xml.cpp:128
const Children & getChildren() const
Return a list of children.
Definition: xml.cpp:132
std::map< UString, UString > Properties
Definition: xml.h:71
XMLNode * _parent
Definition: xml.h:98
A simple scoped smart pointer template.
A list storing pointer to objects, with automatic deletion.
Properties _properties
Definition: xml.h:103
std::map< UString, const XMLNode *, UString::iless > ChildMap
Definition: xml.h:93
static void destroy(T *x)
Definition: deallocator.h:40
const Properties & getProperties() const
Return all the properties on this node.
Definition: xml.cpp:144
Children _children
Definition: xml.h:100
ChildMap _childMap
Definition: xml.h:101
A scoped plain pointer, allowing pointer-y access and normal deletion.
Definition: scopedptr.h:120
UString getProperty(const UString &name, const UString &def="") const
Return a certain property on this node.
Definition: xml.cpp:148
UString _name
Definition: xml.h:95
Unicode string handling.
const XMLNode * findChild(const UString &name) const
Find a child node by name.
Definition: xml.cpp:136
void deinitXML()
Deinitialize the XML subsystem.
Definition: xml.cpp:71
XMLParser(ReadStream &stream, bool makeLower=false, const UString &fileName="stream.xml")
Parse an XML file out of a stream.
Definition: xml.cpp:75
const UString & getContent() const
Definition: xml.cpp:124
const XMLNode & getRoot() const
Return the XML root node.
Definition: xml.cpp:108
void initXML()
Initialize the XML subsystem.
Definition: xml.cpp:66
XMLNode(_xmlNode &node, bool makeLower=false, XMLNode *parent=0)
Definition: xml.cpp:113
void load(_xmlNode &node, bool makeLower)
Definition: xml.cpp:156
ScopedPtr< XMLNode > _rootNode
Definition: xml.h:66
PtrList< const XMLNode > Children
Definition: xml.h:72