diff options
Diffstat (limited to '')
-rw-r--r-- | src/old/xmlnode.h | 207 |
1 files changed, 0 insertions, 207 deletions
diff --git a/src/old/xmlnode.h b/src/old/xmlnode.h deleted file mode 100644 index c895cd8..0000000 --- a/src/old/xmlnode.h +++ /dev/null | |||
@@ -1,207 +0,0 @@ | |||
1 | #ifndef XMLNODE | ||
2 | #define XMLNODE | ||
3 | |||
4 | #include <iostream> | ||
5 | #include "bu/list.h" | ||
6 | #include "bu/hash.h" | ||
7 | #include "bu/fstring.h" | ||
8 | |||
9 | /** | ||
10 | * Maintains all data pertient to an XML node, including sub-nodes and content. | ||
11 | * All child nodes can be accessed through index and through name via a hash | ||
12 | * table. This makes it very easy to gain simple and fast access to all of | ||
13 | * your data. For most applications, the memory footprint is also rather | ||
14 | * small. While XmlNode objects can be used directly to create XML structures | ||
15 | * it is highly reccomended that all operations be performed through the | ||
16 | * XmlDocument class. | ||
17 | *@author Mike Buland | ||
18 | */ | ||
19 | class XmlNode | ||
20 | { | ||
21 | public: | ||
22 | /** | ||
23 | * Construct a new XmlNode. | ||
24 | *@param sName The name of the node. | ||
25 | *@param pParent The parent node. | ||
26 | *@param sContent The initial content string. | ||
27 | */ | ||
28 | XmlNode( | ||
29 | const Bu::FString &sName, | ||
30 | XmlNode *pParent=NULL | ||
31 | ); | ||
32 | |||
33 | /** | ||
34 | * Delete the node and cleanup all memory. | ||
35 | */ | ||
36 | virtual ~XmlNode(); | ||
37 | |||
38 | /** | ||
39 | * Change the name of the node. | ||
40 | *@param sName The new name of the node. | ||
41 | */ | ||
42 | //void setName( const char *sName ); | ||
43 | |||
44 | /** | ||
45 | * Construct a new node and add it as a child to this node, also return a | ||
46 | * pointer to the newly constructed node. | ||
47 | *@param sName The name of the new node. | ||
48 | *@param sContent The initial content of the new node. | ||
49 | *@returns A pointer to the newly created child node. | ||
50 | */ | ||
51 | XmlNode *addChild( const Bu::FString &sName ); | ||
52 | |||
53 | /** | ||
54 | * Add an already created XmlNode as a child to this node. The new child | ||
55 | * XmlNode's parent will be changed appropriately and the parent XmlNode | ||
56 | * will take ownership of the child. | ||
57 | *@param pChild The child XmlNode to add to this XmlNode. | ||
58 | *@returns A pointer to the child node that was just added. | ||
59 | */ | ||
60 | XmlNode *addChild( XmlNode *pChild ); | ||
61 | |||
62 | /** | ||
63 | * Add a new property to the XmlNode. Properties are name/value pairs. | ||
64 | *@param sName The name of the property. Specifying a name that's already | ||
65 | * in use will overwrite that property. | ||
66 | *@param sValue The textual value of the property. | ||
67 | */ | ||
68 | void addProperty( const Bu::FString &sName, const Bu::FString &sValue ); | ||
69 | |||
70 | /** | ||
71 | * Get a pointer to the parent node, if any. | ||
72 | *@returns A pointer to the node's parent, or NULL if there isn't one. | ||
73 | */ | ||
74 | XmlNode *getParent(); | ||
75 | |||
76 | /** | ||
77 | * Tells you if this node has children. | ||
78 | *@returns True if this node has at least one child, false otherwise. | ||
79 | */ | ||
80 | bool hasChildren(); | ||
81 | |||
82 | /** | ||
83 | * Tells you how many children this node has. | ||
84 | *@returns The number of children this node has. | ||
85 | */ | ||
86 | int getNumChildren(); | ||
87 | |||
88 | /** | ||
89 | * Get a child with the specified name, and possibly skip value. For an | ||
90 | * explination of skip values see the HashTable. | ||
91 | *@param sName The name of the child to find. | ||
92 | *@param nSkip The number of nodes with that name to skip. | ||
93 | *@returns A pointer to the child, or NULL if no child with that name was | ||
94 | * found. | ||
95 | */ | ||
96 | XmlNode *getChild( const Bu::FString &sName, int nSkip=0 ); | ||
97 | |||
98 | /** | ||
99 | * Get a pointer to the name of this node. Do not change this, use setName | ||
100 | * instead. | ||
101 | *@returns A pointer to the name of this node. | ||
102 | */ | ||
103 | Bu::FString getName(); | ||
104 | |||
105 | /** | ||
106 | * Set the content of this node, optionally at a specific index. Using the | ||
107 | * default of -1 will set the content after the last added node. | ||
108 | *@param sContent The content string to use. | ||
109 | *@param nIndex The index of the content. | ||
110 | */ | ||
111 | //void setContent( const char *sContent, int nIndex=-1 ); | ||
112 | |||
113 | /** | ||
114 | * Get the number of properties in this node. | ||
115 | *@returns The number of properties in this node. | ||
116 | */ | ||
117 | int getNumProperties(); | ||
118 | |||
119 | /** | ||
120 | * Get a propery's value by name. | ||
121 | *@param sName The name of the property to examine. | ||
122 | *@returns A pointer to the value of the property specified, or NULL if none | ||
123 | * found. | ||
124 | */ | ||
125 | Bu::FString getProperty( const Bu::FString &sName ); | ||
126 | |||
127 | /** | ||
128 | * Delete a child node, possibly replacing it with some text. This actually | ||
129 | * fixes all content strings around the newly deleted child node. | ||
130 | *@param nIndex The index of the node to delete. | ||
131 | *@param sReplacementText The optional text to replace the node with. | ||
132 | *@returns True of the node was found, and deleted, false if it wasn't | ||
133 | * found. | ||
134 | */ | ||
135 | //void deleteNode( int nIndex, const char *sReplacementText = NULL ); | ||
136 | |||
137 | /** | ||
138 | * Delete a given node, but move all of it's children and content up to | ||
139 | * replace the deleted node. All of the content of the child node is | ||
140 | * spliced seamlessly into place with the parent node's content. | ||
141 | *@param nIndex The node to delete. | ||
142 | *@returns True if the node was found and deleted, false if it wasn't. | ||
143 | */ | ||
144 | //void deleteNodeKeepChildren( int nIndex ); | ||
145 | |||
146 | /** | ||
147 | * Detatch a given child node from this node. This effectively works just | ||
148 | * like a deleteNode, except that instead of deleting the node it is removed | ||
149 | * and returned, and all ownership is given up. | ||
150 | *@param nIndex The index of the node to detatch. | ||
151 | *@param sReplacementText The optional text to replace the detatched node | ||
152 | * with. | ||
153 | *@returns A pointer to the newly detatched node, which then passes | ||
154 | * ownership to the caller. | ||
155 | */ | ||
156 | //XmlNode *detatchNode( int nIndex, const char *sReplacementText = NULL ); | ||
157 | |||
158 | /** | ||
159 | * Replace a given node with a different node that is not currently owned by | ||
160 | * this XmlNode or any ancestor. | ||
161 | *@param nIndex The index of the node to replace. | ||
162 | *@param pNewNode The new node to replace the old node with. | ||
163 | *@returns True if the node was found and replaced, false if it wasn't. | ||
164 | */ | ||
165 | //void replaceNode( int nIndex, XmlNode *pNewNode ); | ||
166 | |||
167 | /** | ||
168 | * Replace a given node with the children and content of a given node. | ||
169 | *@param nIndex The index of the node to replace. | ||
170 | *@param pNewNode The node that contains the children and content that will | ||
171 | * replace the node specified by nIndex. | ||
172 | *@returns True if the node was found and replaced, false if it wasn't. | ||
173 | */ | ||
174 | //void replaceNodeWithChildren( int nIndex, XmlNode *pNewNode ); | ||
175 | |||
176 | /** | ||
177 | * Get a copy of this node and all children. getCopy is recursive, so | ||
178 | * beware copying large trees of xml. | ||
179 | *@returns A newly created copy of this node and all of it's children. | ||
180 | */ | ||
181 | //XmlNode *getCopy(); | ||
182 | |||
183 | enum ChildType | ||
184 | { | ||
185 | typeNode, | ||
186 | typeContent | ||
187 | }; | ||
188 | |||
189 | private: | ||
190 | typedef struct | ||
191 | { | ||
192 | uint8_t nType; | ||
193 | union { | ||
194 | XmlNode *pNode; | ||
195 | Bu::FString *pContent; | ||
196 | }; | ||
197 | } Child; | ||
198 | Bu::FString sName; /**< The name of the node. */ | ||
199 | Bu::List<Child> lChildren; /**< The children. */ | ||
200 | Bu::Hash<Bu::FString, Bu::FString> hProperties; /**< Property hashtable. */ | ||
201 | Bu::Hash<Bu::FString, Bu::List<XmlNode *> > hChildren; /**< Children hashtable. */ | ||
202 | XmlNode *pParent; /**< A pointer to the parent of this node. */ | ||
203 | int nCurContent; /**< The current content we're on, for using the -1 on | ||
204 | setContent. */ | ||
205 | }; | ||
206 | |||
207 | #endif | ||