Lee Thomason (grinliz) | 2812986 | 2012-02-25 21:11:20 -0800 | [diff] [blame] | 1 | /*
|
| 2 | Original code by Lee Thomason (www.grinninglizard.com)
|
| 3 |
|
| 4 | This software is provided 'as-is', without any express or implied
|
| 5 | warranty. In no event will the authors be held liable for any
|
| 6 | damages arising from the use of this software.
|
| 7 |
|
| 8 | Permission is granted to anyone to use this software for any
|
| 9 | purpose, including commercial applications, and to alter it and
|
| 10 | redistribute it freely, subject to the following restrictions:
|
| 11 |
|
| 12 | 1. The origin of this software must not be misrepresented; you must
|
| 13 | not claim that you wrote the original software. If you use this
|
| 14 | software in a product, an acknowledgment in the product documentation
|
| 15 | would be appreciated but is not required.
|
| 16 |
|
| 17 | 2. Altered source versions must be plainly marked as such, and
|
| 18 | must not be misrepresented as being the original software.
|
| 19 |
|
| 20 | 3. This notice may not be removed or altered from any source
|
| 21 | distribution.
|
| 22 | */
|
Lee Thomason (grinliz) | 9c38d13 | 2012-02-24 21:50:50 -0800 | [diff] [blame] | 23 |
|
Lee Thomason | 7d00b9a | 2012-02-27 17:54:22 -0800 | [diff] [blame] | 24 | #ifndef TINYXML2_INCLUDED
|
U-Lama\Lee | e13c3e6 | 2011-12-28 14:36:55 -0800 | [diff] [blame] | 25 | #define TINYXML2_INCLUDED
|
| 26 |
|
Lee Thomason (grinliz) | bc1bfb7 | 2012-08-20 22:00:38 -0700 | [diff] [blame] | 27 | #ifdef ANDROID_NDK
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 28 | # include <ctype.h>
|
| 29 | # include <limits.h>
|
| 30 | # include <stdio.h>
|
| 31 | # include <stdlib.h>
|
| 32 | # include <string.h>
|
| 33 | # include <stdarg.h>
|
Lee Thomason (grinliz) | bc1bfb7 | 2012-08-20 22:00:38 -0700 | [diff] [blame] | 34 | #else
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 35 | # include <cctype>
|
| 36 | # include <climits>
|
| 37 | # include <cstdio>
|
| 38 | # include <cstdlib>
|
| 39 | # include <cstring>
|
| 40 | # include <cstdarg>
|
Lee Thomason (grinliz) | bc1bfb7 | 2012-08-20 22:00:38 -0700 | [diff] [blame] | 41 | #endif
|
Lee Thomason (grinliz) | 6a22be2 | 2012-04-04 12:39:05 -0700 | [diff] [blame] | 42 |
|
Lee Thomason (grinliz) | 2f1f624 | 2012-09-16 11:32:34 -0700 | [diff] [blame] | 43 | /*
|
Lee Thomason | 7d00b9a | 2012-02-27 17:54:22 -0800 | [diff] [blame] | 44 | TODO: intern strings instead of allocation.
|
Lee Thomason (grinliz) | 2a1cd27 | 2012-02-24 17:37:53 -0800 | [diff] [blame] | 45 | */
|
Lee Thomason (grinliz) | 9b093cc | 2012-02-25 21:30:18 -0800 | [diff] [blame] | 46 | /*
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 47 | gcc:
|
| 48 | g++ -Wall tinyxml2.cpp xmltest.cpp -o gccxmltest.exe
|
| 49 |
|
| 50 | Formatting, Artistic Style:
|
| 51 | AStyle.exe --style=1tbs --indent-switches --break-closing-brackets --indent-preprocessor tinyxml2.cpp tinyxml2.h
|
Lee Thomason (grinliz) | 9b093cc | 2012-02-25 21:30:18 -0800 | [diff] [blame] | 52 | */
|
Lee Thomason (grinliz) | 2a1cd27 | 2012-02-24 17:37:53 -0800 | [diff] [blame] | 53 |
|
U-Lama\Lee | 4cee611 | 2011-12-31 14:58:18 -0800 | [diff] [blame] | 54 | #if defined( _DEBUG ) || defined( DEBUG ) || defined (__DEBUG__)
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 55 | # ifndef DEBUG
|
| 56 | # define DEBUG
|
| 57 | # endif
|
U-Lama\Lee | 4cee611 | 2011-12-31 14:58:18 -0800 | [diff] [blame] | 58 | #endif
|
| 59 |
|
| 60 |
|
| 61 | #if defined(DEBUG)
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 62 | # if defined(_MSC_VER)
|
| 63 | # define TIXMLASSERT( x ) if ( !(x)) { __debugbreak(); } //if ( !(x)) WinDebugBreak()
|
| 64 | # elif defined (ANDROID_NDK)
|
| 65 | # include <android/log.h>
|
| 66 | # define TIXMLASSERT( x ) if ( !(x)) { __android_log_assert( "assert", "grinliz", "ASSERT in '%s' at %d.", __FILE__, __LINE__ ); }
|
| 67 | # else
|
| 68 | # include <assert.h>
|
| 69 | # define TIXMLASSERT assert
|
| 70 | # endif
|
| 71 | # else
|
| 72 | # define TIXMLASSERT( x ) {}
|
U-Lama\Lee | 4cee611 | 2011-12-31 14:58:18 -0800 | [diff] [blame] | 73 | #endif
|
| 74 |
|
U-Lama\Lee | e13c3e6 | 2011-12-28 14:36:55 -0800 | [diff] [blame] | 75 |
|
Lee Thomason | 1a1d4a7 | 2012-02-15 09:09:25 -0800 | [diff] [blame] | 76 | #if defined(_MSC_VER) && (_MSC_VER >= 1400 )
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 77 | // Microsoft visual studio, version 2005 and higher.
|
| 78 | /*int _snprintf_s(
|
| 79 | char *buffer,
|
| 80 | size_t sizeOfBuffer,
|
| 81 | size_t count,
|
| 82 | const char *format [,
|
| 83 | argument] ...
|
| 84 | );*/
|
| 85 | inline int TIXML_SNPRINTF( char* buffer, size_t size, const char* format, ... )
|
| 86 | {
|
| 87 | va_list va;
|
| 88 | va_start( va, format );
|
| 89 | int result = vsnprintf_s( buffer, size, _TRUNCATE, format, va );
|
| 90 | va_end( va );
|
| 91 | return result;
|
| 92 | }
|
| 93 | #define TIXML_SSCANF sscanf_s
|
Lee Thomason (grinliz) | b9e791f | 2012-04-06 21:27:10 -0700 | [diff] [blame] | 94 | #else
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 95 | // GCC version 3 and higher
|
| 96 | //#warning( "Using sn* functions." )
|
| 97 | #define TIXML_SNPRINTF snprintf
|
| 98 | #define TIXML_SSCANF sscanf
|
Lee Thomason | 1a1d4a7 | 2012-02-15 09:09:25 -0800 | [diff] [blame] | 99 | #endif
|
Lee Thomason | 1ff38e0 | 2012-02-14 18:18:16 -0800 | [diff] [blame] | 100 |
|
Lee Thomason (grinliz) | 390e978 | 2012-07-01 21:22:53 -0700 | [diff] [blame] | 101 | static const int TIXML2_MAJOR_VERSION = 1;
|
| 102 | static const int TIXML2_MINOR_VERSION = 0;
|
Lee Thomason (grinliz) | fc6320e | 2012-09-23 20:25:50 -0700 | [diff] [blame] | 103 | static const int TIXML2_PATCH_VERSION = 8;
|
Lee Thomason | 1ff38e0 | 2012-02-14 18:18:16 -0800 | [diff] [blame] | 104 |
|
U-Lama\Lee | e13c3e6 | 2011-12-28 14:36:55 -0800 | [diff] [blame] | 105 | namespace tinyxml2
|
| 106 | {
|
Lee Thomason | ce0763e | 2012-01-11 15:43:54 -0800 | [diff] [blame] | 107 | class XMLDocument;
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 108 | class XMLElement;
|
| 109 | class XMLAttribute;
|
| 110 | class XMLComment;
|
| 111 | class XMLNode;
|
Lee Thomason | 5492a1c | 2012-01-23 15:32:10 -0800 | [diff] [blame] | 112 | class XMLText;
|
Lee Thomason | 50f97b2 | 2012-02-11 16:33:40 -0800 | [diff] [blame] | 113 | class XMLDeclaration;
|
| 114 | class XMLUnknown;
|
U-Lama\Lee | e13c3e6 | 2011-12-28 14:36:55 -0800 | [diff] [blame] | 115 |
|
Lee Thomason (grinliz) | 2a1cd27 | 2012-02-24 17:37:53 -0800 | [diff] [blame] | 116 | class XMLPrinter;
|
Lee Thomason | 5cae897 | 2012-01-24 18:03:07 -0800 | [diff] [blame] | 117 |
|
U-Stream\Lee | ae25a44 | 2012-02-17 17:48:16 -0800 | [diff] [blame] | 118 | /*
|
| 119 | A class that wraps strings. Normally stores the start and end
|
| 120 | pointers into the XML file itself, and will apply normalization
|
Lee Thomason (grinliz) | 2a1cd27 | 2012-02-24 17:37:53 -0800 | [diff] [blame] | 121 | and entity translation if actually read. Can also store (and memory
|
U-Stream\Lee | ae25a44 | 2012-02-17 17:48:16 -0800 | [diff] [blame] | 122 | manage) a traditional char[]
|
| 123 | */
|
Lee Thomason | 39ede24 | 2012-01-20 11:27:56 -0800 | [diff] [blame] | 124 | class StrPair
|
| 125 | {
|
Lee Thomason | d34f52c | 2012-01-20 12:55:24 -0800 | [diff] [blame] | 126 | public:
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 127 | enum {
|
| 128 | NEEDS_ENTITY_PROCESSING = 0x01,
|
| 129 | NEEDS_NEWLINE_NORMALIZATION = 0x02,
|
| 130 | COLLAPSE_WHITESPACE = 0x04,
|
Lee Thomason | 18d68bd | 2012-01-26 18:17:26 -0800 | [diff] [blame] | 131 |
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 132 | TEXT_ELEMENT = NEEDS_ENTITY_PROCESSING | NEEDS_NEWLINE_NORMALIZATION,
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 133 | TEXT_ELEMENT_LEAVE_ENTITIES = NEEDS_NEWLINE_NORMALIZATION,
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 134 | ATTRIBUTE_NAME = 0,
|
| 135 | ATTRIBUTE_VALUE = NEEDS_ENTITY_PROCESSING | NEEDS_NEWLINE_NORMALIZATION,
|
| 136 | ATTRIBUTE_VALUE_LEAVE_ENTITIES = NEEDS_NEWLINE_NORMALIZATION,
|
| 137 | COMMENT = NEEDS_NEWLINE_NORMALIZATION
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 138 | };
|
Lee Thomason | 39ede24 | 2012-01-20 11:27:56 -0800 | [diff] [blame] | 139 |
|
Lee Thomason | 120b3a6 | 2012-10-12 10:06:59 -0700 | [diff] [blame] | 140 | StrPair() : _flags( 0 ), _start( 0 ), _end( 0 ) {}
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 141 | ~StrPair();
|
Lee Thomason | 1a1d4a7 | 2012-02-15 09:09:25 -0800 | [diff] [blame] | 142 |
|
Lee Thomason | 120b3a6 | 2012-10-12 10:06:59 -0700 | [diff] [blame] | 143 | void Set( char* start, char* end, int flags ) {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 144 | Reset();
|
Lee Thomason | 120b3a6 | 2012-10-12 10:06:59 -0700 | [diff] [blame] | 145 | _start = start;
|
| 146 | _end = end;
|
| 147 | _flags = flags | NEEDS_FLUSH;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 148 | }
|
Lee Thomason | 120b3a6 | 2012-10-12 10:06:59 -0700 | [diff] [blame] | 149 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 150 | const char* GetStr();
|
Lee Thomason | 120b3a6 | 2012-10-12 10:06:59 -0700 | [diff] [blame] | 151 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 152 | bool Empty() const {
|
Lee Thomason | 120b3a6 | 2012-10-12 10:06:59 -0700 | [diff] [blame] | 153 | return _start == _end;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 154 | }
|
Lee Thomason | 39ede24 | 2012-01-20 11:27:56 -0800 | [diff] [blame] | 155 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 156 | void SetInternedStr( const char* str ) {
|
| 157 | Reset();
|
Lee Thomason | 120b3a6 | 2012-10-12 10:06:59 -0700 | [diff] [blame] | 158 | _start = const_cast<char*>(str);
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 159 | }
|
Lee Thomason | 120b3a6 | 2012-10-12 10:06:59 -0700 | [diff] [blame] | 160 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 161 | void SetStr( const char* str, int flags=0 );
|
Lee Thomason | 1a1d4a7 | 2012-02-15 09:09:25 -0800 | [diff] [blame] | 162 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 163 | char* ParseText( char* in, const char* endTag, int strFlags );
|
| 164 | char* ParseName( char* in );
|
Lee Thomason | 56bdd02 | 2012-02-09 18:16:58 -0800 | [diff] [blame] | 165 |
|
Lee Thomason | 39ede24 | 2012-01-20 11:27:56 -0800 | [diff] [blame] | 166 | private:
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 167 | void Reset();
|
| 168 | void CollapseWhitespace();
|
Lee Thomason | 1a1d4a7 | 2012-02-15 09:09:25 -0800 | [diff] [blame] | 169 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 170 | enum {
|
| 171 | NEEDS_FLUSH = 0x100,
|
| 172 | NEEDS_DELETE = 0x200
|
| 173 | };
|
Lee Thomason | e442230 | 2012-01-20 17:59:50 -0800 | [diff] [blame] | 174 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 175 | // After parsing, if *end != 0, it can be set to zero.
|
Lee Thomason | 120b3a6 | 2012-10-12 10:06:59 -0700 | [diff] [blame] | 176 | int _flags;
|
| 177 | char* _start;
|
| 178 | char* _end;
|
Lee Thomason | 39ede24 | 2012-01-20 11:27:56 -0800 | [diff] [blame] | 179 | };
|
| 180 |
|
U-Lama\Lee | 560bd47 | 2011-12-28 19:42:49 -0800 | [diff] [blame] | 181 |
|
U-Stream\Lee | ae25a44 | 2012-02-17 17:48:16 -0800 | [diff] [blame] | 182 | /*
|
| 183 | A dynamic array of Plain Old Data. Doesn't support constructors, etc.
|
| 184 | Has a small initial memory pool, so that low or no usage will not
|
| 185 | cause a call to new/delete
|
| 186 | */
|
Lee Thomason | 2c85a71 | 2012-01-31 08:24:24 -0800 | [diff] [blame] | 187 | template <class T, int INIT>
|
| 188 | class DynArray
|
| 189 | {
|
| 190 | public:
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 191 | DynArray< T, INIT >() {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 192 | _mem = _pool;
|
| 193 | _allocated = INIT;
|
| 194 | _size = 0;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 195 | }
|
Lee Thomason | 120b3a6 | 2012-10-12 10:06:59 -0700 | [diff] [blame] | 196 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 197 | ~DynArray() {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 198 | if ( _mem != _pool ) {
|
Lee Thomason | ed5c879 | 2012-10-12 10:09:48 -0700 | [diff] [blame] | 199 | delete [] _mem;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 200 | }
|
| 201 | }
|
Lee Thomason | 120b3a6 | 2012-10-12 10:06:59 -0700 | [diff] [blame] | 202 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 203 | void Push( T t ) {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 204 | EnsureCapacity( _size+1 );
|
| 205 | _mem[_size++] = t;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 206 | }
|
Lee Thomason | 2c85a71 | 2012-01-31 08:24:24 -0800 | [diff] [blame] | 207 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 208 | T* PushArr( int count ) {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 209 | EnsureCapacity( _size+count );
|
| 210 | T* ret = &_mem[_size];
|
| 211 | _size += count;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 212 | return ret;
|
| 213 | }
|
Lee Thomason | 120b3a6 | 2012-10-12 10:06:59 -0700 | [diff] [blame] | 214 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 215 | T Pop() {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 216 | return _mem[--_size];
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 217 | }
|
Lee Thomason | 120b3a6 | 2012-10-12 10:06:59 -0700 | [diff] [blame] | 218 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 219 | void PopArr( int count ) {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 220 | TIXMLASSERT( _size >= count );
|
| 221 | _size -= count;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 222 | }
|
Lee Thomason | 2c85a71 | 2012-01-31 08:24:24 -0800 | [diff] [blame] | 223 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 224 | bool Empty() const {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 225 | return _size == 0;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 226 | }
|
Lee Thomason | 120b3a6 | 2012-10-12 10:06:59 -0700 | [diff] [blame] | 227 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 228 | T& operator[](int i) {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 229 | TIXMLASSERT( i>= 0 && i < _size );
|
Lee Thomason | ed5c879 | 2012-10-12 10:09:48 -0700 | [diff] [blame] | 230 | return _mem[i];
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 231 | }
|
Lee Thomason | 120b3a6 | 2012-10-12 10:06:59 -0700 | [diff] [blame] | 232 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 233 | const T& operator[](int i) const {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 234 | TIXMLASSERT( i>= 0 && i < _size );
|
Lee Thomason | ed5c879 | 2012-10-12 10:09:48 -0700 | [diff] [blame] | 235 | return _mem[i];
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 236 | }
|
Lee Thomason | 120b3a6 | 2012-10-12 10:06:59 -0700 | [diff] [blame] | 237 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 238 | int Size() const {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 239 | return _size;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 240 | }
|
Lee Thomason | 120b3a6 | 2012-10-12 10:06:59 -0700 | [diff] [blame] | 241 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 242 | int Capacity() const {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 243 | return _allocated;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 244 | }
|
Lee Thomason | 120b3a6 | 2012-10-12 10:06:59 -0700 | [diff] [blame] | 245 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 246 | const T* Mem() const {
|
Lee Thomason | ed5c879 | 2012-10-12 10:09:48 -0700 | [diff] [blame] | 247 | return _mem;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 248 | }
|
Lee Thomason | 120b3a6 | 2012-10-12 10:06:59 -0700 | [diff] [blame] | 249 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 250 | T* Mem() {
|
Lee Thomason | ed5c879 | 2012-10-12 10:09:48 -0700 | [diff] [blame] | 251 | return _mem;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 252 | }
|
Lee Thomason | 2c85a71 | 2012-01-31 08:24:24 -0800 | [diff] [blame] | 253 |
|
Lee Thomason | 2c85a71 | 2012-01-31 08:24:24 -0800 | [diff] [blame] | 254 | private:
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 255 | void EnsureCapacity( int cap ) {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 256 | if ( cap > _allocated ) {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 257 | int newAllocated = cap * 2;
|
| 258 | T* newMem = new T[newAllocated];
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 259 | memcpy( newMem, _mem, sizeof(T)*_size ); // warning: not using constructors, only works for PODs
|
| 260 | if ( _mem != _pool ) {
|
Lee Thomason | ed5c879 | 2012-10-12 10:09:48 -0700 | [diff] [blame] | 261 | delete [] _mem;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 262 | }
|
Lee Thomason | ed5c879 | 2012-10-12 10:09:48 -0700 | [diff] [blame] | 263 | _mem = newMem;
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 264 | _allocated = newAllocated;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 265 | }
|
| 266 | }
|
Lee Thomason | 2c85a71 | 2012-01-31 08:24:24 -0800 | [diff] [blame] | 267 |
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 268 | T* _mem;
|
| 269 | T _pool[INIT];
|
| 270 | int _allocated; // objects allocated
|
| 271 | int _size; // number objects in use
|
Lee Thomason | 2c85a71 | 2012-01-31 08:24:24 -0800 | [diff] [blame] | 272 | };
|
| 273 |
|
Lee Thomason | 50adb4c | 2012-02-13 15:07:09 -0800 | [diff] [blame] | 274 |
|
U-Stream\Lee | ae25a44 | 2012-02-17 17:48:16 -0800 | [diff] [blame] | 275 | /*
|
Thomas Roß | 08bdf50 | 2012-05-12 14:21:23 +0200 | [diff] [blame] | 276 | Parent virtual class of a pool for fast allocation
|
U-Stream\Lee | ae25a44 | 2012-02-17 17:48:16 -0800 | [diff] [blame] | 277 | and deallocation of objects.
|
| 278 | */
|
Lee Thomason | d198322 | 2012-02-06 08:41:24 -0800 | [diff] [blame] | 279 | class MemPool
|
| 280 | {
|
| 281 | public:
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 282 | MemPool() {}
|
| 283 | virtual ~MemPool() {}
|
Lee Thomason | d198322 | 2012-02-06 08:41:24 -0800 | [diff] [blame] | 284 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 285 | virtual int ItemSize() const = 0;
|
| 286 | virtual void* Alloc() = 0;
|
| 287 | virtual void Free( void* ) = 0;
|
Lee Thomason | d198322 | 2012-02-06 08:41:24 -0800 | [diff] [blame] | 288 | };
|
| 289 |
|
Lee Thomason | 50adb4c | 2012-02-13 15:07:09 -0800 | [diff] [blame] | 290 |
|
U-Stream\Lee | ae25a44 | 2012-02-17 17:48:16 -0800 | [diff] [blame] | 291 | /*
|
| 292 | Template child class to create pools of the correct type.
|
| 293 | */
|
Lee Thomason | d198322 | 2012-02-06 08:41:24 -0800 | [diff] [blame] | 294 | template< int SIZE >
|
| 295 | class MemPoolT : public MemPool
|
| 296 | {
|
| 297 | public:
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 298 | MemPoolT() : _root(0), _currentAllocs(0), _nAllocs(0), _maxAllocs(0) {}
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 299 | ~MemPoolT() {
|
| 300 | // Delete the blocks.
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 301 | for( int i=0; i<_blockPtrs.Size(); ++i ) {
|
| 302 | delete _blockPtrs[i];
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 303 | }
|
| 304 | }
|
Lee Thomason | d198322 | 2012-02-06 08:41:24 -0800 | [diff] [blame] | 305 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 306 | virtual int ItemSize() const {
|
| 307 | return SIZE;
|
| 308 | }
|
| 309 | int CurrentAllocs() const {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 310 | return _currentAllocs;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 311 | }
|
Lee Thomason | d198322 | 2012-02-06 08:41:24 -0800 | [diff] [blame] | 312 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 313 | virtual void* Alloc() {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 314 | if ( !_root ) {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 315 | // Need a new block.
|
| 316 | Block* block = new Block();
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 317 | _blockPtrs.Push( block );
|
Lee Thomason | d198322 | 2012-02-06 08:41:24 -0800 | [diff] [blame] | 318 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 319 | for( int i=0; i<COUNT-1; ++i ) {
|
| 320 | block->chunk[i].next = &block->chunk[i+1];
|
| 321 | }
|
| 322 | block->chunk[COUNT-1].next = 0;
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 323 | _root = block->chunk;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 324 | }
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 325 | void* result = _root;
|
| 326 | _root = _root->next;
|
Lee Thomason | 455c9d4 | 2012-02-06 09:14:14 -0800 | [diff] [blame] | 327 |
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 328 | ++_currentAllocs;
|
| 329 | if ( _currentAllocs > _maxAllocs ) {
|
| 330 | _maxAllocs = _currentAllocs;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 331 | }
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 332 | _nAllocs++;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 333 | return result;
|
| 334 | }
|
| 335 | virtual void Free( void* mem ) {
|
| 336 | if ( !mem ) {
|
| 337 | return;
|
| 338 | }
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 339 | --_currentAllocs;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 340 | Chunk* chunk = (Chunk*)mem;
|
Lee Thomason (grinliz) | 6020a01 | 2012-09-08 21:15:09 -0700 | [diff] [blame] | 341 | #ifdef DEBUG
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 342 | memset( chunk, 0xfe, sizeof(Chunk) );
|
Lee Thomason (grinliz) | 6020a01 | 2012-09-08 21:15:09 -0700 | [diff] [blame] | 343 | #endif
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 344 | chunk->next = _root;
|
| 345 | _root = chunk;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 346 | }
|
| 347 | void Trace( const char* name ) {
|
| 348 | printf( "Mempool %s watermark=%d [%dk] current=%d size=%d nAlloc=%d blocks=%d\n",
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 349 | name, _maxAllocs, _maxAllocs*SIZE/1024, _currentAllocs, SIZE, _nAllocs, _blockPtrs.Size() );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 350 | }
|
Lee Thomason | d198322 | 2012-02-06 08:41:24 -0800 | [diff] [blame] | 351 |
|
| 352 | private:
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 353 | enum { COUNT = 1024/SIZE };
|
| 354 | union Chunk {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 355 | Chunk* next;
|
| 356 | char mem[SIZE];
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 357 | };
|
| 358 | struct Block {
|
Lee Thomason (grinliz) | 856da21 | 2012-10-19 09:08:15 -0700 | [diff] [blame^] | 359 | Chunk chunk[COUNT];
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 360 | };
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 361 | DynArray< Block*, 10 > _blockPtrs;
|
| 362 | Chunk* _root;
|
Lee Thomason | 455c9d4 | 2012-02-06 09:14:14 -0800 | [diff] [blame] | 363 |
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 364 | int _currentAllocs;
|
| 365 | int _nAllocs;
|
| 366 | int _maxAllocs;
|
Lee Thomason | d198322 | 2012-02-06 08:41:24 -0800 | [diff] [blame] | 367 | };
|
| 368 |
|
Lee Thomason | 2c85a71 | 2012-01-31 08:24:24 -0800 | [diff] [blame] | 369 |
|
Lee Thomason | 56bdd02 | 2012-02-09 18:16:58 -0800 | [diff] [blame] | 370 |
|
| 371 | /**
|
| 372 | Implements the interface to the "Visitor pattern" (see the Accept() method.)
|
| 373 | If you call the Accept() method, it requires being passed a XMLVisitor
|
| 374 | class to handle callbacks. For nodes that contain other nodes (Document, Element)
|
Thomas Roß | 08bdf50 | 2012-05-12 14:21:23 +0200 | [diff] [blame] | 375 | you will get called with a VisitEnter/VisitExit pair. Nodes that are always leafs
|
Lee Thomason | 56bdd02 | 2012-02-09 18:16:58 -0800 | [diff] [blame] | 376 | are simply called with Visit().
|
| 377 |
|
| 378 | If you return 'true' from a Visit method, recursive parsing will continue. If you return
|
Thomas Roß | 08bdf50 | 2012-05-12 14:21:23 +0200 | [diff] [blame] | 379 | false, <b>no children of this node or its sibilings</b> will be visited.
|
Lee Thomason | 56bdd02 | 2012-02-09 18:16:58 -0800 | [diff] [blame] | 380 |
|
Lee Thomason (grinliz) | 2f1f624 | 2012-09-16 11:32:34 -0700 | [diff] [blame] | 381 | All flavors of Visit methods have a default implementation that returns 'true' (continue
|
Lee Thomason | 56bdd02 | 2012-02-09 18:16:58 -0800 | [diff] [blame] | 382 | visiting). You need to only override methods that are interesting to you.
|
| 383 |
|
Thomas Roß | 08bdf50 | 2012-05-12 14:21:23 +0200 | [diff] [blame] | 384 | Generally Accept() is called on the TiXmlDocument, although all nodes support visiting.
|
Lee Thomason | 56bdd02 | 2012-02-09 18:16:58 -0800 | [diff] [blame] | 385 |
|
| 386 | You should never change the document from a callback.
|
| 387 |
|
| 388 | @sa XMLNode::Accept()
|
| 389 | */
|
| 390 | class XMLVisitor
|
U-Lama\Lee | e13c3e6 | 2011-12-28 14:36:55 -0800 | [diff] [blame] | 391 | {
|
| 392 | public:
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 393 | virtual ~XMLVisitor() {}
|
Lee Thomason | d198322 | 2012-02-06 08:41:24 -0800 | [diff] [blame] | 394 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 395 | /// Visit a document.
|
| 396 | virtual bool VisitEnter( const XMLDocument& /*doc*/ ) {
|
| 397 | return true;
|
| 398 | }
|
| 399 | /// Visit a document.
|
| 400 | virtual bool VisitExit( const XMLDocument& /*doc*/ ) {
|
| 401 | return true;
|
| 402 | }
|
Lee Thomason | 56bdd02 | 2012-02-09 18:16:58 -0800 | [diff] [blame] | 403 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 404 | /// Visit an element.
|
| 405 | virtual bool VisitEnter( const XMLElement& /*element*/, const XMLAttribute* /*firstAttribute*/ ) {
|
| 406 | return true;
|
| 407 | }
|
| 408 | /// Visit an element.
|
| 409 | virtual bool VisitExit( const XMLElement& /*element*/ ) {
|
| 410 | return true;
|
| 411 | }
|
Lee Thomason | 56bdd02 | 2012-02-09 18:16:58 -0800 | [diff] [blame] | 412 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 413 | /// Visit a declaration.
|
| 414 | virtual bool Visit( const XMLDeclaration& /*declaration*/ ) {
|
| 415 | return true;
|
| 416 | }
|
| 417 | /// Visit a text node.
|
| 418 | virtual bool Visit( const XMLText& /*text*/ ) {
|
| 419 | return true;
|
| 420 | }
|
| 421 | /// Visit a comment node.
|
| 422 | virtual bool Visit( const XMLComment& /*comment*/ ) {
|
| 423 | return true;
|
| 424 | }
|
| 425 | /// Visit an unknown node.
|
| 426 | virtual bool Visit( const XMLUnknown& /*unknown*/ ) {
|
| 427 | return true;
|
| 428 | }
|
Lee Thomason | 56bdd02 | 2012-02-09 18:16:58 -0800 | [diff] [blame] | 429 | };
|
| 430 |
|
| 431 |
|
U-Stream\Lee | ae25a44 | 2012-02-17 17:48:16 -0800 | [diff] [blame] | 432 | /*
|
| 433 | Utility functionality.
|
| 434 | */
|
Lee Thomason | 56bdd02 | 2012-02-09 18:16:58 -0800 | [diff] [blame] | 435 | class XMLUtil
|
| 436 | {
|
Lee Thomason | d198322 | 2012-02-06 08:41:24 -0800 | [diff] [blame] | 437 | public:
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 438 | // Anything in the high order range of UTF-8 is assumed to not be whitespace. This isn't
|
| 439 | // correct, but simple, and usually works.
|
| 440 | static const char* SkipWhiteSpace( const char* p ) {
|
Jerome Martinez | 7fbefab | 2012-10-19 11:30:33 +0200 | [diff] [blame] | 441 | while( !IsUTF8Continuation(*p) && std::isspace( *reinterpret_cast<const unsigned char*>(p) ) ) {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 442 | ++p;
|
| 443 | }
|
| 444 | return p;
|
| 445 | }
|
| 446 | static char* SkipWhiteSpace( char* p ) {
|
Jerome Martinez | 7fbefab | 2012-10-19 11:30:33 +0200 | [diff] [blame] | 447 | while( !IsUTF8Continuation(*p) && std::isspace( *reinterpret_cast<unsigned char*>(p) ) ) {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 448 | ++p;
|
| 449 | }
|
| 450 | return p;
|
| 451 | }
|
| 452 | static bool IsWhiteSpace( char p ) {
|
Jerome Martinez | 7fbefab | 2012-10-19 11:30:33 +0200 | [diff] [blame] | 453 | return !IsUTF8Continuation(p) && std::isspace( static_cast<unsigned char>(p) );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 454 | }
|
U-Lama\Lee | 4cee611 | 2011-12-31 14:58:18 -0800 | [diff] [blame] | 455 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 456 | inline static bool StringEqual( const char* p, const char* q, int nChar=INT_MAX ) {
|
| 457 | int n = 0;
|
| 458 | if ( p == q ) {
|
| 459 | return true;
|
| 460 | }
|
| 461 | while( *p && *q && *p == *q && n<nChar ) {
|
| 462 | ++p;
|
| 463 | ++q;
|
| 464 | ++n;
|
| 465 | }
|
| 466 | if ( (n == nChar) || ( *p == 0 && *q == 0 ) ) {
|
| 467 | return true;
|
| 468 | }
|
| 469 | return false;
|
| 470 | }
|
| 471 | inline static int IsUTF8Continuation( const char p ) {
|
| 472 | return p & 0x80;
|
| 473 | }
|
| 474 | inline static int IsAlphaNum( unsigned char anyByte ) {
|
Jerome Martinez | 7fbefab | 2012-10-19 11:30:33 +0200 | [diff] [blame] | 475 | return ( anyByte < 128 ) ? std::isalnum( anyByte ) : 1;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 476 | }
|
| 477 | inline static int IsAlpha( unsigned char anyByte ) {
|
Jerome Martinez | 7fbefab | 2012-10-19 11:30:33 +0200 | [diff] [blame] | 478 | return ( anyByte < 128 ) ? std::isalpha( anyByte ) : 1;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 479 | }
|
Lee Thomason (grinliz) | 68db57e | 2012-02-21 09:08:12 -0800 | [diff] [blame] | 480 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 481 | static const char* ReadBOM( const char* p, bool* hasBOM );
|
| 482 | // p is the starting location,
|
| 483 | // the UTF-8 value of the entity will be placed in value, and length filled in.
|
| 484 | static const char* GetCharacterRef( const char* p, char* value, int* length );
|
| 485 | static void ConvertUTF32ToUTF8( unsigned long input, char* output, int* length );
|
Lee Thomason | 21be882 | 2012-07-15 17:27:22 -0700 | [diff] [blame] | 486 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 487 | // converts primitive types to strings
|
| 488 | static void ToStr( int v, char* buffer, int bufferSize );
|
| 489 | static void ToStr( unsigned v, char* buffer, int bufferSize );
|
| 490 | static void ToStr( bool v, char* buffer, int bufferSize );
|
| 491 | static void ToStr( float v, char* buffer, int bufferSize );
|
| 492 | static void ToStr( double v, char* buffer, int bufferSize );
|
Lee Thomason | 21be882 | 2012-07-15 17:27:22 -0700 | [diff] [blame] | 493 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 494 | // converts strings to primitive types
|
| 495 | static bool ToInt( const char* str, int* value );
|
| 496 | static bool ToUnsigned( const char* str, unsigned* value );
|
| 497 | static bool ToBool( const char* str, bool* value );
|
| 498 | static bool ToFloat( const char* str, float* value );
|
| 499 | static bool ToDouble( const char* str, double* value );
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 500 | };
|
| 501 |
|
Lee Thomason | 5cae897 | 2012-01-24 18:03:07 -0800 | [diff] [blame] | 502 |
|
Lee Thomason (grinliz) | 9c38d13 | 2012-02-24 21:50:50 -0800 | [diff] [blame] | 503 | /** XMLNode is a base class for every object that is in the
|
| 504 | XML Document Object Model (DOM), except XMLAttributes.
|
| 505 | Nodes have siblings, a parent, and children which can
|
| 506 | be navigated. A node is always in a XMLDocument.
|
Lee Thomason (grinliz) | 2f1f624 | 2012-09-16 11:32:34 -0700 | [diff] [blame] | 507 | The type of a XMLNode can be queried, and it can
|
Lee Thomason (grinliz) | 9c38d13 | 2012-02-24 21:50:50 -0800 | [diff] [blame] | 508 | be cast to its more defined type.
|
| 509 |
|
Thomas Roß | 08bdf50 | 2012-05-12 14:21:23 +0200 | [diff] [blame] | 510 | A XMLDocument allocates memory for all its Nodes.
|
Lee Thomason (grinliz) | 9c38d13 | 2012-02-24 21:50:50 -0800 | [diff] [blame] | 511 | When the XMLDocument gets deleted, all its Nodes
|
| 512 | will also be deleted.
|
| 513 |
|
| 514 | @verbatim
|
| 515 | A Document can contain: Element (container or leaf)
|
| 516 | Comment (leaf)
|
| 517 | Unknown (leaf)
|
| 518 | Declaration( leaf )
|
| 519 |
|
| 520 | An Element can contain: Element (container or leaf)
|
| 521 | Text (leaf)
|
| 522 | Attributes (not on tree)
|
| 523 | Comment (leaf)
|
| 524 | Unknown (leaf)
|
| 525 |
|
| 526 | @endverbatim
|
Lee Thomason (grinliz) | 2a1cd27 | 2012-02-24 17:37:53 -0800 | [diff] [blame] | 527 | */
|
Lee Thomason | d198322 | 2012-02-06 08:41:24 -0800 | [diff] [blame] | 528 | class XMLNode
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 529 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 530 | friend class XMLDocument;
|
| 531 | friend class XMLElement;
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 532 | public:
|
Lee Thomason (grinliz) | 2a1cd27 | 2012-02-24 17:37:53 -0800 | [diff] [blame] | 533 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 534 | /// Get the XMLDocument that owns this XMLNode.
|
| 535 | const XMLDocument* GetDocument() const {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 536 | return _document;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 537 | }
|
| 538 | /// Get the XMLDocument that owns this XMLNode.
|
| 539 | XMLDocument* GetDocument() {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 540 | return _document;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 541 | }
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 542 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 543 | virtual XMLElement* ToElement() {
|
| 544 | return 0; ///< Safely cast to an Element, or null.
|
| 545 | }
|
| 546 | virtual XMLText* ToText() {
|
| 547 | return 0; ///< Safely cast to Text, or null.
|
| 548 | }
|
| 549 | virtual XMLComment* ToComment() {
|
| 550 | return 0; ///< Safely cast to a Comment, or null.
|
| 551 | }
|
| 552 | virtual XMLDocument* ToDocument() {
|
| 553 | return 0; ///< Safely cast to a Document, or null.
|
| 554 | }
|
| 555 | virtual XMLDeclaration* ToDeclaration() {
|
| 556 | return 0; ///< Safely cast to a Declaration, or null.
|
| 557 | }
|
| 558 | virtual XMLUnknown* ToUnknown() {
|
| 559 | return 0; ///< Safely cast to an Unknown, or null.
|
| 560 | }
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 561 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 562 | virtual const XMLElement* ToElement() const {
|
| 563 | return 0;
|
| 564 | }
|
| 565 | virtual const XMLText* ToText() const {
|
| 566 | return 0;
|
| 567 | }
|
| 568 | virtual const XMLComment* ToComment() const {
|
| 569 | return 0;
|
| 570 | }
|
| 571 | virtual const XMLDocument* ToDocument() const {
|
| 572 | return 0;
|
| 573 | }
|
| 574 | virtual const XMLDeclaration* ToDeclaration() const {
|
| 575 | return 0;
|
| 576 | }
|
| 577 | virtual const XMLUnknown* ToUnknown() const {
|
| 578 | return 0;
|
| 579 | }
|
Lee Thomason | 751da52 | 2012-02-10 08:50:51 -0800 | [diff] [blame] | 580 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 581 | /** The meaning of 'value' changes for the specific type.
|
| 582 | @verbatim
|
| 583 | Document: empty
|
| 584 | Element: name of the element
|
| 585 | Comment: the comment text
|
| 586 | Unknown: the tag contents
|
| 587 | Text: the text string
|
| 588 | @endverbatim
|
| 589 | */
|
| 590 | const char* Value() const {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 591 | return _value.GetStr();
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 592 | }
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 593 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 594 | /** Set the Value of an XML node.
|
| 595 | @sa Value()
|
| 596 | */
|
| 597 | void SetValue( const char* val, bool staticMem=false );
|
Lee Thomason | 2c85a71 | 2012-01-31 08:24:24 -0800 | [diff] [blame] | 598 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 599 | /// Get the parent of this node on the DOM.
|
| 600 | const XMLNode* Parent() const {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 601 | return _parent;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 602 | }
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 603 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 604 | XMLNode* Parent() {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 605 | return _parent;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 606 | }
|
Lee Thomason | 751da52 | 2012-02-10 08:50:51 -0800 | [diff] [blame] | 607 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 608 | /// Returns true if this node has no children.
|
| 609 | bool NoChildren() const {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 610 | return !_firstChild;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 611 | }
|
Lee Thomason | 751da52 | 2012-02-10 08:50:51 -0800 | [diff] [blame] | 612 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 613 | /// Get the first child node, or null if none exists.
|
| 614 | const XMLNode* FirstChild() const {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 615 | return _firstChild;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 616 | }
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 617 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 618 | XMLNode* FirstChild() {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 619 | return _firstChild;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 620 | }
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 621 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 622 | /** Get the first child element, or optionally the first child
|
| 623 | element with the specified name.
|
| 624 | */
|
| 625 | const XMLElement* FirstChildElement( const char* value=0 ) const;
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 626 |
|
| 627 | XMLElement* FirstChildElement( const char* value=0 ) {
|
| 628 | return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->FirstChildElement( value ));
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 629 | }
|
Lee Thomason | 3f57d27 | 2012-01-11 15:30:03 -0800 | [diff] [blame] | 630 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 631 | /// Get the last child node, or null if none exists.
|
| 632 | const XMLNode* LastChild() const {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 633 | return _lastChild;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 634 | }
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 635 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 636 | XMLNode* LastChild() {
|
| 637 | return const_cast<XMLNode*>(const_cast<const XMLNode*>(this)->LastChild() );
|
| 638 | }
|
Lee Thomason | 2c85a71 | 2012-01-31 08:24:24 -0800 | [diff] [blame] | 639 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 640 | /** Get the last child element or optionally the last child
|
| 641 | element with the specified name.
|
| 642 | */
|
| 643 | const XMLElement* LastChildElement( const char* value=0 ) const;
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 644 |
|
| 645 | XMLElement* LastChildElement( const char* value=0 ) {
|
| 646 | return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->LastChildElement(value) );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 647 | }
|
Lee Thomason (grinliz) | 2f1f624 | 2012-09-16 11:32:34 -0700 | [diff] [blame] | 648 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 649 | /// Get the previous (left) sibling node of this node.
|
| 650 | const XMLNode* PreviousSibling() const {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 651 | return _prev;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 652 | }
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 653 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 654 | XMLNode* PreviousSibling() {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 655 | return _prev;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 656 | }
|
Lee Thomason | 56bdd02 | 2012-02-09 18:16:58 -0800 | [diff] [blame] | 657 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 658 | /// Get the previous (left) sibling element of this node, with an opitionally supplied name.
|
| 659 | const XMLElement* PreviousSiblingElement( const char* value=0 ) const ;
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 660 |
|
| 661 | XMLElement* PreviousSiblingElement( const char* value=0 ) {
|
| 662 | return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->PreviousSiblingElement( value ) );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 663 | }
|
Lee Thomason (grinliz) | 2f1f624 | 2012-09-16 11:32:34 -0700 | [diff] [blame] | 664 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 665 | /// Get the next (right) sibling node of this node.
|
| 666 | const XMLNode* NextSibling() const {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 667 | return _next;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 668 | }
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 669 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 670 | XMLNode* NextSibling() {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 671 | return _next;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 672 | }
|
Lee Thomason (grinliz) | 2f1f624 | 2012-09-16 11:32:34 -0700 | [diff] [blame] | 673 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 674 | /// Get the next (right) sibling element of this node, with an opitionally supplied name.
|
| 675 | const XMLElement* NextSiblingElement( const char* value=0 ) const;
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 676 |
|
| 677 | XMLElement* NextSiblingElement( const char* value=0 ) {
|
| 678 | return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->NextSiblingElement( value ) );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 679 | }
|
Lee Thomason | 56bdd02 | 2012-02-09 18:16:58 -0800 | [diff] [blame] | 680 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 681 | /**
|
| 682 | Add a child node as the last (right) child.
|
| 683 | */
|
| 684 | XMLNode* InsertEndChild( XMLNode* addThis );
|
Lee Thomason | 618dbf8 | 2012-02-28 12:34:27 -0800 | [diff] [blame] | 685 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 686 | XMLNode* LinkEndChild( XMLNode* addThis ) {
|
| 687 | return InsertEndChild( addThis );
|
| 688 | }
|
| 689 | /**
|
| 690 | Add a child node as the first (left) child.
|
| 691 | */
|
| 692 | XMLNode* InsertFirstChild( XMLNode* addThis );
|
| 693 | /**
|
| 694 | Add a node after the specified child node.
|
| 695 | */
|
| 696 | XMLNode* InsertAfterChild( XMLNode* afterThis, XMLNode* addThis );
|
Lee Thomason (grinliz) | 2f1f624 | 2012-09-16 11:32:34 -0700 | [diff] [blame] | 697 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 698 | /**
|
| 699 | Delete all the children of this node.
|
| 700 | */
|
| 701 | void DeleteChildren();
|
U-Stream\Lee | ae25a44 | 2012-02-17 17:48:16 -0800 | [diff] [blame] | 702 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 703 | /**
|
| 704 | Delete a child of this node.
|
| 705 | */
|
| 706 | void DeleteChild( XMLNode* node );
|
Lee Thomason | 56bdd02 | 2012-02-09 18:16:58 -0800 | [diff] [blame] | 707 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 708 | /**
|
| 709 | Make a copy of this node, but not its children.
|
| 710 | You may pass in a Document pointer that will be
|
| 711 | the owner of the new Node. If the 'document' is
|
| 712 | null, then the node returned will be allocated
|
| 713 | from the current Document. (this->GetDocument())
|
Lee Thomason | 7d00b9a | 2012-02-27 17:54:22 -0800 | [diff] [blame] | 714 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 715 | Note: if called on a XMLDocument, this will return null.
|
| 716 | */
|
| 717 | virtual XMLNode* ShallowClone( XMLDocument* document ) const = 0;
|
Lee Thomason | 7d00b9a | 2012-02-27 17:54:22 -0800 | [diff] [blame] | 718 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 719 | /**
|
| 720 | Test if 2 nodes are the same, but don't test children.
|
| 721 | The 2 nodes do not need to be in the same Document.
|
Lee Thomason | 7d00b9a | 2012-02-27 17:54:22 -0800 | [diff] [blame] | 722 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 723 | Note: if called on a XMLDocument, this will return false.
|
| 724 | */
|
| 725 | virtual bool ShallowEqual( const XMLNode* compare ) const = 0;
|
Lee Thomason | 7d00b9a | 2012-02-27 17:54:22 -0800 | [diff] [blame] | 726 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 727 | /** Accept a hierarchical visit of the nodes in the TinyXML DOM. Every node in the
|
| 728 | XML tree will be conditionally visited and the host will be called back
|
| 729 | via the TiXmlVisitor interface.
|
Lee Thomason (grinliz) | 9c38d13 | 2012-02-24 21:50:50 -0800 | [diff] [blame] | 730 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 731 | This is essentially a SAX interface for TinyXML. (Note however it doesn't re-parse
|
| 732 | the XML for the callbacks, so the performance of TinyXML is unchanged by using this
|
| 733 | interface versus any other.)
|
Lee Thomason (grinliz) | 9c38d13 | 2012-02-24 21:50:50 -0800 | [diff] [blame] | 734 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 735 | The interface has been based on ideas from:
|
Lee Thomason (grinliz) | 9c38d13 | 2012-02-24 21:50:50 -0800 | [diff] [blame] | 736 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 737 | - http://www.saxproject.org/
|
| 738 | - http://c2.com/cgi/wiki?HierarchicalVisitorPattern
|
Lee Thomason (grinliz) | 9c38d13 | 2012-02-24 21:50:50 -0800 | [diff] [blame] | 739 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 740 | Which are both good references for "visiting".
|
Lee Thomason (grinliz) | 9c38d13 | 2012-02-24 21:50:50 -0800 | [diff] [blame] | 741 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 742 | An example of using Accept():
|
| 743 | @verbatim
|
| 744 | TiXmlPrinter printer;
|
| 745 | tinyxmlDoc.Accept( &printer );
|
| 746 | const char* xmlcstr = printer.CStr();
|
| 747 | @endverbatim
|
| 748 | */
|
| 749 | virtual bool Accept( XMLVisitor* visitor ) const = 0;
|
Lee Thomason | 56bdd02 | 2012-02-09 18:16:58 -0800 | [diff] [blame] | 750 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 751 | // internal
|
| 752 | virtual char* ParseDeep( char*, StrPair* );
|
Lee Thomason | 3f57d27 | 2012-01-11 15:30:03 -0800 | [diff] [blame] | 753 |
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 754 | protected:
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 755 | XMLNode( XMLDocument* );
|
| 756 | virtual ~XMLNode();
|
| 757 | XMLNode( const XMLNode& ); // not supported
|
| 758 | XMLNode& operator=( const XMLNode& ); // not supported
|
Lee Thomason (grinliz) | 2f1f624 | 2012-09-16 11:32:34 -0700 | [diff] [blame] | 759 |
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 760 | XMLDocument* _document;
|
| 761 | XMLNode* _parent;
|
| 762 | mutable StrPair _value;
|
Lee Thomason | 3f57d27 | 2012-01-11 15:30:03 -0800 | [diff] [blame] | 763 |
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 764 | XMLNode* _firstChild;
|
| 765 | XMLNode* _lastChild;
|
Lee Thomason | 3f57d27 | 2012-01-11 15:30:03 -0800 | [diff] [blame] | 766 |
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 767 | XMLNode* _prev;
|
| 768 | XMLNode* _next;
|
Lee Thomason | 3f57d27 | 2012-01-11 15:30:03 -0800 | [diff] [blame] | 769 |
|
U-Lama\Lee | 4cee611 | 2011-12-31 14:58:18 -0800 | [diff] [blame] | 770 | private:
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 771 | MemPool* _memPool;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 772 | void Unlink( XMLNode* child );
|
U-Lama\Lee | 4cee611 | 2011-12-31 14:58:18 -0800 | [diff] [blame] | 773 | };
|
| 774 |
|
| 775 |
|
Lee Thomason (grinliz) | 9c38d13 | 2012-02-24 21:50:50 -0800 | [diff] [blame] | 776 | /** XML text.
|
| 777 |
|
| 778 | Note that a text node can have child element nodes, for example:
|
| 779 | @verbatim
|
| 780 | <root>This is <b>bold</b></root>
|
| 781 | @endverbatim
|
| 782 |
|
Lee Thomason (grinliz) | 2f1f624 | 2012-09-16 11:32:34 -0700 | [diff] [blame] | 783 | A text node can have 2 ways to output the next. "normal" output
|
Lee Thomason (grinliz) | 9c38d13 | 2012-02-24 21:50:50 -0800 | [diff] [blame] | 784 | and CDATA. It will default to the mode it was parsed from the XML file and
|
Lee Thomason (grinliz) | 2f1f624 | 2012-09-16 11:32:34 -0700 | [diff] [blame] | 785 | you generally want to leave it alone, but you can change the output mode with
|
Lee Thomason (grinliz) | 9c38d13 | 2012-02-24 21:50:50 -0800 | [diff] [blame] | 786 | SetCDATA() and query it with CDATA().
|
| 787 | */
|
Lee Thomason | 5492a1c | 2012-01-23 15:32:10 -0800 | [diff] [blame] | 788 | class XMLText : public XMLNode
|
| 789 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 790 | friend class XMLBase;
|
| 791 | friend class XMLDocument;
|
Lee Thomason | 5492a1c | 2012-01-23 15:32:10 -0800 | [diff] [blame] | 792 | public:
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 793 | virtual bool Accept( XMLVisitor* visitor ) const;
|
Lee Thomason | 50adb4c | 2012-02-13 15:07:09 -0800 | [diff] [blame] | 794 |
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 795 | virtual XMLText* ToText() {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 796 | return this;
|
| 797 | }
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 798 | virtual const XMLText* ToText() const {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 799 | return this;
|
| 800 | }
|
Lee Thomason | 5492a1c | 2012-01-23 15:32:10 -0800 | [diff] [blame] | 801 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 802 | /// Declare whether this should be CDATA or standard text.
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 803 | void SetCData( bool isCData ) {
|
| 804 | _isCData = isCData;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 805 | }
|
| 806 | /// Returns true if this is a CDATA text element.
|
| 807 | bool CData() const {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 808 | return _isCData;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 809 | }
|
Lee Thomason | 50f97b2 | 2012-02-11 16:33:40 -0800 | [diff] [blame] | 810 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 811 | char* ParseDeep( char*, StrPair* endTag );
|
| 812 | virtual XMLNode* ShallowClone( XMLDocument* document ) const;
|
| 813 | virtual bool ShallowEqual( const XMLNode* compare ) const;
|
Lee Thomason | 7d00b9a | 2012-02-27 17:54:22 -0800 | [diff] [blame] | 814 |
|
Lee Thomason | 5492a1c | 2012-01-23 15:32:10 -0800 | [diff] [blame] | 815 | protected:
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 816 | XMLText( XMLDocument* doc ) : XMLNode( doc ), _isCData( false ) {}
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 817 | virtual ~XMLText() {}
|
| 818 | XMLText( const XMLText& ); // not supported
|
| 819 | XMLText& operator=( const XMLText& ); // not supported
|
Lee Thomason | 5492a1c | 2012-01-23 15:32:10 -0800 | [diff] [blame] | 820 |
|
| 821 | private:
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 822 | bool _isCData;
|
Lee Thomason | 5492a1c | 2012-01-23 15:32:10 -0800 | [diff] [blame] | 823 | };
|
| 824 |
|
| 825 |
|
Lee Thomason (grinliz) | 2a1cd27 | 2012-02-24 17:37:53 -0800 | [diff] [blame] | 826 | /** An XML Comment. */
|
U-Lama\Lee | 4cee611 | 2011-12-31 14:58:18 -0800 | [diff] [blame] | 827 | class XMLComment : public XMLNode
|
| 828 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 829 | friend class XMLDocument;
|
Lee Thomason | 3f57d27 | 2012-01-11 15:30:03 -0800 | [diff] [blame] | 830 | public:
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 831 | virtual XMLComment* ToComment() {
|
| 832 | return this;
|
| 833 | }
|
| 834 | virtual const XMLComment* ToComment() const {
|
| 835 | return this;
|
| 836 | }
|
Lee Thomason | ce0763e | 2012-01-11 15:43:54 -0800 | [diff] [blame] | 837 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 838 | virtual bool Accept( XMLVisitor* visitor ) const;
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 839 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 840 | char* ParseDeep( char*, StrPair* endTag );
|
| 841 | virtual XMLNode* ShallowClone( XMLDocument* document ) const;
|
| 842 | virtual bool ShallowEqual( const XMLNode* compare ) const;
|
Lee Thomason | ce0763e | 2012-01-11 15:43:54 -0800 | [diff] [blame] | 843 |
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 844 | protected:
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 845 | XMLComment( XMLDocument* doc );
|
| 846 | virtual ~XMLComment();
|
| 847 | XMLComment( const XMLComment& ); // not supported
|
| 848 | XMLComment& operator=( const XMLComment& ); // not supported
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 849 |
|
Lee Thomason | 3f57d27 | 2012-01-11 15:30:03 -0800 | [diff] [blame] | 850 | private:
|
U-Lama\Lee | 4cee611 | 2011-12-31 14:58:18 -0800 | [diff] [blame] | 851 | };
|
U-Lama\Lee | e13c3e6 | 2011-12-28 14:36:55 -0800 | [diff] [blame] | 852 |
|
| 853 |
|
Lee Thomason (grinliz) | 9c38d13 | 2012-02-24 21:50:50 -0800 | [diff] [blame] | 854 | /** In correct XML the declaration is the first entry in the file.
|
| 855 | @verbatim
|
| 856 | <?xml version="1.0" standalone="yes"?>
|
| 857 | @endverbatim
|
| 858 |
|
| 859 | TinyXML2 will happily read or write files without a declaration,
|
| 860 | however.
|
| 861 |
|
| 862 | The text of the declaration isn't interpreted. It is parsed
|
| 863 | and written as a string.
|
| 864 | */
|
Lee Thomason | 50f97b2 | 2012-02-11 16:33:40 -0800 | [diff] [blame] | 865 | class XMLDeclaration : public XMLNode
|
| 866 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 867 | friend class XMLDocument;
|
Lee Thomason | 50f97b2 | 2012-02-11 16:33:40 -0800 | [diff] [blame] | 868 | public:
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 869 | virtual XMLDeclaration* ToDeclaration() {
|
| 870 | return this;
|
| 871 | }
|
| 872 | virtual const XMLDeclaration* ToDeclaration() const {
|
| 873 | return this;
|
| 874 | }
|
Lee Thomason | 50f97b2 | 2012-02-11 16:33:40 -0800 | [diff] [blame] | 875 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 876 | virtual bool Accept( XMLVisitor* visitor ) const;
|
Lee Thomason | 50f97b2 | 2012-02-11 16:33:40 -0800 | [diff] [blame] | 877 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 878 | char* ParseDeep( char*, StrPair* endTag );
|
| 879 | virtual XMLNode* ShallowClone( XMLDocument* document ) const;
|
| 880 | virtual bool ShallowEqual( const XMLNode* compare ) const;
|
Lee Thomason | 50f97b2 | 2012-02-11 16:33:40 -0800 | [diff] [blame] | 881 |
|
| 882 | protected:
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 883 | XMLDeclaration( XMLDocument* doc );
|
| 884 | virtual ~XMLDeclaration();
|
| 885 | XMLDeclaration( const XMLDeclaration& ); // not supported
|
| 886 | XMLDeclaration& operator=( const XMLDeclaration& ); // not supported
|
Lee Thomason | 50f97b2 | 2012-02-11 16:33:40 -0800 | [diff] [blame] | 887 | };
|
| 888 |
|
| 889 |
|
Lee Thomason (grinliz) | 9c38d13 | 2012-02-24 21:50:50 -0800 | [diff] [blame] | 890 | /** Any tag that tinyXml doesn't recognize is saved as an
|
| 891 | unknown. It is a tag of text, but should not be modified.
|
| 892 | It will be written back to the XML, unchanged, when the file
|
| 893 | is saved.
|
| 894 |
|
| 895 | DTD tags get thrown into TiXmlUnknowns.
|
| 896 | */
|
Lee Thomason | 50f97b2 | 2012-02-11 16:33:40 -0800 | [diff] [blame] | 897 | class XMLUnknown : public XMLNode
|
| 898 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 899 | friend class XMLDocument;
|
Lee Thomason | 50f97b2 | 2012-02-11 16:33:40 -0800 | [diff] [blame] | 900 | public:
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 901 | virtual XMLUnknown* ToUnknown() {
|
| 902 | return this;
|
| 903 | }
|
| 904 | virtual const XMLUnknown* ToUnknown() const {
|
| 905 | return this;
|
| 906 | }
|
Lee Thomason | 50f97b2 | 2012-02-11 16:33:40 -0800 | [diff] [blame] | 907 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 908 | virtual bool Accept( XMLVisitor* visitor ) const;
|
Lee Thomason | 50f97b2 | 2012-02-11 16:33:40 -0800 | [diff] [blame] | 909 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 910 | char* ParseDeep( char*, StrPair* endTag );
|
| 911 | virtual XMLNode* ShallowClone( XMLDocument* document ) const;
|
| 912 | virtual bool ShallowEqual( const XMLNode* compare ) const;
|
Lee Thomason | 50f97b2 | 2012-02-11 16:33:40 -0800 | [diff] [blame] | 913 |
|
| 914 | protected:
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 915 | XMLUnknown( XMLDocument* doc );
|
| 916 | virtual ~XMLUnknown();
|
| 917 | XMLUnknown( const XMLUnknown& ); // not supported
|
| 918 | XMLUnknown& operator=( const XMLUnknown& ); // not supported
|
Lee Thomason | 50f97b2 | 2012-02-11 16:33:40 -0800 | [diff] [blame] | 919 | };
|
| 920 |
|
| 921 |
|
Lee Thomason | 1ff38e0 | 2012-02-14 18:18:16 -0800 | [diff] [blame] | 922 | enum {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 923 | XML_NO_ERROR = 0,
|
| 924 | XML_SUCCESS = 0,
|
Lee Thomason (grinliz) | 68db57e | 2012-02-21 09:08:12 -0800 | [diff] [blame] | 925 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 926 | XML_NO_ATTRIBUTE,
|
| 927 | XML_WRONG_ATTRIBUTE_TYPE,
|
Lee Thomason (grinliz) | 68db57e | 2012-02-21 09:08:12 -0800 | [diff] [blame] | 928 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 929 | XML_ERROR_FILE_NOT_FOUND,
|
| 930 | XML_ERROR_FILE_COULD_NOT_BE_OPENED,
|
| 931 | XML_ERROR_FILE_READ_ERROR,
|
| 932 | XML_ERROR_ELEMENT_MISMATCH,
|
| 933 | XML_ERROR_PARSING_ELEMENT,
|
| 934 | XML_ERROR_PARSING_ATTRIBUTE,
|
| 935 | XML_ERROR_IDENTIFYING_TAG,
|
| 936 | XML_ERROR_PARSING_TEXT,
|
| 937 | XML_ERROR_PARSING_CDATA,
|
| 938 | XML_ERROR_PARSING_COMMENT,
|
| 939 | XML_ERROR_PARSING_DECLARATION,
|
| 940 | XML_ERROR_PARSING_UNKNOWN,
|
| 941 | XML_ERROR_EMPTY_DOCUMENT,
|
| 942 | XML_ERROR_MISMATCHED_ELEMENT,
|
| 943 | XML_ERROR_PARSING,
|
Lee Thomason | 21be882 | 2012-07-15 17:27:22 -0700 | [diff] [blame] | 944 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 945 | XML_CAN_NOT_CONVERT_TEXT,
|
| 946 | XML_NO_TEXT_NODE
|
Lee Thomason | 1ff38e0 | 2012-02-14 18:18:16 -0800 | [diff] [blame] | 947 | };
|
| 948 |
|
| 949 |
|
Lee Thomason (grinliz) | 9c38d13 | 2012-02-24 21:50:50 -0800 | [diff] [blame] | 950 | /** An attribute is a name-value pair. Elements have an arbitrary
|
| 951 | number of attributes, each with a unique name.
|
| 952 |
|
| 953 | @note The attributes are not XMLNodes. You may only query the
|
| 954 | Next() attribute in a list.
|
| 955 | */
|
Lee Thomason | 56bdd02 | 2012-02-09 18:16:58 -0800 | [diff] [blame] | 956 | class XMLAttribute
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 957 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 958 | friend class XMLElement;
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 959 | public:
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 960 | const char* Name() const {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 961 | return _name.GetStr(); ///< The name of the attribute.
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 962 | }
|
| 963 | const char* Value() const {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 964 | return _value.GetStr(); ///< The value of the attribute.
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 965 | }
|
| 966 | const XMLAttribute* Next() const {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 967 | return _next; ///< The next attribute in the list.
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 968 | }
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 969 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 970 | /** IntAttribute interprets the attribute as an integer, and returns the value.
|
| 971 | If the value isn't an integer, 0 will be returned. There is no error checking;
|
| 972 | use QueryIntAttribute() if you need error checking.
|
| 973 | */
|
| 974 | int IntValue() const {
|
| 975 | int i=0;
|
| 976 | QueryIntValue( &i );
|
| 977 | return i;
|
| 978 | }
|
| 979 | /// Query as an unsigned integer. See IntAttribute()
|
| 980 | unsigned UnsignedValue() const {
|
| 981 | unsigned i=0;
|
| 982 | QueryUnsignedValue( &i );
|
| 983 | return i;
|
| 984 | }
|
| 985 | /// Query as a boolean. See IntAttribute()
|
| 986 | bool BoolValue() const {
|
| 987 | bool b=false;
|
| 988 | QueryBoolValue( &b );
|
| 989 | return b;
|
| 990 | }
|
| 991 | /// Query as a double. See IntAttribute()
|
| 992 | double DoubleValue() const {
|
| 993 | double d=0;
|
| 994 | QueryDoubleValue( &d );
|
| 995 | return d;
|
| 996 | }
|
| 997 | /// Query as a float. See IntAttribute()
|
| 998 | float FloatValue() const {
|
| 999 | float f=0;
|
| 1000 | QueryFloatValue( &f );
|
| 1001 | return f;
|
| 1002 | }
|
U-Stream\Lee | ae25a44 | 2012-02-17 17:48:16 -0800 | [diff] [blame] | 1003 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1004 | /** QueryIntAttribute interprets the attribute as an integer, and returns the value
|
| 1005 | in the provided paremeter. The function will return XML_NO_ERROR on success,
|
| 1006 | and XML_WRONG_ATTRIBUTE_TYPE if the conversion is not successful.
|
| 1007 | */
|
| 1008 | int QueryIntValue( int* value ) const;
|
| 1009 | /// See QueryIntAttribute
|
| 1010 | int QueryUnsignedValue( unsigned int* value ) const;
|
| 1011 | /// See QueryIntAttribute
|
| 1012 | int QueryBoolValue( bool* value ) const;
|
| 1013 | /// See QueryIntAttribute
|
| 1014 | int QueryDoubleValue( double* value ) const;
|
| 1015 | /// See QueryIntAttribute
|
| 1016 | int QueryFloatValue( float* value ) const;
|
Lee Thomason | 50adb4c | 2012-02-13 15:07:09 -0800 | [diff] [blame] | 1017 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1018 | /// Set the attribute to a string value.
|
| 1019 | void SetAttribute( const char* value );
|
| 1020 | /// Set the attribute to value.
|
| 1021 | void SetAttribute( int value );
|
| 1022 | /// Set the attribute to value.
|
| 1023 | void SetAttribute( unsigned value );
|
| 1024 | /// Set the attribute to value.
|
| 1025 | void SetAttribute( bool value );
|
| 1026 | /// Set the attribute to value.
|
| 1027 | void SetAttribute( double value );
|
| 1028 | /// Set the attribute to value.
|
| 1029 | void SetAttribute( float value );
|
Lee Thomason | 50adb4c | 2012-02-13 15:07:09 -0800 | [diff] [blame] | 1030 |
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 1031 | private:
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1032 | enum { BUF_SIZE = 200 };
|
U-Stream\Lee | 09a11c5 | 2012-02-17 08:31:16 -0800 | [diff] [blame] | 1033 |
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1034 | XMLAttribute() : _next( 0 ) {}
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1035 | virtual ~XMLAttribute() {}
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1036 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1037 | XMLAttribute( const XMLAttribute& ); // not supported
|
| 1038 | void operator=( const XMLAttribute& ); // not supported
|
| 1039 | void SetName( const char* name );
|
Lee Thomason | 50adb4c | 2012-02-13 15:07:09 -0800 | [diff] [blame] | 1040 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1041 | char* ParseDeep( char* p, bool processEntities );
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 1042 |
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1043 | mutable StrPair _name;
|
| 1044 | mutable StrPair _value;
|
| 1045 | XMLAttribute* _next;
|
| 1046 | MemPool* _memPool;
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 1047 | };
|
| 1048 |
|
| 1049 |
|
Lee Thomason (grinliz) | 9c38d13 | 2012-02-24 21:50:50 -0800 | [diff] [blame] | 1050 | /** The element is a container class. It has a value, the element name,
|
| 1051 | and can contain other elements, text, comments, and unknowns.
|
| 1052 | Elements also contain an arbitrary number of attributes.
|
| 1053 | */
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 1054 | class XMLElement : public XMLNode
|
| 1055 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1056 | friend class XMLBase;
|
| 1057 | friend class XMLDocument;
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 1058 | public:
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1059 | /// Get the name of an element (which is the Value() of the node.)
|
| 1060 | const char* Name() const {
|
| 1061 | return Value();
|
| 1062 | }
|
| 1063 | /// Set the name of the element.
|
| 1064 | void SetName( const char* str, bool staticMem=false ) {
|
| 1065 | SetValue( str, staticMem );
|
| 1066 | }
|
Lee Thomason | 2c85a71 | 2012-01-31 08:24:24 -0800 | [diff] [blame] | 1067 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1068 | virtual XMLElement* ToElement() {
|
| 1069 | return this;
|
| 1070 | }
|
| 1071 | virtual const XMLElement* ToElement() const {
|
| 1072 | return this;
|
| 1073 | }
|
| 1074 | virtual bool Accept( XMLVisitor* visitor ) const;
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 1075 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1076 | /** Given an attribute name, Attribute() returns the value
|
| 1077 | for the attribute of that name, or null if none
|
| 1078 | exists. For example:
|
Lee Thomason | 9225815 | 2012-03-24 13:05:39 -0700 | [diff] [blame] | 1079 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1080 | @verbatim
|
| 1081 | const char* value = ele->Attribute( "foo" );
|
| 1082 | @endverbatim
|
Lee Thomason | 9225815 | 2012-03-24 13:05:39 -0700 | [diff] [blame] | 1083 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1084 | The 'value' parameter is normally null. However, if specified,
|
| 1085 | the attribute will only be returned if the 'name' and 'value'
|
| 1086 | match. This allow you to write code:
|
Lee Thomason | 8ba7f7d | 2012-03-24 13:04:04 -0700 | [diff] [blame] | 1087 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1088 | @verbatim
|
| 1089 | if ( ele->Attribute( "foo", "bar" ) ) callFooIsBar();
|
| 1090 | @endverbatim
|
Lee Thomason | 8ba7f7d | 2012-03-24 13:04:04 -0700 | [diff] [blame] | 1091 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1092 | rather than:
|
| 1093 | @verbatim
|
| 1094 | if ( ele->Attribute( "foo" ) ) {
|
| 1095 | if ( strcmp( ele->Attribute( "foo" ), "bar" ) == 0 ) callFooIsBar();
|
| 1096 | }
|
| 1097 | @endverbatim
|
| 1098 | */
|
| 1099 | const char* Attribute( const char* name, const char* value=0 ) const;
|
Lee Thomason | 751da52 | 2012-02-10 08:50:51 -0800 | [diff] [blame] | 1100 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1101 | /** Given an attribute name, IntAttribute() returns the value
|
| 1102 | of the attribute interpreted as an integer. 0 will be
|
| 1103 | returned if there is an error. For a method with error
|
| 1104 | checking, see QueryIntAttribute()
|
| 1105 | */
|
| 1106 | int IntAttribute( const char* name ) const {
|
| 1107 | int i=0;
|
| 1108 | QueryIntAttribute( name, &i );
|
| 1109 | return i;
|
| 1110 | }
|
| 1111 | /// See IntAttribute()
|
| 1112 | unsigned UnsignedAttribute( const char* name ) const {
|
| 1113 | unsigned i=0;
|
| 1114 | QueryUnsignedAttribute( name, &i );
|
| 1115 | return i;
|
| 1116 | }
|
| 1117 | /// See IntAttribute()
|
| 1118 | bool BoolAttribute( const char* name ) const {
|
| 1119 | bool b=false;
|
| 1120 | QueryBoolAttribute( name, &b );
|
| 1121 | return b;
|
| 1122 | }
|
| 1123 | /// See IntAttribute()
|
| 1124 | double DoubleAttribute( const char* name ) const {
|
| 1125 | double d=0;
|
| 1126 | QueryDoubleAttribute( name, &d );
|
| 1127 | return d;
|
| 1128 | }
|
| 1129 | /// See IntAttribute()
|
| 1130 | float FloatAttribute( const char* name ) const {
|
| 1131 | float f=0;
|
| 1132 | QueryFloatAttribute( name, &f );
|
| 1133 | return f;
|
| 1134 | }
|
U-Stream\Lee | 09a11c5 | 2012-02-17 08:31:16 -0800 | [diff] [blame] | 1135 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1136 | /** Given an attribute name, QueryIntAttribute() returns
|
| 1137 | XML_NO_ERROR, XML_WRONG_ATTRIBUTE_TYPE if the conversion
|
| 1138 | can't be performed, or XML_NO_ATTRIBUTE if the attribute
|
| 1139 | doesn't exist. If successful, the result of the conversion
|
| 1140 | will be written to 'value'. If not successful, nothing will
|
| 1141 | be written to 'value'. This allows you to provide default
|
| 1142 | value:
|
Lee Thomason (grinliz) | 9c38d13 | 2012-02-24 21:50:50 -0800 | [diff] [blame] | 1143 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1144 | @verbatim
|
| 1145 | int value = 10;
|
| 1146 | QueryIntAttribute( "foo", &value ); // if "foo" isn't found, value will still be 10
|
| 1147 | @endverbatim
|
| 1148 | */
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1149 | int QueryIntAttribute( const char* name, int* value ) const {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1150 | const XMLAttribute* a = FindAttribute( name );
|
| 1151 | if ( !a ) {
|
| 1152 | return XML_NO_ATTRIBUTE;
|
| 1153 | }
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1154 | return a->QueryIntValue( value );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1155 | }
|
| 1156 | /// See QueryIntAttribute()
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1157 | int QueryUnsignedAttribute( const char* name, unsigned int* value ) const {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1158 | const XMLAttribute* a = FindAttribute( name );
|
| 1159 | if ( !a ) {
|
| 1160 | return XML_NO_ATTRIBUTE;
|
| 1161 | }
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1162 | return a->QueryUnsignedValue( value );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1163 | }
|
| 1164 | /// See QueryIntAttribute()
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1165 | int QueryBoolAttribute( const char* name, bool* value ) const {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1166 | const XMLAttribute* a = FindAttribute( name );
|
| 1167 | if ( !a ) {
|
| 1168 | return XML_NO_ATTRIBUTE;
|
| 1169 | }
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1170 | return a->QueryBoolValue( value );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1171 | }
|
| 1172 | /// See QueryIntAttribute()
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1173 | int QueryDoubleAttribute( const char* name, double* value ) const {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1174 | const XMLAttribute* a = FindAttribute( name );
|
| 1175 | if ( !a ) {
|
| 1176 | return XML_NO_ATTRIBUTE;
|
| 1177 | }
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1178 | return a->QueryDoubleValue( value );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1179 | }
|
| 1180 | /// See QueryIntAttribute()
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1181 | int QueryFloatAttribute( const char* name, float* value ) const {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1182 | const XMLAttribute* a = FindAttribute( name );
|
| 1183 | if ( !a ) {
|
| 1184 | return XML_NO_ATTRIBUTE;
|
| 1185 | }
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1186 | return a->QueryFloatValue( value );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1187 | }
|
Lee Thomason | 50f97b2 | 2012-02-11 16:33:40 -0800 | [diff] [blame] | 1188 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1189 | /// Sets the named attribute to value.
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1190 | void SetAttribute( const char* name, const char* value ) {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1191 | XMLAttribute* a = FindOrCreateAttribute( name );
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1192 | a->SetAttribute( value );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1193 | }
|
| 1194 | /// Sets the named attribute to value.
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1195 | void SetAttribute( const char* name, int value ) {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1196 | XMLAttribute* a = FindOrCreateAttribute( name );
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1197 | a->SetAttribute( value );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1198 | }
|
| 1199 | /// Sets the named attribute to value.
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1200 | void SetAttribute( const char* name, unsigned value ) {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1201 | XMLAttribute* a = FindOrCreateAttribute( name );
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1202 | a->SetAttribute( value );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1203 | }
|
| 1204 | /// Sets the named attribute to value.
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1205 | void SetAttribute( const char* name, bool value ) {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1206 | XMLAttribute* a = FindOrCreateAttribute( name );
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1207 | a->SetAttribute( value );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1208 | }
|
| 1209 | /// Sets the named attribute to value.
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1210 | void SetAttribute( const char* name, double value ) {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1211 | XMLAttribute* a = FindOrCreateAttribute( name );
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1212 | a->SetAttribute( value );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1213 | }
|
Lee Thomason | 50f97b2 | 2012-02-11 16:33:40 -0800 | [diff] [blame] | 1214 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1215 | /**
|
| 1216 | Delete an attribute.
|
| 1217 | */
|
| 1218 | void DeleteAttribute( const char* name );
|
Lee Thomason | 751da52 | 2012-02-10 08:50:51 -0800 | [diff] [blame] | 1219 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1220 | /// Return the first attribute in the list.
|
| 1221 | const XMLAttribute* FirstAttribute() const {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1222 | return _rootAttribute;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1223 | }
|
| 1224 | /// Query a specific attribute in the list.
|
| 1225 | const XMLAttribute* FindAttribute( const char* name ) const;
|
Lee Thomason | 751da52 | 2012-02-10 08:50:51 -0800 | [diff] [blame] | 1226 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1227 | /** Convenience function for easy access to the text inside an element. Although easy
|
| 1228 | and concise, GetText() is limited compared to getting the TiXmlText child
|
| 1229 | and accessing it directly.
|
Lee Thomason (grinliz) | 2f1f624 | 2012-09-16 11:32:34 -0700 | [diff] [blame] | 1230 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1231 | If the first child of 'this' is a TiXmlText, the GetText()
|
| 1232 | returns the character string of the Text node, else null is returned.
|
Lee Thomason (grinliz) | 9c38d13 | 2012-02-24 21:50:50 -0800 | [diff] [blame] | 1233 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1234 | This is a convenient method for getting the text of simple contained text:
|
| 1235 | @verbatim
|
| 1236 | <foo>This is text</foo>
|
| 1237 | const char* str = fooElement->GetText();
|
| 1238 | @endverbatim
|
Lee Thomason (grinliz) | 9c38d13 | 2012-02-24 21:50:50 -0800 | [diff] [blame] | 1239 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1240 | 'str' will be a pointer to "This is text".
|
Lee Thomason (grinliz) | 2f1f624 | 2012-09-16 11:32:34 -0700 | [diff] [blame] | 1241 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1242 | Note that this function can be misleading. If the element foo was created from
|
| 1243 | this XML:
|
| 1244 | @verbatim
|
| 1245 | <foo><b>This is text</b></foo>
|
| 1246 | @endverbatim
|
Lee Thomason (grinliz) | 9c38d13 | 2012-02-24 21:50:50 -0800 | [diff] [blame] | 1247 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1248 | then the value of str would be null. The first child node isn't a text node, it is
|
| 1249 | another element. From this XML:
|
| 1250 | @verbatim
|
| 1251 | <foo>This is <b>text</b></foo>
|
| 1252 | @endverbatim
|
| 1253 | GetText() will return "This is ".
|
| 1254 | */
|
| 1255 | const char* GetText() const;
|
Lee Thomason | 751da52 | 2012-02-10 08:50:51 -0800 | [diff] [blame] | 1256 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1257 | /**
|
| 1258 | Convenience method to query the value of a child text node. This is probably best
|
| 1259 | shown by example. Given you have a document is this form:
|
| 1260 | @verbatim
|
| 1261 | <point>
|
| 1262 | <x>1</x>
|
| 1263 | <y>1.4</y>
|
| 1264 | </point>
|
| 1265 | @endverbatim
|
Lee Thomason | 21be882 | 2012-07-15 17:27:22 -0700 | [diff] [blame] | 1266 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1267 | The QueryIntText() and similar functions provide a safe and easier way to get to the
|
| 1268 | "value" of x and y.
|
Lee Thomason | 21be882 | 2012-07-15 17:27:22 -0700 | [diff] [blame] | 1269 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1270 | @verbatim
|
| 1271 | int x = 0;
|
| 1272 | float y = 0; // types of x and y are contrived for example
|
| 1273 | const XMLElement* xElement = pointElement->FirstChildElement( "x" );
|
| 1274 | const XMLElement* yElement = pointElement->FirstChildElement( "y" );
|
| 1275 | xElement->QueryIntText( &x );
|
| 1276 | yElement->QueryFloatText( &y );
|
| 1277 | @endverbatim
|
Lee Thomason | 21be882 | 2012-07-15 17:27:22 -0700 | [diff] [blame] | 1278 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1279 | @returns XML_SUCCESS (0) on success, XML_CAN_NOT_CONVERT_TEXT if the text cannot be converted
|
| 1280 | to the requested type, and XML_NO_TEXT_NODE if there is no child text to query.
|
Lee Thomason (grinliz) | 2f1f624 | 2012-09-16 11:32:34 -0700 | [diff] [blame] | 1281 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1282 | */
|
| 1283 | int QueryIntText( int* _value ) const;
|
| 1284 | /// See QueryIntText()
|
| 1285 | int QueryUnsignedText( unsigned* _value ) const;
|
| 1286 | /// See QueryIntText()
|
| 1287 | int QueryBoolText( bool* _value ) const;
|
| 1288 | /// See QueryIntText()
|
| 1289 | int QueryDoubleText( double* _value ) const;
|
| 1290 | /// See QueryIntText()
|
| 1291 | int QueryFloatText( float* _value ) const;
|
Lee Thomason | 21be882 | 2012-07-15 17:27:22 -0700 | [diff] [blame] | 1292 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1293 | // internal:
|
| 1294 | enum {
|
| 1295 | OPEN, // <foo>
|
| 1296 | CLOSED, // <foo/>
|
| 1297 | CLOSING // </foo>
|
| 1298 | };
|
| 1299 | int ClosingType() const {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1300 | return _closingType;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1301 | }
|
| 1302 | char* ParseDeep( char* p, StrPair* endTag );
|
| 1303 | virtual XMLNode* ShallowClone( XMLDocument* document ) const;
|
| 1304 | virtual bool ShallowEqual( const XMLNode* compare ) const;
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 1305 |
|
Lee Thomason | 50adb4c | 2012-02-13 15:07:09 -0800 | [diff] [blame] | 1306 | private:
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1307 | XMLElement( XMLDocument* doc );
|
| 1308 | virtual ~XMLElement();
|
| 1309 | XMLElement( const XMLElement& ); // not supported
|
| 1310 | void operator=( const XMLElement& ); // not supported
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 1311 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1312 | XMLAttribute* FindAttribute( const char* name );
|
| 1313 | XMLAttribute* FindOrCreateAttribute( const char* name );
|
| 1314 | //void LinkAttribute( XMLAttribute* attrib );
|
| 1315 | char* ParseAttributes( char* p );
|
Lee Thomason | 67d6131 | 2012-01-24 16:01:51 -0800 | [diff] [blame] | 1316 |
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1317 | int _closingType;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1318 | // The attribute list is ordered; there is no 'lastAttribute'
|
| 1319 | // because the list needs to be scanned for dupes before adding
|
| 1320 | // a new attribute.
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1321 | XMLAttribute* _rootAttribute;
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 1322 | };
|
| 1323 |
|
| 1324 |
|
Lee Thomason (grinliz) | bc1bfb7 | 2012-08-20 22:00:38 -0700 | [diff] [blame] | 1325 | enum Whitespace {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1326 | PRESERVE_WHITESPACE,
|
| 1327 | COLLAPSE_WHITESPACE
|
Lee Thomason (grinliz) | 2f1f624 | 2012-09-16 11:32:34 -0700 | [diff] [blame] | 1328 | };
|
Lee Thomason (grinliz) | bc1bfb7 | 2012-08-20 22:00:38 -0700 | [diff] [blame] | 1329 |
|
Lee Thomason (grinliz) | 2f1f624 | 2012-09-16 11:32:34 -0700 | [diff] [blame] | 1330 |
|
| 1331 | /** A Document binds together all the functionality.
|
Lee Thomason (grinliz) | 9c38d13 | 2012-02-24 21:50:50 -0800 | [diff] [blame] | 1332 | It can be saved, loaded, and printed to the screen.
|
| 1333 | All Nodes are connected and allocated to a Document.
|
| 1334 | If the Document is deleted, all its Nodes are also deleted.
|
| 1335 | */
|
Lee Thomason | 67d6131 | 2012-01-24 16:01:51 -0800 | [diff] [blame] | 1336 | class XMLDocument : public XMLNode
|
U-Lama\Lee | e13c3e6 | 2011-12-28 14:36:55 -0800 | [diff] [blame] | 1337 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1338 | friend class XMLElement;
|
U-Lama\Lee | e13c3e6 | 2011-12-28 14:36:55 -0800 | [diff] [blame] | 1339 | public:
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1340 | /// constructor
|
| 1341 | XMLDocument( bool processEntities = true, Whitespace = PRESERVE_WHITESPACE );
|
| 1342 | ~XMLDocument();
|
U-Lama\Lee | e13c3e6 | 2011-12-28 14:36:55 -0800 | [diff] [blame] | 1343 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1344 | virtual XMLDocument* ToDocument() {
|
| 1345 | return this;
|
| 1346 | }
|
| 1347 | virtual const XMLDocument* ToDocument() const {
|
| 1348 | return this;
|
| 1349 | }
|
Lee Thomason | 56bdd02 | 2012-02-09 18:16:58 -0800 | [diff] [blame] | 1350 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1351 | /**
|
| 1352 | Parse an XML file from a character string.
|
| 1353 | Returns XML_NO_ERROR (0) on success, or
|
| 1354 | an errorID.
|
Lee Thomason (grinliz) | e2bcb32 | 2012-09-17 17:58:25 -0700 | [diff] [blame] | 1355 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1356 | You may optionally pass in the 'nBytes', which is
|
| 1357 | the number of bytes which will be parsed. If not
|
| 1358 | specified, TinyXML will assume 'xml' points to a
|
| 1359 | null terminated string.
|
| 1360 | */
|
| 1361 | int Parse( const char* xml, size_t nBytes=(size_t)(-1) );
|
Lee Thomason (grinliz) | 2f1f624 | 2012-09-16 11:32:34 -0700 | [diff] [blame] | 1362 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1363 | /**
|
| 1364 | Load an XML file from disk.
|
| 1365 | Returns XML_NO_ERROR (0) on success, or
|
| 1366 | an errorID.
|
| 1367 | */
|
| 1368 | int LoadFile( const char* filename );
|
Lee Thomason (grinliz) | 2f1f624 | 2012-09-16 11:32:34 -0700 | [diff] [blame] | 1369 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1370 | /**
|
| 1371 | Load an XML file from disk. You are responsible
|
| 1372 | for providing and closing the FILE*.
|
Lee Thomason (grinliz) | 2a1cd27 | 2012-02-24 17:37:53 -0800 | [diff] [blame] | 1373 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1374 | Returns XML_NO_ERROR (0) on success, or
|
| 1375 | an errorID.
|
| 1376 | */
|
Jerome Martinez | 7fbefab | 2012-10-19 11:30:33 +0200 | [diff] [blame] | 1377 | int LoadFile( std::FILE* );
|
Lee Thomason (grinliz) | 2f1f624 | 2012-09-16 11:32:34 -0700 | [diff] [blame] | 1378 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1379 | /**
|
| 1380 | Save the XML file to disk.
|
| 1381 | Returns XML_NO_ERROR (0) on success, or
|
| 1382 | an errorID.
|
| 1383 | */
|
| 1384 | int SaveFile( const char* filename, bool compact = false );
|
Lee Thomason | d11cd16 | 2012-04-12 08:35:36 -0700 | [diff] [blame] | 1385 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1386 | /**
|
| 1387 | Save the XML file to disk. You are responsible
|
| 1388 | for providing and closing the FILE*.
|
Ken Miller | 81da1fb | 2012-04-09 23:32:26 -0500 | [diff] [blame] | 1389 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1390 | Returns XML_NO_ERROR (0) on success, or
|
| 1391 | an errorID.
|
| 1392 | */
|
Jerome Martinez | 7fbefab | 2012-10-19 11:30:33 +0200 | [diff] [blame] | 1393 | int SaveFile( std::FILE* fp, bool compact = false );
|
Lee Thomason (grinliz) | 68db57e | 2012-02-21 09:08:12 -0800 | [diff] [blame] | 1394 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1395 | bool ProcessEntities() const {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1396 | return _processEntities;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1397 | }
|
| 1398 | Whitespace WhitespaceMode() const {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1399 | return _whitespace;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1400 | }
|
Lee Thomason | 6f381b7 | 2012-03-02 12:59:39 -0800 | [diff] [blame] | 1401 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1402 | /**
|
| 1403 | Returns true if this document has a leading Byte Order Mark of UTF8.
|
| 1404 | */
|
| 1405 | bool HasBOM() const {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1406 | return _writeBOM;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1407 | }
|
| 1408 | /** Sets whether to write the BOM when writing the file.
|
| 1409 | */
|
| 1410 | void SetBOM( bool useBOM ) {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1411 | _writeBOM = useBOM;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1412 | }
|
Lee Thomason (grinliz) | 2a1cd27 | 2012-02-24 17:37:53 -0800 | [diff] [blame] | 1413 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1414 | /** Return the root element of DOM. Equivalent to FirstChildElement().
|
| 1415 | To get the first node, use FirstChild().
|
| 1416 | */
|
| 1417 | XMLElement* RootElement() {
|
| 1418 | return FirstChildElement();
|
| 1419 | }
|
| 1420 | const XMLElement* RootElement() const {
|
| 1421 | return FirstChildElement();
|
| 1422 | }
|
Lee Thomason | 18d68bd | 2012-01-26 18:17:26 -0800 | [diff] [blame] | 1423 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1424 | /** Print the Document. If the Printer is not provided, it will
|
| 1425 | print to stdout. If you provide Printer, this can print to a file:
|
| 1426 | @verbatim
|
| 1427 | XMLPrinter printer( fp );
|
| 1428 | doc.Print( &printer );
|
| 1429 | @endverbatim
|
Lee Thomason (grinliz) | 2a1cd27 | 2012-02-24 17:37:53 -0800 | [diff] [blame] | 1430 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1431 | Or you can use a printer to print to memory:
|
| 1432 | @verbatim
|
| 1433 | XMLPrinter printer;
|
| 1434 | doc->Print( &printer );
|
| 1435 | // printer.CStr() has a const char* to the XML
|
| 1436 | @endverbatim
|
| 1437 | */
|
| 1438 | void Print( XMLPrinter* streamer=0 );
|
| 1439 | virtual bool Accept( XMLVisitor* visitor ) const;
|
U-Lama\Lee | e13c3e6 | 2011-12-28 14:36:55 -0800 | [diff] [blame] | 1440 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1441 | /**
|
| 1442 | Create a new Element associated with
|
| 1443 | this Document. The memory for the Element
|
| 1444 | is managed by the Document.
|
| 1445 | */
|
| 1446 | XMLElement* NewElement( const char* name );
|
| 1447 | /**
|
| 1448 | Create a new Comment associated with
|
| 1449 | this Document. The memory for the Comment
|
| 1450 | is managed by the Document.
|
| 1451 | */
|
| 1452 | XMLComment* NewComment( const char* comment );
|
| 1453 | /**
|
| 1454 | Create a new Text associated with
|
| 1455 | this Document. The memory for the Text
|
| 1456 | is managed by the Document.
|
| 1457 | */
|
| 1458 | XMLText* NewText( const char* text );
|
| 1459 | /**
|
| 1460 | Create a new Declaration associated with
|
| 1461 | this Document. The memory for the object
|
| 1462 | is managed by the Document.
|
Lee Thomason | f68c438 | 2012-04-28 14:37:11 -0700 | [diff] [blame] | 1463 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1464 | If the 'text' param is null, the standard
|
| 1465 | declaration is used.:
|
| 1466 | @verbatim
|
| 1467 | <?xml version="1.0" encoding="UTF-8"?>
|
| 1468 | @endverbatim
|
| 1469 | */
|
| 1470 | XMLDeclaration* NewDeclaration( const char* text=0 );
|
| 1471 | /**
|
| 1472 | Create a new Unknown associated with
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1473 | this Document. The memory forthe object
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1474 | is managed by the Document.
|
| 1475 | */
|
| 1476 | XMLUnknown* NewUnknown( const char* text );
|
Lee Thomason | 2c85a71 | 2012-01-31 08:24:24 -0800 | [diff] [blame] | 1477 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1478 | /**
|
| 1479 | Delete a node associated with this document.
|
| 1480 | It will be unlinked from the DOM.
|
| 1481 | */
|
| 1482 | void DeleteNode( XMLNode* node ) {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1483 | node->_parent->DeleteChild( node );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1484 | }
|
U-Stream\Lee | ae25a44 | 2012-02-17 17:48:16 -0800 | [diff] [blame] | 1485 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1486 | void SetError( int error, const char* str1, const char* str2 );
|
Lee Thomason (grinliz) | 2f1f624 | 2012-09-16 11:32:34 -0700 | [diff] [blame] | 1487 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1488 | /// Return true if there was an error parsing the document.
|
| 1489 | bool Error() const {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1490 | return _errorID != XML_NO_ERROR;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1491 | }
|
| 1492 | /// Return the errorID.
|
| 1493 | int ErrorID() const {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1494 | return _errorID;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1495 | }
|
| 1496 | /// Return a possibly helpful diagnostic location or string.
|
| 1497 | const char* GetErrorStr1() const {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1498 | return _errorStr1;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1499 | }
|
| 1500 | /// Return a possibly helpful secondary diagnostic location or string.
|
| 1501 | const char* GetErrorStr2() const {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1502 | return _errorStr2;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1503 | }
|
| 1504 | /// If there is an error, print it to stdout.
|
| 1505 | void PrintError() const;
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 1506 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1507 | // internal
|
| 1508 | char* Identify( char* p, XMLNode** node );
|
Lee Thomason | 2c85a71 | 2012-01-31 08:24:24 -0800 | [diff] [blame] | 1509 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1510 | virtual XMLNode* ShallowClone( XMLDocument* /*document*/ ) const {
|
| 1511 | return 0;
|
| 1512 | }
|
| 1513 | virtual bool ShallowEqual( const XMLNode* /*compare*/ ) const {
|
| 1514 | return false;
|
| 1515 | }
|
Lee Thomason | 7d00b9a | 2012-02-27 17:54:22 -0800 | [diff] [blame] | 1516 |
|
Lee Thomason | 3f57d27 | 2012-01-11 15:30:03 -0800 | [diff] [blame] | 1517 | private:
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1518 | XMLDocument( const XMLDocument& ); // not supported
|
| 1519 | void operator=( const XMLDocument& ); // not supported
|
| 1520 | void InitDocument();
|
Lee Thomason | 18d68bd | 2012-01-26 18:17:26 -0800 | [diff] [blame] | 1521 |
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1522 | bool _writeBOM;
|
| 1523 | bool _processEntities;
|
| 1524 | int _errorID;
|
| 1525 | Whitespace _whitespace;
|
| 1526 | const char* _errorStr1;
|
| 1527 | const char* _errorStr2;
|
| 1528 | char* _charBuffer;
|
Lee Thomason | d198322 | 2012-02-06 08:41:24 -0800 | [diff] [blame] | 1529 |
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1530 | MemPoolT< sizeof(XMLElement) > _elementPool;
|
| 1531 | MemPoolT< sizeof(XMLAttribute) > _attributePool;
|
| 1532 | MemPoolT< sizeof(XMLText) > _textPool;
|
| 1533 | MemPoolT< sizeof(XMLComment) > _commentPool;
|
Lee Thomason | 5cae897 | 2012-01-24 18:03:07 -0800 | [diff] [blame] | 1534 | };
|
| 1535 |
|
Lee Thomason | 7c913cd | 2012-01-26 18:32:34 -0800 | [diff] [blame] | 1536 |
|
Lee Thomason | 3ffdd39 | 2012-03-28 17:27:55 -0700 | [diff] [blame] | 1537 | /**
|
| 1538 | A XMLHandle is a class that wraps a node pointer with null checks; this is
|
Lee Thomason (grinliz) | ae209f6 | 2012-04-04 22:00:07 -0700 | [diff] [blame] | 1539 | an incredibly useful thing. Note that XMLHandle is not part of the TinyXML
|
Lee Thomason | 3ffdd39 | 2012-03-28 17:27:55 -0700 | [diff] [blame] | 1540 | DOM structure. It is a separate utility class.
|
| 1541 |
|
| 1542 | Take an example:
|
| 1543 | @verbatim
|
| 1544 | <Document>
|
| 1545 | <Element attributeA = "valueA">
|
| 1546 | <Child attributeB = "value1" />
|
| 1547 | <Child attributeB = "value2" />
|
| 1548 | </Element>
|
Thomas Roß | 08bdf50 | 2012-05-12 14:21:23 +0200 | [diff] [blame] | 1549 | </Document>
|
Lee Thomason | 3ffdd39 | 2012-03-28 17:27:55 -0700 | [diff] [blame] | 1550 | @endverbatim
|
| 1551 |
|
Lee Thomason (grinliz) | 2f1f624 | 2012-09-16 11:32:34 -0700 | [diff] [blame] | 1552 | Assuming you want the value of "attributeB" in the 2nd "Child" element, it's very
|
Lee Thomason | 3ffdd39 | 2012-03-28 17:27:55 -0700 | [diff] [blame] | 1553 | easy to write a *lot* of code that looks like:
|
| 1554 |
|
| 1555 | @verbatim
|
Lee Thomason (grinliz) | ae209f6 | 2012-04-04 22:00:07 -0700 | [diff] [blame] | 1556 | XMLElement* root = document.FirstChildElement( "Document" );
|
Lee Thomason | 3ffdd39 | 2012-03-28 17:27:55 -0700 | [diff] [blame] | 1557 | if ( root )
|
| 1558 | {
|
Lee Thomason (grinliz) | ae209f6 | 2012-04-04 22:00:07 -0700 | [diff] [blame] | 1559 | XMLElement* element = root->FirstChildElement( "Element" );
|
Lee Thomason | 3ffdd39 | 2012-03-28 17:27:55 -0700 | [diff] [blame] | 1560 | if ( element )
|
| 1561 | {
|
Lee Thomason (grinliz) | ae209f6 | 2012-04-04 22:00:07 -0700 | [diff] [blame] | 1562 | XMLElement* child = element->FirstChildElement( "Child" );
|
Lee Thomason | 3ffdd39 | 2012-03-28 17:27:55 -0700 | [diff] [blame] | 1563 | if ( child )
|
| 1564 | {
|
Lee Thomason (grinliz) | ae209f6 | 2012-04-04 22:00:07 -0700 | [diff] [blame] | 1565 | XMLElement* child2 = child->NextSiblingElement( "Child" );
|
Lee Thomason | 3ffdd39 | 2012-03-28 17:27:55 -0700 | [diff] [blame] | 1566 | if ( child2 )
|
| 1567 | {
|
| 1568 | // Finally do something useful.
|
| 1569 | @endverbatim
|
| 1570 |
|
Lee Thomason (grinliz) | ae209f6 | 2012-04-04 22:00:07 -0700 | [diff] [blame] | 1571 | And that doesn't even cover "else" cases. XMLHandle addresses the verbosity
|
Lee Thomason (grinliz) | 2f1f624 | 2012-09-16 11:32:34 -0700 | [diff] [blame] | 1572 | of such code. A XMLHandle checks for null pointers so it is perfectly safe
|
Lee Thomason | 3ffdd39 | 2012-03-28 17:27:55 -0700 | [diff] [blame] | 1573 | and correct to use:
|
| 1574 |
|
| 1575 | @verbatim
|
Lee Thomason | db0bbb6 | 2012-04-04 15:47:04 -0700 | [diff] [blame] | 1576 | XMLHandle docHandle( &document );
|
| 1577 | XMLElement* child2 = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).FirstChild().NextSibling().ToElement();
|
Lee Thomason | 3ffdd39 | 2012-03-28 17:27:55 -0700 | [diff] [blame] | 1578 | if ( child2 )
|
| 1579 | {
|
| 1580 | // do something useful
|
| 1581 | @endverbatim
|
| 1582 |
|
| 1583 | Which is MUCH more concise and useful.
|
| 1584 |
|
| 1585 | It is also safe to copy handles - internally they are nothing more than node pointers.
|
| 1586 | @verbatim
|
Lee Thomason (grinliz) | ae209f6 | 2012-04-04 22:00:07 -0700 | [diff] [blame] | 1587 | XMLHandle handleCopy = handle;
|
Lee Thomason | 3ffdd39 | 2012-03-28 17:27:55 -0700 | [diff] [blame] | 1588 | @endverbatim
|
Lee Thomason (grinliz) | ae209f6 | 2012-04-04 22:00:07 -0700 | [diff] [blame] | 1589 |
|
| 1590 | See also XMLConstHandle, which is the same as XMLHandle, but operates on const objects.
|
Lee Thomason | 3ffdd39 | 2012-03-28 17:27:55 -0700 | [diff] [blame] | 1591 | */
|
| 1592 | class XMLHandle
|
| 1593 | {
|
| 1594 | public:
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1595 | /// Create a handle from any node (at any depth of the tree.) This can be a null pointer.
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1596 | XMLHandle( XMLNode* node ) {
|
| 1597 | _node = node;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1598 | }
|
| 1599 | /// Create a handle from a node.
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1600 | XMLHandle( XMLNode& node ) {
|
| 1601 | _node = &node;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1602 | }
|
| 1603 | /// Copy constructor
|
| 1604 | XMLHandle( const XMLHandle& ref ) {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1605 | _node = ref._node;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1606 | }
|
| 1607 | /// Assignment
|
| 1608 | XMLHandle& operator=( const XMLHandle& ref ) {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1609 | _node = ref._node;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1610 | return *this;
|
| 1611 | }
|
Lee Thomason | 3ffdd39 | 2012-03-28 17:27:55 -0700 | [diff] [blame] | 1612 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1613 | /// Get the first child of this handle.
|
| 1614 | XMLHandle FirstChild() {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1615 | return XMLHandle( _node ? _node->FirstChild() : 0 );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1616 | }
|
| 1617 | /// Get the first child element of this handle.
|
| 1618 | XMLHandle FirstChildElement( const char* value=0 ) {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1619 | return XMLHandle( _node ? _node->FirstChildElement( value ) : 0 );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1620 | }
|
| 1621 | /// Get the last child of this handle.
|
| 1622 | XMLHandle LastChild() {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1623 | return XMLHandle( _node ? _node->LastChild() : 0 );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1624 | }
|
| 1625 | /// Get the last child element of this handle.
|
| 1626 | XMLHandle LastChildElement( const char* _value=0 ) {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1627 | return XMLHandle( _node ? _node->LastChildElement( _value ) : 0 );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1628 | }
|
| 1629 | /// Get the previous sibling of this handle.
|
| 1630 | XMLHandle PreviousSibling() {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1631 | return XMLHandle( _node ? _node->PreviousSibling() : 0 );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1632 | }
|
| 1633 | /// Get the previous sibling element of this handle.
|
| 1634 | XMLHandle PreviousSiblingElement( const char* _value=0 ) {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1635 | return XMLHandle( _node ? _node->PreviousSiblingElement( _value ) : 0 );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1636 | }
|
| 1637 | /// Get the next sibling of this handle.
|
| 1638 | XMLHandle NextSibling() {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1639 | return XMLHandle( _node ? _node->NextSibling() : 0 );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1640 | }
|
| 1641 | /// Get the next sibling element of this handle.
|
| 1642 | XMLHandle NextSiblingElement( const char* _value=0 ) {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1643 | return XMLHandle( _node ? _node->NextSiblingElement( _value ) : 0 );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1644 | }
|
Lee Thomason | 3ffdd39 | 2012-03-28 17:27:55 -0700 | [diff] [blame] | 1645 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1646 | /// Safe cast to XMLNode. This can return null.
|
| 1647 | XMLNode* ToNode() {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1648 | return _node;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1649 | }
|
| 1650 | /// Safe cast to XMLElement. This can return null.
|
| 1651 | XMLElement* ToElement() {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1652 | return ( ( _node && _node->ToElement() ) ? _node->ToElement() : 0 );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1653 | }
|
| 1654 | /// Safe cast to XMLText. This can return null.
|
| 1655 | XMLText* ToText() {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1656 | return ( ( _node && _node->ToText() ) ? _node->ToText() : 0 );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1657 | }
|
| 1658 | /// Safe cast to XMLUnknown. This can return null.
|
| 1659 | XMLUnknown* ToUnknown() {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1660 | return ( ( _node && _node->ToUnknown() ) ? _node->ToUnknown() : 0 );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1661 | }
|
| 1662 | /// Safe cast to XMLDeclaration. This can return null.
|
| 1663 | XMLDeclaration* ToDeclaration() {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1664 | return ( ( _node && _node->ToDeclaration() ) ? _node->ToDeclaration() : 0 );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1665 | }
|
Lee Thomason | 3ffdd39 | 2012-03-28 17:27:55 -0700 | [diff] [blame] | 1666 |
|
| 1667 | private:
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1668 | XMLNode* _node;
|
Lee Thomason | 3ffdd39 | 2012-03-28 17:27:55 -0700 | [diff] [blame] | 1669 | };
|
| 1670 |
|
Lee Thomason (grinliz) | 2a1cd27 | 2012-02-24 17:37:53 -0800 | [diff] [blame] | 1671 |
|
| 1672 | /**
|
Lee Thomason (grinliz) | ae209f6 | 2012-04-04 22:00:07 -0700 | [diff] [blame] | 1673 | A variant of the XMLHandle class for working with const XMLNodes and Documents. It is the
|
| 1674 | same in all regards, except for the 'const' qualifiers. See XMLHandle for API.
|
Lee Thomason | 8b89981 | 2012-04-04 15:58:16 -0700 | [diff] [blame] | 1675 | */
|
| 1676 | class XMLConstHandle
|
| 1677 | {
|
| 1678 | public:
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1679 | XMLConstHandle( const XMLNode* node ) {
|
| 1680 | _node = node;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1681 | }
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1682 | XMLConstHandle( const XMLNode& node ) {
|
| 1683 | _node = &node;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1684 | }
|
| 1685 | XMLConstHandle( const XMLConstHandle& ref ) {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1686 | _node = ref._node;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1687 | }
|
Lee Thomason | 8b89981 | 2012-04-04 15:58:16 -0700 | [diff] [blame] | 1688 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1689 | XMLConstHandle& operator=( const XMLConstHandle& ref ) {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1690 | _node = ref._node;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1691 | return *this;
|
| 1692 | }
|
Lee Thomason | 8b89981 | 2012-04-04 15:58:16 -0700 | [diff] [blame] | 1693 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1694 | const XMLConstHandle FirstChild() const {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1695 | return XMLConstHandle( _node ? _node->FirstChild() : 0 );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1696 | }
|
| 1697 | const XMLConstHandle FirstChildElement( const char* value=0 ) const {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1698 | return XMLConstHandle( _node ? _node->FirstChildElement( value ) : 0 );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1699 | }
|
| 1700 | const XMLConstHandle LastChild() const {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1701 | return XMLConstHandle( _node ? _node->LastChild() : 0 );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1702 | }
|
| 1703 | const XMLConstHandle LastChildElement( const char* _value=0 ) const {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1704 | return XMLConstHandle( _node ? _node->LastChildElement( _value ) : 0 );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1705 | }
|
| 1706 | const XMLConstHandle PreviousSibling() const {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1707 | return XMLConstHandle( _node ? _node->PreviousSibling() : 0 );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1708 | }
|
| 1709 | const XMLConstHandle PreviousSiblingElement( const char* _value=0 ) const {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1710 | return XMLConstHandle( _node ? _node->PreviousSiblingElement( _value ) : 0 );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1711 | }
|
| 1712 | const XMLConstHandle NextSibling() const {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1713 | return XMLConstHandle( _node ? _node->NextSibling() : 0 );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1714 | }
|
| 1715 | const XMLConstHandle NextSiblingElement( const char* _value=0 ) const {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1716 | return XMLConstHandle( _node ? _node->NextSiblingElement( _value ) : 0 );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1717 | }
|
Lee Thomason | 8b89981 | 2012-04-04 15:58:16 -0700 | [diff] [blame] | 1718 |
|
| 1719 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1720 | const XMLNode* ToNode() const {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1721 | return _node;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1722 | }
|
| 1723 | const XMLElement* ToElement() const {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1724 | return ( ( _node && _node->ToElement() ) ? _node->ToElement() : 0 );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1725 | }
|
| 1726 | const XMLText* ToText() const {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1727 | return ( ( _node && _node->ToText() ) ? _node->ToText() : 0 );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1728 | }
|
| 1729 | const XMLUnknown* ToUnknown() const {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1730 | return ( ( _node && _node->ToUnknown() ) ? _node->ToUnknown() : 0 );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1731 | }
|
| 1732 | const XMLDeclaration* ToDeclaration() const {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1733 | return ( ( _node && _node->ToDeclaration() ) ? _node->ToDeclaration() : 0 );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1734 | }
|
Lee Thomason (grinliz) | bd0a8ac | 2012-02-20 20:14:33 -0800 | [diff] [blame] | 1735 |
|
Lee Thomason | 5cae897 | 2012-01-24 18:03:07 -0800 | [diff] [blame] | 1736 | private:
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1737 | const XMLNode* _node;
|
Lee Thomason | 56bdd02 | 2012-02-09 18:16:58 -0800 | [diff] [blame] | 1738 | };
|
Lee Thomason | 6f381b7 | 2012-03-02 12:59:39 -0800 | [diff] [blame] | 1739 |
|
U-Lama\Lee | e13c3e6 | 2011-12-28 14:36:55 -0800 | [diff] [blame] | 1740 |
|
| 1741 | /**
|
| 1742 | Printing functionality. The XMLPrinter gives you more
|
| 1743 | options than the XMLDocument::Print() method.
|
| 1744 |
|
| 1745 | It can:
|
| 1746 | -# Print to memory.
|
Thomas Roß | 08bdf50 | 2012-05-12 14:21:23 +0200 | [diff] [blame] | 1747 | -# Print to a file you provide.
|
U-Lama\Lee | e13c3e6 | 2011-12-28 14:36:55 -0800 | [diff] [blame] | 1748 | -# Print XML without a XMLDocument.
|
| 1749 |
|
| 1750 | Print to Memory
|
| 1751 |
|
| 1752 | @verbatim
|
| 1753 | XMLPrinter printer;
|
| 1754 | doc->Print( &printer );
|
Thomas Roß | 08bdf50 | 2012-05-12 14:21:23 +0200 | [diff] [blame] | 1755 | SomeFunction( printer.CStr() );
|
U-Lama\Lee | e13c3e6 | 2011-12-28 14:36:55 -0800 | [diff] [blame] | 1756 | @endverbatim
|
| 1757 |
|
| 1758 | Print to a File
|
Lee Thomason (grinliz) | 2f1f624 | 2012-09-16 11:32:34 -0700 | [diff] [blame] | 1759 |
|
U-Lama\Lee | e13c3e6 | 2011-12-28 14:36:55 -0800 | [diff] [blame] | 1760 | You provide the file pointer.
|
| 1761 | @verbatim
|
| 1762 | XMLPrinter printer( fp );
|
| 1763 | doc.Print( &printer );
|
| 1764 | @endverbatim
|
| 1765 |
|
| 1766 | Print without a XMLDocument
|
| 1767 |
|
| 1768 | When loading, an XML parser is very useful. However, sometimes
|
| 1769 | when saving, it just gets in the way. The code is often set up
|
| 1770 | for streaming, and constructing the DOM is just overhead.
|
| 1771 |
|
| 1772 | The Printer supports the streaming case. The following code
|
| 1773 | prints out a trivially simple XML file without ever creating
|
| 1774 | an XML document.
|
| 1775 |
|
| 1776 | @verbatim
|
| 1777 | XMLPrinter printer( fp );
|
| 1778 | printer.OpenElement( "foo" );
|
| 1779 | printer.PushAttribute( "foo", "bar" );
|
| 1780 | printer.CloseElement();
|
| 1781 | @endverbatim
|
| 1782 | */
|
| 1783 | class XMLPrinter : public XMLVisitor
|
| 1784 | {
|
| 1785 | public:
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1786 | /** Construct the printer. If the FILE* is specified,
|
| 1787 | this will print to the FILE. Else it will print
|
| 1788 | to memory, and the result is available in CStr().
|
| 1789 | If 'compact' is set to true, then output is created
|
| 1790 | with only required whitespace and newlines.
|
| 1791 | */
|
Jerome Martinez | 7fbefab | 2012-10-19 11:30:33 +0200 | [diff] [blame] | 1792 | XMLPrinter( std::FILE* file=0, bool compact = false );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1793 | ~XMLPrinter() {}
|
U-Lama\Lee | e13c3e6 | 2011-12-28 14:36:55 -0800 | [diff] [blame] | 1794 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1795 | /** If streaming, write the BOM and declaration. */
|
| 1796 | void PushHeader( bool writeBOM, bool writeDeclaration );
|
| 1797 | /** If streaming, start writing an element.
|
| 1798 | The element must be closed with CloseElement()
|
| 1799 | */
|
| 1800 | void OpenElement( const char* name );
|
| 1801 | /// If streaming, add an attribute to an open element.
|
| 1802 | void PushAttribute( const char* name, const char* value );
|
| 1803 | void PushAttribute( const char* name, int value );
|
| 1804 | void PushAttribute( const char* name, unsigned value );
|
| 1805 | void PushAttribute( const char* name, bool value );
|
| 1806 | void PushAttribute( const char* name, double value );
|
| 1807 | /// If streaming, close the Element.
|
| 1808 | void CloseElement();
|
U-Lama\Lee | e13c3e6 | 2011-12-28 14:36:55 -0800 | [diff] [blame] | 1809 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1810 | /// Add a text node.
|
| 1811 | void PushText( const char* text, bool cdata=false );
|
| 1812 | /// Add a text node from an integer.
|
| 1813 | void PushText( int value );
|
| 1814 | /// Add a text node from an unsigned.
|
| 1815 | void PushText( unsigned value );
|
| 1816 | /// Add a text node from a bool.
|
| 1817 | void PushText( bool value );
|
| 1818 | /// Add a text node from a float.
|
| 1819 | void PushText( float value );
|
| 1820 | /// Add a text node from a double.
|
| 1821 | void PushText( double value );
|
Lee Thomason | 21be882 | 2012-07-15 17:27:22 -0700 | [diff] [blame] | 1822 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1823 | /// Add a comment
|
| 1824 | void PushComment( const char* comment );
|
U-Lama\Lee | e13c3e6 | 2011-12-28 14:36:55 -0800 | [diff] [blame] | 1825 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1826 | void PushDeclaration( const char* value );
|
| 1827 | void PushUnknown( const char* value );
|
U-Lama\Lee | e13c3e6 | 2011-12-28 14:36:55 -0800 | [diff] [blame] | 1828 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1829 | virtual bool VisitEnter( const XMLDocument& /*doc*/ );
|
| 1830 | virtual bool VisitExit( const XMLDocument& /*doc*/ ) {
|
| 1831 | return true;
|
| 1832 | }
|
U-Lama\Lee | e13c3e6 | 2011-12-28 14:36:55 -0800 | [diff] [blame] | 1833 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1834 | virtual bool VisitEnter( const XMLElement& element, const XMLAttribute* attribute );
|
| 1835 | virtual bool VisitExit( const XMLElement& element );
|
U-Lama\Lee | e13c3e6 | 2011-12-28 14:36:55 -0800 | [diff] [blame] | 1836 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1837 | virtual bool Visit( const XMLText& text );
|
| 1838 | virtual bool Visit( const XMLComment& comment );
|
| 1839 | virtual bool Visit( const XMLDeclaration& declaration );
|
| 1840 | virtual bool Visit( const XMLUnknown& unknown );
|
U-Lama\Lee | e13c3e6 | 2011-12-28 14:36:55 -0800 | [diff] [blame] | 1841 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1842 | /**
|
| 1843 | If in print to memory mode, return a pointer to
|
| 1844 | the XML file in memory.
|
| 1845 | */
|
| 1846 | const char* CStr() const {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1847 | return _buffer.Mem();
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1848 | }
|
| 1849 | /**
|
| 1850 | If in print to memory mode, return the size
|
| 1851 | of the XML file in memory. (Note the size returned
|
| 1852 | includes the terminating null.)
|
| 1853 | */
|
| 1854 | int CStrSize() const {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1855 | return _buffer.Size();
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1856 | }
|
U-Lama\Lee | e13c3e6 | 2011-12-28 14:36:55 -0800 | [diff] [blame] | 1857 |
|
| 1858 | private:
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1859 | void SealElement();
|
| 1860 | void PrintSpace( int depth );
|
| 1861 | void PrintString( const char*, bool restrictedEntitySet ); // prints out, after detecting entities.
|
| 1862 | void Print( const char* format, ... );
|
U-Lama\Lee | e13c3e6 | 2011-12-28 14:36:55 -0800 | [diff] [blame] | 1863 |
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1864 | bool _elementJustOpened;
|
| 1865 | bool _firstElement;
|
Jerome Martinez | 7fbefab | 2012-10-19 11:30:33 +0200 | [diff] [blame] | 1866 | std::FILE* _fp;
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1867 | int _depth;
|
| 1868 | int _textDepth;
|
| 1869 | bool _processEntities;
|
| 1870 | bool _compactMode;
|
U-Lama\Lee | e13c3e6 | 2011-12-28 14:36:55 -0800 | [diff] [blame] | 1871 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1872 | enum {
|
| 1873 | ENTITY_RANGE = 64,
|
| 1874 | BUF_SIZE = 200
|
| 1875 | };
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1876 | bool _entityFlag[ENTITY_RANGE];
|
| 1877 | bool _restrictedEntityFlag[ENTITY_RANGE];
|
U-Lama\Lee | e13c3e6 | 2011-12-28 14:36:55 -0800 | [diff] [blame] | 1878 |
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1879 | DynArray< const char*, 10 > _stack;
|
| 1880 | DynArray< char, 20 > _buffer;
|
PKEuS | e736f29 | 2012-07-16 03:27:55 -0700 | [diff] [blame] | 1881 | #ifdef _MSC_VER
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1882 | DynArray< char, 20 > _accumulator;
|
PKEuS | e736f29 | 2012-07-16 03:27:55 -0700 | [diff] [blame] | 1883 | #endif
|
U-Lama\Lee | e13c3e6 | 2011-12-28 14:36:55 -0800 | [diff] [blame] | 1884 | };
|
| 1885 |
|
| 1886 |
|
Guillermo A. Amaral | b42ba36 | 2012-03-20 00:15:30 -0700 | [diff] [blame] | 1887 | } // tinyxml2
|
U-Lama\Lee | e13c3e6 | 2011-12-28 14:36:55 -0800 | [diff] [blame] | 1888 |
|
| 1889 |
|
U-Lama\Lee | e13c3e6 | 2011-12-28 14:36:55 -0800 | [diff] [blame] | 1890 | #endif // TINYXML2_INCLUDED
|