Minor cleanup.
[lsystem3d.git] / src / xmlstructure.h
CommitLineData
15c82487 1// Copyright (C) 2006 Erik Dahlberg
2//
1a372e99 3// This file is part of LSystem3D.
15c82487 4//
5// LSystem3D 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 2
8// of the License, or (at your option) any later version.
9//
10// LSystem3D 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 LSystem3D; if not, write to the Free Software
17// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19
20
21
22#ifndef XMLSTRUCTURE_H
23#define XMLSTRUCTURE_H
24
25#include <string>
26
27#include <libxml++/document.h>
28#include <libxml++/nodes/element.h>
29#include <libxml++/nodes/node.h>
30#include <libxml++/parsers/domparser.h>
31
32using namespace std;
33
34
35
36/**
37 * Basic logic for building and parsing xml-structures
38 */
39class XMLStructure
40{
41public:
68a7b857 42
15c82487 43 /**
44 * Constructor
45 */
46 XMLStructure();
47
48 /**
49 * Destructor
50 */
51 ~XMLStructure();
52
53protected:
54
55 // Saver
15c82487 56
57 /**
58 * Create new document with root node
59 * @param rootName name of root
60 */
61 void createDocumentWithRoot(string rootName);
62
63 /**
64 * Add new child to root
65 * @param name name of child
66 */
67 void addChildToRoot(string name);
68
69 /**
70 * Add a string as content of current child
71 * @param text the text
72 */
73 void addString(string text);
74
75 /**
76 * Add a number as content of current child
77 * @param value the number
78 */
79 void addNumber(double value);
80
81 /**
82 * Add attribute to current child
83 * @param name name of attribute
84 * @param value value of attribute
85 */
86 void addAttribute(string name, string value);
87
88 /**
89 * Save document to file
90 * @param path path to file
91 */
92 void saveToDisk(string path);
93
94
95 // Loader
15c82487 96
97 /**
98 * Load document from file
99 * @param path path to file
100 */
101 void loadFromDisk(string path);
102
103 /**
104 * Find all children with the specified name
105 * @param name name of children
106 * @return true if found, else false
107 */
108 bool findChild(string name);
109
110 /**
111 * Find next child in current search result list
112 * @return true if found, else false
113 */
114 bool findNextChild();
115
116 /**
117 * Get content of current child as a string
118 * @return the string
119 */
120 string getString();
121
122 /**
123 * Get content of current child as a number
124 * @return the number
125 */
126 double getNumber();
127
128 /**
129 * Get attribute value of current child
130 * @param name name of attribute
131 * @return the value
132 */
133 string getAttribute(string name);
134
68a7b857 135
136 /**
137 * Convert double to string
138 * @param doubleValue the double value
139 * @return the corresponding string
140 */
141 string doubleToString(double doubleValue);
142
15c82487 143private:
144
145 // Saver
146 xmlpp::Element *_rootElement;
147 xmlpp::Element *_activeElement;
148 xmlpp::Document *_activeDocument;
149
150 // Loader
151 xmlpp::DomParser _parser;
152 xmlpp::Node::NodeList _activeList;
153 xmlpp::Node::NodeList::iterator _activeChildInList;
154};
155
156
157
158#endif