diff options
Diffstat (limited to 'src/xmldocument.h')
-rw-r--r-- | src/xmldocument.h | 163 |
1 files changed, 163 insertions, 0 deletions
diff --git a/src/xmldocument.h b/src/xmldocument.h new file mode 100644 index 0000000..f9a8606 --- /dev/null +++ b/src/xmldocument.h | |||
@@ -0,0 +1,163 @@ | |||
1 | #ifndef XMLDOCUMENT | ||
2 | #define XMLDOCUMENT | ||
3 | |||
4 | #include "xmlnode.h" | ||
5 | |||
6 | /** | ||
7 | * Keeps track of an easily managed set of XmlNode information. Allows simple | ||
8 | * operations for logical writing to and reading from XML structures. Using | ||
9 | * already formed structures is simply done through the XmlNode structures, | ||
10 | * and the getRoot function here. Creation is performed through a simple set | ||
11 | * of operations that creates the data in a stream type format. | ||
12 | *@author Mike Buland | ||
13 | */ | ||
14 | class XmlDocument | ||
15 | { | ||
16 | public: | ||
17 | /** | ||
18 | * Construct either a blank XmlDocuemnt or construct a document around an | ||
19 | * existing XmlNode. Be careful, once an XmlNode is passed into a document | ||
20 | * the document takes over ownership and will delete it when the XmlDocument | ||
21 | * is deleted. | ||
22 | *@param pRoot The XmlNode to use as the root of this document, or NULL if | ||
23 | * you want to start a new document. | ||
24 | */ | ||
25 | XmlDocument( XmlNode *pRoot=NULL ); | ||
26 | |||
27 | /** | ||
28 | * Destroy all contained nodes. | ||
29 | */ | ||
30 | ~XmlDocument(); | ||
31 | |||
32 | /** | ||
33 | * Add a new node to the document. The new node is appended to the end of | ||
34 | * the current context, i.e. XmlNode, and the new node, provided it isn't | ||
35 | * close as part of this operation, will become the current context. | ||
36 | *@param sName The name of the new node to add. | ||
37 | *@param sContent A content string to be placed inside of the new node. | ||
38 | *@param bClose Set this to true to close the node immediately after adding | ||
39 | * the node and setting the content and name. If this is set to true the | ||
40 | * node is appended, but the context node doesn't change. | ||
41 | */ | ||
42 | void addNode( const char *sName=NULL, const char *sContent=NULL, bool bClose=false ); | ||
43 | |||
44 | /** | ||
45 | * Set the name of the current node context. | ||
46 | *@param sName The new name of the node. | ||
47 | */ | ||
48 | void setName( const char *sName ); | ||
49 | |||
50 | /** | ||
51 | * Close the current node context. This will move the current context to | ||
52 | * the parent node of the former current node. If the current node was the | ||
53 | * root then the "completed" flag is set and no more operations are allowed. | ||
54 | */ | ||
55 | void closeNode(); | ||
56 | |||
57 | /** | ||
58 | * Change the content of the current node at the current position between | ||
59 | * nodes. | ||
60 | *@param sContent The new content of the current node. | ||
61 | */ | ||
62 | void setContent( const char *sContent ); | ||
63 | |||
64 | /** | ||
65 | * Add a named property to the current context node. | ||
66 | *@param sName The name of the property to add. | ||
67 | *@param sValue The string value of the property. | ||
68 | */ | ||
69 | void addProperty( const char *sName, const char *sValue ); | ||
70 | |||
71 | /** | ||
72 | * Add a named property to the current context node, converting the | ||
73 | * numerical parameter to text using standrd printf style conversion. | ||
74 | *@param sName The name of the property to add. | ||
75 | *@param nValue The numerical value to add. | ||
76 | */ | ||
77 | void addProperty( const char *sName, const unsigned char nValue ); | ||
78 | |||
79 | /** | ||
80 | * Add a named property to the current context node, converting the | ||
81 | * numerical parameter to text using standrd printf style conversion. | ||
82 | *@param sName The name of the property to add. | ||
83 | *@param nValue The numerical value to add. | ||
84 | */ | ||
85 | void addProperty( const char *sName, const char nValue ); | ||
86 | |||
87 | /** | ||
88 | * Add a named property to the current context node, converting the | ||
89 | * numerical parameter to text using standrd printf style conversion. | ||
90 | *@param sName The name of the property to add. | ||
91 | *@param nValue The numerical value to add. | ||
92 | */ | ||
93 | void addProperty( const char *sName, const unsigned short nValue ); | ||
94 | |||
95 | /** | ||
96 | * Add a named property to the current context node, converting the | ||
97 | * numerical parameter to text using standrd printf style conversion. | ||
98 | *@param sName The name of the property to add. | ||
99 | *@param nValue The numerical value to add. | ||
100 | */ | ||
101 | void addProperty( const char *sName, const short nValue ); | ||
102 | |||
103 | /** | ||
104 | * Add a named property to the current context node, converting the | ||
105 | * numerical parameter to text using standrd printf style conversion. | ||
106 | *@param sName The name of the property to add. | ||
107 | *@param nValue The numerical value to add. | ||
108 | */ | ||
109 | void addProperty( const char *sName, const unsigned long nValue ); | ||
110 | |||
111 | /** | ||
112 | * Add a named property to the current context node, converting the | ||
113 | * numerical parameter to text using standrd printf style conversion. | ||
114 | *@param sName The name of the property to add. | ||
115 | *@param nValue The numerical value to add. | ||
116 | */ | ||
117 | void addProperty( const char *sName, const long nValue ); | ||
118 | |||
119 | /** | ||
120 | * Add a named property to the current context node, converting the | ||
121 | * numerical parameter to text using standrd printf style conversion. | ||
122 | *@param sName The name of the property to add. | ||
123 | *@param nValue The numerical value to add. | ||
124 | */ | ||
125 | void addProperty( const char *sName, const int nValue ); | ||
126 | |||
127 | /** | ||
128 | * Add a named property to the current context node, converting the | ||
129 | * numerical parameter to text using standrd printf style conversion. | ||
130 | *@param sName The name of the property to add. | ||
131 | *@param dValue The numerical value to add. | ||
132 | */ | ||
133 | void addProperty( const char *sName, const double dValue ); | ||
134 | |||
135 | /** | ||
136 | * The XmlDocuemnt is considered completed if the root node has been closed. | ||
137 | * Once an XmlDocument has been completed, you can no longer perform | ||
138 | * operations on it. | ||
139 | *@return True if completed, false if still in progress. | ||
140 | */ | ||
141 | bool isCompleted(); | ||
142 | |||
143 | /** | ||
144 | * Get a pointer to the root object of this XmlDocument. | ||
145 | *@returns A pointer to an internally owned XmlNode. Do not delete this | ||
146 | * XmlNode. | ||
147 | */ | ||
148 | XmlNode *getRoot(); | ||
149 | |||
150 | /** | ||
151 | * Get the current context node, which could be the same as the root node. | ||
152 | *@returns A pointer to an internally owned XmlNode. Do not delete this | ||
153 | * XmlNode. | ||
154 | */ | ||
155 | XmlNode *getCurrent(); | ||
156 | |||
157 | private: | ||
158 | XmlNode *pRoot; /**< The root node. */ | ||
159 | XmlNode *pCurrent; /**< The current node. */ | ||
160 | bool bCompleted; /**< Is it completed? */ | ||
161 | }; | ||
162 | |||
163 | #endif | ||