Lee Thomason | 50f97b2 | 2012-02-11 16:33:40 -0800 | [diff] [blame] | 1 | #ifndef TINYXML_INCLUDED
|
U-Lama\Lee | e13c3e6 | 2011-12-28 14:36:55 -0800 | [diff] [blame] | 2 | #define TINYXML2_INCLUDED
|
| 3 |
|
Lee Thomason | 2c85a71 | 2012-01-31 08:24:24 -0800 | [diff] [blame] | 4 | /*
|
| 5 | TODO
|
Lee Thomason | 50adb4c | 2012-02-13 15:07:09 -0800 | [diff] [blame^] | 6 | X const and non-const versions of API
|
Lee Thomason | 455c9d4 | 2012-02-06 09:14:14 -0800 | [diff] [blame] | 7 | X memory pool the class construction
|
Lee Thomason | 50adb4c | 2012-02-13 15:07:09 -0800 | [diff] [blame^] | 8 | X attribute accessors
|
| 9 | X node navigation
|
Lee Thomason | 2c85a71 | 2012-01-31 08:24:24 -0800 | [diff] [blame] | 10 | - handles
|
Lee Thomason | 50adb4c | 2012-02-13 15:07:09 -0800 | [diff] [blame^] | 11 | X visit pattern - change streamer?
|
| 12 | X make constructors protected
|
| 13 | X hide copy constructor
|
| 14 | X hide = operator
|
Lee Thomason | 56bdd02 | 2012-02-09 18:16:58 -0800 | [diff] [blame] | 15 | X UTF8 support: isAlpha, etc.
|
Lee Thomason | 50adb4c | 2012-02-13 15:07:09 -0800 | [diff] [blame^] | 16 | - tests from xml1
|
| 17 | - perf test: xml1
|
| 18 | - perf test: xenowar
|
Lee Thomason | 2c85a71 | 2012-01-31 08:24:24 -0800 | [diff] [blame] | 19 | */
|
| 20 |
|
U-Lama\Lee | 4cee611 | 2011-12-31 14:58:18 -0800 | [diff] [blame] | 21 | #include <limits.h>
|
Lee Thomason | ce0763e | 2012-01-11 15:43:54 -0800 | [diff] [blame] | 22 | #include <ctype.h>
|
| 23 | #include <stdio.h>
|
Lee Thomason | 2c85a71 | 2012-01-31 08:24:24 -0800 | [diff] [blame] | 24 | #include <memory.h>
|
U-Lama\Lee | 4cee611 | 2011-12-31 14:58:18 -0800 | [diff] [blame] | 25 |
|
| 26 | #if defined( _DEBUG ) || defined( DEBUG ) || defined (__DEBUG__)
|
| 27 | #ifndef DEBUG
|
| 28 | #define DEBUG
|
| 29 | #endif
|
| 30 | #endif
|
| 31 |
|
| 32 |
|
| 33 | #if defined(DEBUG)
|
| 34 | #if defined(_MSC_VER)
|
| 35 | #define TIXMLASSERT( x ) if ( !(x)) { _asm { int 3 } } //if ( !(x)) WinDebugBreak()
|
| 36 | #elif defined (ANDROID_NDK)
|
| 37 | #include <android/log.h>
|
| 38 | #define TIXMLASSERT( x ) if ( !(x)) { __android_log_assert( "assert", "grinliz", "ASSERT in '%s' at %d.", __FILE__, __LINE__ ); }
|
| 39 | #else
|
| 40 | #include <assert.h>
|
| 41 | #define TIXMLASSERT assert
|
| 42 | #endif
|
| 43 | #else
|
| 44 | #define TIXMLASSERT( x ) {}
|
| 45 | #endif
|
| 46 |
|
U-Lama\Lee | e13c3e6 | 2011-12-28 14:36:55 -0800 | [diff] [blame] | 47 |
|
| 48 | namespace tinyxml2
|
| 49 | {
|
Lee Thomason | ce0763e | 2012-01-11 15:43:54 -0800 | [diff] [blame] | 50 | class XMLDocument;
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 51 | class XMLElement;
|
| 52 | class XMLAttribute;
|
| 53 | class XMLComment;
|
| 54 | class XMLNode;
|
Lee Thomason | 5492a1c | 2012-01-23 15:32:10 -0800 | [diff] [blame] | 55 | class XMLText;
|
Lee Thomason | 50f97b2 | 2012-02-11 16:33:40 -0800 | [diff] [blame] | 56 | class XMLDeclaration;
|
| 57 | class XMLUnknown;
|
U-Lama\Lee | e13c3e6 | 2011-12-28 14:36:55 -0800 | [diff] [blame] | 58 |
|
Lee Thomason | 5cae897 | 2012-01-24 18:03:07 -0800 | [diff] [blame] | 59 | class XMLStreamer;
|
| 60 |
|
Lee Thomason | 39ede24 | 2012-01-20 11:27:56 -0800 | [diff] [blame] | 61 | class StrPair
|
| 62 | {
|
Lee Thomason | d34f52c | 2012-01-20 12:55:24 -0800 | [diff] [blame] | 63 | public:
|
Lee Thomason | 39ede24 | 2012-01-20 11:27:56 -0800 | [diff] [blame] | 64 | enum {
|
Lee Thomason | e442230 | 2012-01-20 17:59:50 -0800 | [diff] [blame] | 65 | NEEDS_ENTITY_PROCESSING = 0x01,
|
Lee Thomason | 18d68bd | 2012-01-26 18:17:26 -0800 | [diff] [blame] | 66 | NEEDS_NEWLINE_NORMALIZATION = 0x02,
|
| 67 |
|
| 68 | TEXT_ELEMENT = NEEDS_ENTITY_PROCESSING | NEEDS_NEWLINE_NORMALIZATION,
|
| 69 | ATTRIBUTE_NAME = 0,
|
| 70 | ATTRIBUTE_VALUE = NEEDS_ENTITY_PROCESSING | NEEDS_NEWLINE_NORMALIZATION,
|
| 71 | COMMENT = NEEDS_NEWLINE_NORMALIZATION,
|
Lee Thomason | 39ede24 | 2012-01-20 11:27:56 -0800 | [diff] [blame] | 72 | };
|
| 73 |
|
| 74 | StrPair() : flags( 0 ), start( 0 ), end( 0 ) {}
|
Lee Thomason | e442230 | 2012-01-20 17:59:50 -0800 | [diff] [blame] | 75 | void Set( char* start, char* end, int flags ) {
|
Lee Thomason | 39ede24 | 2012-01-20 11:27:56 -0800 | [diff] [blame] | 76 | this->start = start; this->end = end; this->flags = flags | NEEDS_FLUSH;
|
| 77 | }
|
| 78 | const char* GetStr();
|
Lee Thomason | e442230 | 2012-01-20 17:59:50 -0800 | [diff] [blame] | 79 | bool Empty() const { return start == end; }
|
Lee Thomason | 39ede24 | 2012-01-20 11:27:56 -0800 | [diff] [blame] | 80 |
|
Lee Thomason | 2c85a71 | 2012-01-31 08:24:24 -0800 | [diff] [blame] | 81 | void SetInternedStr( const char* str ) { this->start = (char*) str; this->end = 0; this->flags = 0; }
|
Lee Thomason | 56bdd02 | 2012-02-09 18:16:58 -0800 | [diff] [blame] | 82 | char* ParseText( char* in, const char* endTag, int strFlags );
|
| 83 | char* ParseName( char* in );
|
| 84 |
|
Lee Thomason | 2c85a71 | 2012-01-31 08:24:24 -0800 | [diff] [blame] | 85 |
|
Lee Thomason | 39ede24 | 2012-01-20 11:27:56 -0800 | [diff] [blame] | 86 | private:
|
Lee Thomason | e442230 | 2012-01-20 17:59:50 -0800 | [diff] [blame] | 87 | enum {
|
| 88 | NEEDS_FLUSH = 0x100
|
| 89 | };
|
| 90 |
|
Lee Thomason | 39ede24 | 2012-01-20 11:27:56 -0800 | [diff] [blame] | 91 | // After parsing, if *end != 0, it can be set to zero.
|
| 92 | int flags;
|
Lee Thomason | e442230 | 2012-01-20 17:59:50 -0800 | [diff] [blame] | 93 | char* start;
|
Lee Thomason | 39ede24 | 2012-01-20 11:27:56 -0800 | [diff] [blame] | 94 | char* end;
|
| 95 | };
|
| 96 |
|
U-Lama\Lee | 560bd47 | 2011-12-28 19:42:49 -0800 | [diff] [blame] | 97 |
|
Lee Thomason | 2c85a71 | 2012-01-31 08:24:24 -0800 | [diff] [blame] | 98 | template <class T, int INIT>
|
| 99 | class DynArray
|
| 100 | {
|
| 101 | public:
|
| 102 | DynArray< T, INIT >()
|
| 103 | {
|
| 104 | mem = pool;
|
| 105 | allocated = INIT;
|
| 106 | size = 0;
|
| 107 | }
|
| 108 | ~DynArray()
|
| 109 | {
|
| 110 | if ( mem != pool ) {
|
| 111 | delete mem;
|
| 112 | }
|
| 113 | }
|
| 114 | void Push( T t )
|
| 115 | {
|
| 116 | EnsureCapacity( size+1 );
|
| 117 | mem[size++] = t;
|
| 118 | }
|
| 119 |
|
| 120 | T* PushArr( int count )
|
| 121 | {
|
| 122 | EnsureCapacity( size+count );
|
| 123 | T* ret = &mem[size];
|
| 124 | size += count;
|
| 125 | return ret;
|
| 126 | }
|
| 127 | T Pop() {
|
| 128 | return mem[--size];
|
| 129 | }
|
| 130 | void PopArr( int count )
|
| 131 | {
|
| 132 | TIXMLASSERT( size >= count );
|
| 133 | size -= count;
|
| 134 | }
|
| 135 |
|
| 136 | bool Empty() const { return size == 0; }
|
| 137 | T& operator[](int i) { TIXMLASSERT( i>= 0 && i < size ); return mem[i]; }
|
| 138 | const T& operator[](int i) const { TIXMLASSERT( i>= 0 && i < size ); return mem[i]; }
|
| 139 | int Size() const { return size; }
|
| 140 | const T* Mem() const { return mem; }
|
| 141 | T* Mem() { return mem; }
|
| 142 |
|
| 143 |
|
| 144 | private:
|
| 145 | void EnsureCapacity( int cap ) {
|
| 146 | if ( cap > allocated ) {
|
| 147 | int newAllocated = cap * 2;
|
| 148 | T* newMem = new T[newAllocated];
|
| 149 | memcpy( newMem, mem, sizeof(T)*size ); // warning: not using constructors, only works for PODs
|
| 150 | if ( mem != pool ) delete [] mem;
|
| 151 | mem = newMem;
|
| 152 | allocated = newAllocated;
|
| 153 | }
|
| 154 | }
|
| 155 |
|
| 156 | T* mem;
|
| 157 | T pool[INIT];
|
| 158 | int allocated; // objects allocated
|
| 159 | int size; // number objects in use
|
| 160 | };
|
| 161 |
|
Lee Thomason | 50adb4c | 2012-02-13 15:07:09 -0800 | [diff] [blame^] | 162 |
|
Lee Thomason | d198322 | 2012-02-06 08:41:24 -0800 | [diff] [blame] | 163 | class MemPool
|
| 164 | {
|
| 165 | public:
|
| 166 | MemPool() {}
|
| 167 | virtual ~MemPool() {}
|
| 168 |
|
| 169 | virtual int ItemSize() const = 0;
|
| 170 | virtual void* Alloc() = 0;
|
| 171 | virtual void Free( void* ) = 0;
|
| 172 | };
|
| 173 |
|
Lee Thomason | 50adb4c | 2012-02-13 15:07:09 -0800 | [diff] [blame^] | 174 |
|
Lee Thomason | d198322 | 2012-02-06 08:41:24 -0800 | [diff] [blame] | 175 | template< int SIZE >
|
| 176 | class MemPoolT : public MemPool
|
| 177 | {
|
| 178 | public:
|
Lee Thomason | 455c9d4 | 2012-02-06 09:14:14 -0800 | [diff] [blame] | 179 | MemPoolT() : root(0), currentAllocs(0), nAllocs(0), maxAllocs(0) {}
|
Lee Thomason | d198322 | 2012-02-06 08:41:24 -0800 | [diff] [blame] | 180 | ~MemPoolT() {
|
| 181 | // Delete the blocks.
|
| 182 | for( int i=0; i<blockPtrs.Size(); ++i ) {
|
| 183 | delete blockPtrs[i];
|
| 184 | }
|
| 185 | }
|
| 186 |
|
| 187 | virtual int ItemSize() const { return SIZE; }
|
Lee Thomason | 455c9d4 | 2012-02-06 09:14:14 -0800 | [diff] [blame] | 188 | int CurrentAllocs() const { return currentAllocs; }
|
Lee Thomason | d198322 | 2012-02-06 08:41:24 -0800 | [diff] [blame] | 189 |
|
| 190 | virtual void* Alloc() {
|
| 191 | if ( !root ) {
|
| 192 | // Need a new block.
|
| 193 | Block* block = new Block();
|
| 194 | blockPtrs.Push( block );
|
| 195 |
|
| 196 | for( int i=0; i<COUNT-1; ++i ) {
|
| 197 | block->chunk[i].next = &block->chunk[i+1];
|
| 198 | }
|
| 199 | block->chunk[COUNT-1].next = 0;
|
| 200 | root = block->chunk;
|
| 201 | }
|
| 202 | void* result = root;
|
| 203 | root = root->next;
|
Lee Thomason | 455c9d4 | 2012-02-06 09:14:14 -0800 | [diff] [blame] | 204 |
|
| 205 | ++currentAllocs;
|
| 206 | if ( currentAllocs > maxAllocs ) maxAllocs = currentAllocs;
|
| 207 | nAllocs++;
|
Lee Thomason | d198322 | 2012-02-06 08:41:24 -0800 | [diff] [blame] | 208 | return result;
|
| 209 | }
|
| 210 | virtual void Free( void* mem ) {
|
| 211 | if ( !mem ) return;
|
Lee Thomason | 455c9d4 | 2012-02-06 09:14:14 -0800 | [diff] [blame] | 212 | --currentAllocs;
|
Lee Thomason | d198322 | 2012-02-06 08:41:24 -0800 | [diff] [blame] | 213 | Chunk* chunk = (Chunk*)mem;
|
| 214 | memset( chunk, 0xfe, sizeof(Chunk) );
|
| 215 | chunk->next = root;
|
| 216 | root = chunk;
|
| 217 | }
|
Lee Thomason | 455c9d4 | 2012-02-06 09:14:14 -0800 | [diff] [blame] | 218 | void Trace( const char* name ) {
|
Lee Thomason | 43f5930 | 2012-02-06 18:18:11 -0800 | [diff] [blame] | 219 | printf( "Mempool %s watermark=%d [%dk] current=%d size=%d nAlloc=%d blocks=%d\n",
|
| 220 | name, maxAllocs, maxAllocs*SIZE/1024, currentAllocs, SIZE, nAllocs, blockPtrs.Size() );
|
Lee Thomason | 455c9d4 | 2012-02-06 09:14:14 -0800 | [diff] [blame] | 221 | }
|
Lee Thomason | d198322 | 2012-02-06 08:41:24 -0800 | [diff] [blame] | 222 |
|
| 223 | private:
|
| 224 | enum { COUNT = 1024/SIZE };
|
| 225 | union Chunk {
|
| 226 | Chunk* next;
|
| 227 | char mem[SIZE];
|
| 228 | };
|
| 229 | struct Block {
|
| 230 | Chunk chunk[COUNT];
|
| 231 | };
|
| 232 | DynArray< Block*, 10 > blockPtrs;
|
| 233 | Chunk* root;
|
Lee Thomason | 455c9d4 | 2012-02-06 09:14:14 -0800 | [diff] [blame] | 234 |
|
| 235 | int currentAllocs;
|
| 236 | int nAllocs;
|
| 237 | int maxAllocs;
|
Lee Thomason | d198322 | 2012-02-06 08:41:24 -0800 | [diff] [blame] | 238 | };
|
| 239 |
|
Lee Thomason | 2c85a71 | 2012-01-31 08:24:24 -0800 | [diff] [blame] | 240 |
|
Lee Thomason | 56bdd02 | 2012-02-09 18:16:58 -0800 | [diff] [blame] | 241 |
|
| 242 | /**
|
| 243 | Implements the interface to the "Visitor pattern" (see the Accept() method.)
|
| 244 | If you call the Accept() method, it requires being passed a XMLVisitor
|
| 245 | class to handle callbacks. For nodes that contain other nodes (Document, Element)
|
| 246 | you will get called with a VisitEnter/VisitExit pair. Nodes that are always leaves
|
| 247 | are simply called with Visit().
|
| 248 |
|
| 249 | If you return 'true' from a Visit method, recursive parsing will continue. If you return
|
| 250 | false, <b>no children of this node or its sibilings</b> will be Visited.
|
| 251 |
|
| 252 | All flavors of Visit methods have a default implementation that returns 'true' (continue
|
| 253 | visiting). You need to only override methods that are interesting to you.
|
| 254 |
|
| 255 | Generally Accept() is called on the TiXmlDocument, although all nodes suppert Visiting.
|
| 256 |
|
| 257 | You should never change the document from a callback.
|
| 258 |
|
| 259 | @sa XMLNode::Accept()
|
| 260 | */
|
| 261 | class XMLVisitor
|
U-Lama\Lee | e13c3e6 | 2011-12-28 14:36:55 -0800 | [diff] [blame] | 262 | {
|
| 263 | public:
|
Lee Thomason | 56bdd02 | 2012-02-09 18:16:58 -0800 | [diff] [blame] | 264 | virtual ~XMLVisitor() {}
|
Lee Thomason | d198322 | 2012-02-06 08:41:24 -0800 | [diff] [blame] | 265 |
|
Lee Thomason | 56bdd02 | 2012-02-09 18:16:58 -0800 | [diff] [blame] | 266 | /// Visit a document.
|
| 267 | virtual bool VisitEnter( const XMLDocument& /*doc*/ ) { return true; }
|
| 268 | /// Visit a document.
|
| 269 | virtual bool VisitExit( const XMLDocument& /*doc*/ ) { return true; }
|
| 270 |
|
| 271 | /// Visit an element.
|
| 272 | virtual bool VisitEnter( const XMLElement& /*element*/, const XMLAttribute* /*firstAttribute*/ ) { return true; }
|
| 273 | /// Visit an element.
|
| 274 | virtual bool VisitExit( const XMLElement& /*element*/ ) { return true; }
|
| 275 |
|
| 276 | /// Visit a declaration
|
Lee Thomason | 50f97b2 | 2012-02-11 16:33:40 -0800 | [diff] [blame] | 277 | virtual bool Visit( const XMLDeclaration& /*declaration*/ ) { return true; }
|
Lee Thomason | 56bdd02 | 2012-02-09 18:16:58 -0800 | [diff] [blame] | 278 | /// Visit a text node
|
| 279 | virtual bool Visit( const XMLText& /*text*/ ) { return true; }
|
| 280 | /// Visit a comment node
|
| 281 | virtual bool Visit( const XMLComment& /*comment*/ ) { return true; }
|
| 282 | /// Visit an unknown node
|
Lee Thomason | 50f97b2 | 2012-02-11 16:33:40 -0800 | [diff] [blame] | 283 | virtual bool Visit( const XMLUnknown& /*unknown*/ ) { return true; }
|
Lee Thomason | 56bdd02 | 2012-02-09 18:16:58 -0800 | [diff] [blame] | 284 | };
|
| 285 |
|
| 286 |
|
| 287 | class XMLUtil
|
| 288 | {
|
Lee Thomason | d198322 | 2012-02-06 08:41:24 -0800 | [diff] [blame] | 289 | public:
|
Lee Thomason | 56bdd02 | 2012-02-09 18:16:58 -0800 | [diff] [blame] | 290 | // Anything in the high order range of UTF-8 is assumed to not be whitespace. This isn't
|
| 291 | // correct, but simple, and usually works.
|
| 292 | static const char* SkipWhiteSpace( const char* p ) { while( IsUTF8Continuation(*p) || isspace( *p ) ) { ++p; } return p; }
|
| 293 | static char* SkipWhiteSpace( char* p ) { while( IsUTF8Continuation(*p) || isspace( *p ) ) { ++p; } return p; }
|
U-Lama\Lee | 4cee611 | 2011-12-31 14:58:18 -0800 | [diff] [blame] | 294 |
|
| 295 | inline static bool StringEqual( const char* p, const char* q, int nChar=INT_MAX ) {
|
| 296 | int n = 0;
|
Lee Thomason | d34f52c | 2012-01-20 12:55:24 -0800 | [diff] [blame] | 297 | if ( p == q ) {
|
| 298 | return true;
|
| 299 | }
|
U-Lama\Lee | 4cee611 | 2011-12-31 14:58:18 -0800 | [diff] [blame] | 300 | while( *p && *q && *p == *q && n<nChar ) {
|
| 301 | ++p; ++q; ++n;
|
| 302 | }
|
| 303 | if ( (n == nChar) || ( *p == 0 && *q == 0 ) ) {
|
| 304 | return true;
|
| 305 | }
|
| 306 | return false;
|
| 307 | }
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 308 | inline static int IsUTF8Continuation( unsigned char p ) { return p & 0x80; }
|
Lee Thomason | 56bdd02 | 2012-02-09 18:16:58 -0800 | [diff] [blame] | 309 | inline static int IsAlphaNum( unsigned char anyByte ) { return ( anyByte < 128 ) ? isalnum( anyByte ) : 1; }
|
| 310 | inline static int IsAlpha( unsigned char anyByte ) { return ( anyByte < 128 ) ? isalpha( anyByte ) : 1; }
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 311 | };
|
| 312 |
|
Lee Thomason | 5cae897 | 2012-01-24 18:03:07 -0800 | [diff] [blame] | 313 |
|
Lee Thomason | d198322 | 2012-02-06 08:41:24 -0800 | [diff] [blame] | 314 | class XMLNode
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 315 | {
|
| 316 | friend class XMLDocument;
|
| 317 | friend class XMLElement;
|
| 318 | public:
|
Lee Thomason | 751da52 | 2012-02-10 08:50:51 -0800 | [diff] [blame] | 319 | const XMLDocument* GetDocument() const { return document; }
|
Lee Thomason | 56bdd02 | 2012-02-09 18:16:58 -0800 | [diff] [blame] | 320 | XMLDocument* GetDocument() { return document; }
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 321 |
|
Lee Thomason | 56bdd02 | 2012-02-09 18:16:58 -0800 | [diff] [blame] | 322 | virtual XMLElement* ToElement() { return 0; }
|
| 323 | virtual XMLText* ToText() { return 0; }
|
| 324 | virtual XMLComment* ToComment() { return 0; }
|
| 325 | virtual XMLDocument* ToDocument() { return 0; }
|
Lee Thomason | 50f97b2 | 2012-02-11 16:33:40 -0800 | [diff] [blame] | 326 | virtual XMLDeclaration* ToDeclaration() { return 0; }
|
| 327 | virtual XMLUnknown* ToUnknown() { return 0; }
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 328 |
|
Lee Thomason | 50f97b2 | 2012-02-11 16:33:40 -0800 | [diff] [blame] | 329 | virtual const XMLElement* ToElement() const { return 0; }
|
| 330 | virtual const XMLText* ToText() const { return 0; }
|
| 331 | virtual const XMLComment* ToComment() const { return 0; }
|
| 332 | virtual const XMLDocument* ToDocument() const { return 0; }
|
| 333 | virtual const XMLDeclaration* ToDeclaration() const { return 0; }
|
| 334 | virtual const XMLUnknown* ToUnknown() const { return 0; }
|
Lee Thomason | 751da52 | 2012-02-10 08:50:51 -0800 | [diff] [blame] | 335 |
|
Lee Thomason | 2c85a71 | 2012-01-31 08:24:24 -0800 | [diff] [blame] | 336 | const char* Value() const { return value.GetStr(); }
|
| 337 | void SetValue( const char* val ) { value.SetInternedStr( val ); }
|
| 338 |
|
Lee Thomason | 751da52 | 2012-02-10 08:50:51 -0800 | [diff] [blame] | 339 | const XMLNode* Parent() const { return parent; }
|
| 340 | XMLNode* Parent() { return parent; }
|
| 341 |
|
Lee Thomason | 50f97b2 | 2012-02-11 16:33:40 -0800 | [diff] [blame] | 342 | /// Returns true if this node has no children.
|
| 343 | bool NoChildren() const { return !firstChild; }
|
Lee Thomason | 751da52 | 2012-02-10 08:50:51 -0800 | [diff] [blame] | 344 |
|
Lee Thomason | 56bdd02 | 2012-02-09 18:16:58 -0800 | [diff] [blame] | 345 | const XMLNode* FirstChild() const { return firstChild; }
|
| 346 | XMLNode* FirstChild() { return firstChild; }
|
| 347 | const XMLElement* FirstChildElement( const char* value=0 ) const;
|
| 348 | XMLElement* FirstChildElement( const char* value=0 ) { return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->FirstChildElement( value )); }
|
Lee Thomason | 3f57d27 | 2012-01-11 15:30:03 -0800 | [diff] [blame] | 349 |
|
Lee Thomason | 56bdd02 | 2012-02-09 18:16:58 -0800 | [diff] [blame] | 350 | const XMLNode* LastChild() const { return lastChild; }
|
| 351 | XMLNode* LastChild() { return const_cast<XMLNode*>(const_cast<const XMLNode*>(this)->LastChild() ); }
|
Lee Thomason | 2c85a71 | 2012-01-31 08:24:24 -0800 | [diff] [blame] | 352 |
|
Lee Thomason | 56bdd02 | 2012-02-09 18:16:58 -0800 | [diff] [blame] | 353 | const XMLElement* LastChildElement( const char* value=0 ) const;
|
| 354 | XMLElement* LastChildElement( const char* value=0 ) { return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->LastChildElement(value) ); }
|
| 355 |
|
| 356 | const XMLNode* PreviousSibling() const { return prev; }
|
| 357 | XMLNode* PreviousSibling() { return prev; }
|
| 358 |
|
| 359 | const XMLNode* PreviousSiblingElement( const char* value=0 ) const ;
|
| 360 | XMLNode* PreviousSiblingElement( const char* value=0 ) { return const_cast<XMLNode*>(const_cast<const XMLNode*>(this)->PreviousSiblingElement( value ) ); }
|
| 361 |
|
| 362 | const XMLNode* NextSibling() const { return next; }
|
| 363 | XMLNode* NextSibling() { return next; }
|
| 364 |
|
| 365 | const XMLNode* NextSiblingElement( const char* value=0 ) const;
|
| 366 | XMLNode* NextSiblingElement( const char* value=0 ) { return const_cast<XMLNode*>(const_cast<const XMLNode*>(this)->NextSiblingElement( value ) ); }
|
| 367 |
|
| 368 | XMLNode* InsertEndChild( XMLNode* addThis );
|
| 369 | XMLNode* InsertFirstChild( XMLNode* addThis );
|
| 370 | XMLNode* InsertAfterChild( XMLNode* afterThis, XMLNode* addThis );
|
| 371 |
|
| 372 | void ClearChildren();
|
| 373 | void DeleteChild( XMLNode* node );
|
| 374 |
|
| 375 | virtual bool Accept( XMLVisitor* visitor ) const = 0;
|
Lee Thomason | 751da52 | 2012-02-10 08:50:51 -0800 | [diff] [blame] | 376 | //virtual void Print( XMLStreamer* streamer );
|
Lee Thomason | 56bdd02 | 2012-02-09 18:16:58 -0800 | [diff] [blame] | 377 |
|
Lee Thomason | 67d6131 | 2012-01-24 16:01:51 -0800 | [diff] [blame] | 378 | virtual char* ParseDeep( char* );
|
Lee Thomason | 67d6131 | 2012-01-24 16:01:51 -0800 | [diff] [blame] | 379 | virtual bool IsClosingElement() const { return false; }
|
Lee Thomason | 3f57d27 | 2012-01-11 15:30:03 -0800 | [diff] [blame] | 380 |
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 381 | protected:
|
| 382 | XMLNode( XMLDocument* );
|
Lee Thomason | d198322 | 2012-02-06 08:41:24 -0800 | [diff] [blame] | 383 | virtual ~XMLNode();
|
Lee Thomason | 50adb4c | 2012-02-13 15:07:09 -0800 | [diff] [blame^] | 384 | XMLNode( const XMLNode& ); // not supported
|
| 385 | void operator=( const XMLNode& ); // not supported
|
Lee Thomason | d198322 | 2012-02-06 08:41:24 -0800 | [diff] [blame] | 386 |
|
Lee Thomason | 3f57d27 | 2012-01-11 15:30:03 -0800 | [diff] [blame] | 387 | XMLDocument* document;
|
| 388 | XMLNode* parent;
|
Lee Thomason | 50adb4c | 2012-02-13 15:07:09 -0800 | [diff] [blame^] | 389 | mutable StrPair value;
|
Lee Thomason | 3f57d27 | 2012-01-11 15:30:03 -0800 | [diff] [blame] | 390 |
|
| 391 | XMLNode* firstChild;
|
| 392 | XMLNode* lastChild;
|
| 393 |
|
| 394 | XMLNode* prev;
|
| 395 | XMLNode* next;
|
| 396 |
|
U-Lama\Lee | 4cee611 | 2011-12-31 14:58:18 -0800 | [diff] [blame] | 397 | private:
|
Lee Thomason | d198322 | 2012-02-06 08:41:24 -0800 | [diff] [blame] | 398 | MemPool* memPool;
|
Lee Thomason | 18d68bd | 2012-01-26 18:17:26 -0800 | [diff] [blame] | 399 | void Unlink( XMLNode* child );
|
U-Lama\Lee | 4cee611 | 2011-12-31 14:58:18 -0800 | [diff] [blame] | 400 | };
|
| 401 |
|
| 402 |
|
Lee Thomason | 5492a1c | 2012-01-23 15:32:10 -0800 | [diff] [blame] | 403 | class XMLText : public XMLNode
|
| 404 | {
|
Lee Thomason | 2c85a71 | 2012-01-31 08:24:24 -0800 | [diff] [blame] | 405 | friend class XMLBase;
|
| 406 | friend class XMLDocument;
|
Lee Thomason | 5492a1c | 2012-01-23 15:32:10 -0800 | [diff] [blame] | 407 | public:
|
Lee Thomason | 56bdd02 | 2012-02-09 18:16:58 -0800 | [diff] [blame] | 408 | virtual bool Accept( XMLVisitor* visitor ) const;
|
Lee Thomason | 50adb4c | 2012-02-13 15:07:09 -0800 | [diff] [blame^] | 409 |
|
Lee Thomason | 751da52 | 2012-02-10 08:50:51 -0800 | [diff] [blame] | 410 | virtual XMLText* ToText() { return this; }
|
| 411 | virtual const XMLText* ToText() const { return this; }
|
Lee Thomason | 5492a1c | 2012-01-23 15:32:10 -0800 | [diff] [blame] | 412 |
|
Lee Thomason | 50f97b2 | 2012-02-11 16:33:40 -0800 | [diff] [blame] | 413 | void SetCData( bool value ) { isCData = true; }
|
| 414 | bool CData() const { return isCData; }
|
| 415 |
|
Lee Thomason | 5492a1c | 2012-01-23 15:32:10 -0800 | [diff] [blame] | 416 | char* ParseDeep( char* );
|
| 417 |
|
| 418 | protected:
|
Lee Thomason | 50f97b2 | 2012-02-11 16:33:40 -0800 | [diff] [blame] | 419 | XMLText( XMLDocument* doc ) : XMLNode( doc ), isCData( false ) {}
|
| 420 | virtual ~XMLText() {}
|
Lee Thomason | 50adb4c | 2012-02-13 15:07:09 -0800 | [diff] [blame^] | 421 | XMLText( const XMLText& ); // not supported
|
| 422 | void operator=( const XMLText& ); // not supported
|
Lee Thomason | 5492a1c | 2012-01-23 15:32:10 -0800 | [diff] [blame] | 423 |
|
| 424 | private:
|
Lee Thomason | 50f97b2 | 2012-02-11 16:33:40 -0800 | [diff] [blame] | 425 | bool isCData;
|
Lee Thomason | 5492a1c | 2012-01-23 15:32:10 -0800 | [diff] [blame] | 426 | };
|
| 427 |
|
| 428 |
|
U-Lama\Lee | 4cee611 | 2011-12-31 14:58:18 -0800 | [diff] [blame] | 429 | class XMLComment : public XMLNode
|
| 430 | {
|
Lee Thomason | 2c85a71 | 2012-01-31 08:24:24 -0800 | [diff] [blame] | 431 | friend class XMLDocument;
|
Lee Thomason | 3f57d27 | 2012-01-11 15:30:03 -0800 | [diff] [blame] | 432 | public:
|
Lee Thomason | 751da52 | 2012-02-10 08:50:51 -0800 | [diff] [blame] | 433 | virtual XMLComment* ToComment() { return this; }
|
| 434 | virtual const XMLComment* ToComment() const { return this; }
|
Lee Thomason | ce0763e | 2012-01-11 15:43:54 -0800 | [diff] [blame] | 435 |
|
Lee Thomason | 56bdd02 | 2012-02-09 18:16:58 -0800 | [diff] [blame] | 436 | virtual bool Accept( XMLVisitor* visitor ) const;
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 437 |
|
Lee Thomason | ce0763e | 2012-01-11 15:43:54 -0800 | [diff] [blame] | 438 | char* ParseDeep( char* );
|
| 439 |
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 440 | protected:
|
Lee Thomason | 2c85a71 | 2012-01-31 08:24:24 -0800 | [diff] [blame] | 441 | XMLComment( XMLDocument* doc );
|
Lee Thomason | d198322 | 2012-02-06 08:41:24 -0800 | [diff] [blame] | 442 | virtual ~XMLComment();
|
Lee Thomason | 50adb4c | 2012-02-13 15:07:09 -0800 | [diff] [blame^] | 443 | XMLComment( const XMLComment& ); // not supported
|
| 444 | void operator=( const XMLComment& ); // not supported
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 445 |
|
Lee Thomason | 3f57d27 | 2012-01-11 15:30:03 -0800 | [diff] [blame] | 446 | private:
|
U-Lama\Lee | 4cee611 | 2011-12-31 14:58:18 -0800 | [diff] [blame] | 447 | };
|
U-Lama\Lee | e13c3e6 | 2011-12-28 14:36:55 -0800 | [diff] [blame] | 448 |
|
| 449 |
|
Lee Thomason | 50f97b2 | 2012-02-11 16:33:40 -0800 | [diff] [blame] | 450 | class XMLDeclaration : public XMLNode
|
| 451 | {
|
| 452 | friend class XMLDocument;
|
| 453 | public:
|
| 454 | virtual XMLDeclaration* ToDeclaration() { return this; }
|
| 455 | virtual const XMLDeclaration* ToDeclaration() const { return this; }
|
| 456 |
|
| 457 | virtual bool Accept( XMLVisitor* visitor ) const;
|
| 458 |
|
| 459 | char* ParseDeep( char* );
|
| 460 |
|
| 461 | protected:
|
| 462 | XMLDeclaration( XMLDocument* doc );
|
| 463 | virtual ~XMLDeclaration();
|
Lee Thomason | 50adb4c | 2012-02-13 15:07:09 -0800 | [diff] [blame^] | 464 | XMLDeclaration( const XMLDeclaration& ); // not supported
|
| 465 | void operator=( const XMLDeclaration& ); // not supported
|
Lee Thomason | 50f97b2 | 2012-02-11 16:33:40 -0800 | [diff] [blame] | 466 | };
|
| 467 |
|
| 468 |
|
| 469 | class XMLUnknown : public XMLNode
|
| 470 | {
|
| 471 | friend class XMLDocument;
|
| 472 | public:
|
| 473 | virtual XMLUnknown* ToUnknown() { return this; }
|
| 474 | virtual const XMLUnknown* ToUnknown() const { return this; }
|
| 475 |
|
| 476 | virtual bool Accept( XMLVisitor* visitor ) const;
|
| 477 |
|
| 478 | char* ParseDeep( char* );
|
| 479 |
|
| 480 | protected:
|
| 481 | XMLUnknown( XMLDocument* doc );
|
| 482 | virtual ~XMLUnknown();
|
Lee Thomason | 50adb4c | 2012-02-13 15:07:09 -0800 | [diff] [blame^] | 483 | XMLUnknown( const XMLUnknown& ); // not supported
|
| 484 | void operator=( const XMLUnknown& ); // not supported
|
Lee Thomason | 50f97b2 | 2012-02-11 16:33:40 -0800 | [diff] [blame] | 485 | };
|
| 486 |
|
| 487 |
|
Lee Thomason | 56bdd02 | 2012-02-09 18:16:58 -0800 | [diff] [blame] | 488 | class XMLAttribute
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 489 | {
|
| 490 | friend class XMLElement;
|
| 491 | public:
|
Lee Thomason | 751da52 | 2012-02-10 08:50:51 -0800 | [diff] [blame] | 492 | const char* Name() const { return name.GetStr(); }
|
| 493 | const char* Value() const { return value.GetStr(); }
|
| 494 | const XMLAttribute* Next() const { return next; }
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 495 |
|
Lee Thomason | 50adb4c | 2012-02-13 15:07:09 -0800 | [diff] [blame^] | 496 | int QueryIntAttribute( const char* name, int* value ) const;
|
| 497 | int QueryUnsignedAttribute( const char* name, unsigned int* value ) const;
|
| 498 | int QueryBoolAttribute( const char* name, bool* value ) const;
|
| 499 | int QueryDoubleAttribute( const char* name, double* _value ) const;
|
| 500 | int QueryFloatAttribute( const char* name, float* _value ) const;
|
| 501 |
|
| 502 | void SetAttribute( const char* name, const char* value );
|
| 503 | void SetAttribute( const char* name, int value );
|
| 504 | void SetAttribute( const char* name, unsigned value );
|
| 505 | void SetAttribute( const char* name, bool value );
|
| 506 | void SetAttribute( const char* name, double value );
|
| 507 |
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 508 | private:
|
Lee Thomason | d198322 | 2012-02-06 08:41:24 -0800 | [diff] [blame] | 509 | XMLAttribute( XMLElement* element ) : next( 0 ) {}
|
| 510 | virtual ~XMLAttribute() {}
|
Lee Thomason | 50adb4c | 2012-02-13 15:07:09 -0800 | [diff] [blame^] | 511 | XMLAttribute( const XMLAttribute& ); // not supported
|
| 512 | void operator=( const XMLAttribute& ); // not supported
|
| 513 |
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 514 | char* ParseDeep( char* p );
|
| 515 |
|
Lee Thomason | 751da52 | 2012-02-10 08:50:51 -0800 | [diff] [blame] | 516 | mutable StrPair name;
|
| 517 | mutable StrPair value;
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 518 | XMLAttribute* next;
|
Lee Thomason | 43f5930 | 2012-02-06 18:18:11 -0800 | [diff] [blame] | 519 | MemPool* memPool;
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 520 | };
|
| 521 |
|
| 522 |
|
| 523 | class XMLElement : public XMLNode
|
| 524 | {
|
Lee Thomason | 2c85a71 | 2012-01-31 08:24:24 -0800 | [diff] [blame] | 525 | friend class XMLBase;
|
| 526 | friend class XMLDocument;
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 527 | public:
|
Lee Thomason | 2c85a71 | 2012-01-31 08:24:24 -0800 | [diff] [blame] | 528 | const char* Name() const { return Value(); }
|
| 529 | void SetName( const char* str ) { SetValue( str ); }
|
| 530 |
|
Lee Thomason | 751da52 | 2012-02-10 08:50:51 -0800 | [diff] [blame] | 531 | virtual XMLElement* ToElement() { return this; }
|
| 532 | virtual const XMLElement* ToElement() const { return this; }
|
Lee Thomason | 56bdd02 | 2012-02-09 18:16:58 -0800 | [diff] [blame] | 533 | virtual bool Accept( XMLVisitor* visitor ) const;
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 534 |
|
Lee Thomason | 751da52 | 2012-02-10 08:50:51 -0800 | [diff] [blame] | 535 | const char* Attribute( const char* name ) const;
|
| 536 |
|
| 537 | int QueryIntAttribute( const char* name, int* value ) const;
|
| 538 | int QueryUnsignedAttribute( const char* name, unsigned int* value ) const;
|
| 539 | int QueryBoolAttribute( const char* name, bool* value ) const;
|
Lee Thomason | 50f97b2 | 2012-02-11 16:33:40 -0800 | [diff] [blame] | 540 | int QueryDoubleAttribute( const char* name, double* _value ) const;
|
| 541 | int QueryFloatAttribute( const char* name, float* _value ) const;
|
| 542 |
|
| 543 | void SetAttribute( const char* name, const char* value );
|
| 544 | void SetAttribute( const char* name, int value );
|
| 545 | void SetAttribute( const char* name, unsigned value );
|
| 546 | void SetAttribute( const char* name, bool value );
|
| 547 | void SetAttribute( const char* name, double value );
|
| 548 |
|
| 549 | void RemoveAttribute( const char* name );
|
Lee Thomason | 751da52 | 2012-02-10 08:50:51 -0800 | [diff] [blame] | 550 |
|
| 551 | const XMLAttribute* FirstAttribute() const { return rootAttribute; }
|
| 552 |
|
Lee Thomason | 50f97b2 | 2012-02-11 16:33:40 -0800 | [diff] [blame] | 553 | const char* GetText() const;
|
Lee Thomason | 751da52 | 2012-02-10 08:50:51 -0800 | [diff] [blame] | 554 |
|
Lee Thomason | 2c85a71 | 2012-01-31 08:24:24 -0800 | [diff] [blame] | 555 | // internal:
|
| 556 | virtual bool IsClosingElement() const { return closing; }
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 557 | char* ParseDeep( char* p );
|
| 558 |
|
Lee Thomason | 50adb4c | 2012-02-13 15:07:09 -0800 | [diff] [blame^] | 559 | private:
|
Lee Thomason | 2c85a71 | 2012-01-31 08:24:24 -0800 | [diff] [blame] | 560 | XMLElement( XMLDocument* doc );
|
Lee Thomason | d198322 | 2012-02-06 08:41:24 -0800 | [diff] [blame] | 561 | virtual ~XMLElement();
|
Lee Thomason | 50adb4c | 2012-02-13 15:07:09 -0800 | [diff] [blame^] | 562 | XMLElement( const XMLElement& ); // not supported
|
| 563 | void operator=( const XMLElement& ); // not supported
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 564 |
|
Lee Thomason | 67d6131 | 2012-01-24 16:01:51 -0800 | [diff] [blame] | 565 | char* ParseAttributes( char* p, bool *closedElement );
|
| 566 |
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 567 | bool closing;
|
| 568 | XMLAttribute* rootAttribute;
|
Lee Thomason | 751da52 | 2012-02-10 08:50:51 -0800 | [diff] [blame] | 569 | XMLAttribute* lastAttribute; // fixme: remove
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 570 | };
|
| 571 |
|
| 572 |
|
Lee Thomason | 67d6131 | 2012-01-24 16:01:51 -0800 | [diff] [blame] | 573 | class XMLDocument : public XMLNode
|
U-Lama\Lee | e13c3e6 | 2011-12-28 14:36:55 -0800 | [diff] [blame] | 574 | {
|
Lee Thomason | d198322 | 2012-02-06 08:41:24 -0800 | [diff] [blame] | 575 | friend class XMLElement;
|
U-Lama\Lee | e13c3e6 | 2011-12-28 14:36:55 -0800 | [diff] [blame] | 576 | public:
|
Lee Thomason | 18d68bd | 2012-01-26 18:17:26 -0800 | [diff] [blame] | 577 | XMLDocument();
|
Lee Thomason | 3f57d27 | 2012-01-11 15:30:03 -0800 | [diff] [blame] | 578 | ~XMLDocument();
|
U-Lama\Lee | e13c3e6 | 2011-12-28 14:36:55 -0800 | [diff] [blame] | 579 |
|
Lee Thomason | 751da52 | 2012-02-10 08:50:51 -0800 | [diff] [blame] | 580 | virtual XMLDocument* ToDocument() { return this; }
|
| 581 | virtual const XMLDocument* ToDocument() const { return this; }
|
Lee Thomason | 56bdd02 | 2012-02-09 18:16:58 -0800 | [diff] [blame] | 582 |
|
Lee Thomason | 7c913cd | 2012-01-26 18:32:34 -0800 | [diff] [blame] | 583 | int Parse( const char* );
|
| 584 | int Load( const char* );
|
| 585 | int Load( FILE* );
|
Lee Thomason | 18d68bd | 2012-01-26 18:17:26 -0800 | [diff] [blame] | 586 |
|
Lee Thomason | 5cae897 | 2012-01-24 18:03:07 -0800 | [diff] [blame] | 587 | void Print( XMLStreamer* streamer=0 );
|
Lee Thomason | 56bdd02 | 2012-02-09 18:16:58 -0800 | [diff] [blame] | 588 | virtual bool Accept( XMLVisitor* visitor ) const;
|
U-Lama\Lee | e13c3e6 | 2011-12-28 14:36:55 -0800 | [diff] [blame] | 589 |
|
Lee Thomason | 2c85a71 | 2012-01-31 08:24:24 -0800 | [diff] [blame] | 590 | XMLElement* NewElement( const char* name );
|
| 591 |
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 592 | enum {
|
Lee Thomason | 18d68bd | 2012-01-26 18:17:26 -0800 | [diff] [blame] | 593 | NO_ERROR = 0,
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 594 | ERROR_ELEMENT_MISMATCH,
|
| 595 | ERROR_PARSING_ELEMENT,
|
Lee Thomason | 50f97b2 | 2012-02-11 16:33:40 -0800 | [diff] [blame] | 596 | ERROR_PARSING_ATTRIBUTE,
|
| 597 | ERROR_IDENTIFYING_TAG
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 598 | };
|
Lee Thomason | 67d6131 | 2012-01-24 16:01:51 -0800 | [diff] [blame] | 599 | void SetError( int error, const char* str1, const char* str2 );
|
Lee Thomason | 18d68bd | 2012-01-26 18:17:26 -0800 | [diff] [blame] | 600 |
|
Lee Thomason | 7c913cd | 2012-01-26 18:32:34 -0800 | [diff] [blame] | 601 | bool Error() const { return errorID != NO_ERROR; }
|
Lee Thomason | 18d68bd | 2012-01-26 18:17:26 -0800 | [diff] [blame] | 602 | int GetErrorID() const { return errorID; }
|
| 603 | const char* GetErrorStr1() const { return errorStr1; }
|
| 604 | const char* GetErrorStr2() const { return errorStr2; }
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 605 |
|
Lee Thomason | d198322 | 2012-02-06 08:41:24 -0800 | [diff] [blame] | 606 | char* Identify( char* p, XMLNode** node );
|
Lee Thomason | 2c85a71 | 2012-01-31 08:24:24 -0800 | [diff] [blame] | 607 |
|
Lee Thomason | 3f57d27 | 2012-01-11 15:30:03 -0800 | [diff] [blame] | 608 | private:
|
Lee Thomason | 50adb4c | 2012-02-13 15:07:09 -0800 | [diff] [blame^] | 609 | XMLDocument( const XMLDocument& ); // not supported
|
| 610 | void operator=( const XMLDocument& ); // not supported
|
Lee Thomason | 18d68bd | 2012-01-26 18:17:26 -0800 | [diff] [blame] | 611 | void InitDocument();
|
| 612 |
|
Lee Thomason | 7c913cd | 2012-01-26 18:32:34 -0800 | [diff] [blame] | 613 | int errorID;
|
Lee Thomason | 18d68bd | 2012-01-26 18:17:26 -0800 | [diff] [blame] | 614 | const char* errorStr1;
|
| 615 | const char* errorStr2;
|
| 616 | char* charBuffer;
|
Lee Thomason | d198322 | 2012-02-06 08:41:24 -0800 | [diff] [blame] | 617 |
|
| 618 | MemPoolT< sizeof(XMLElement) > elementPool;
|
| 619 | MemPoolT< sizeof(XMLAttribute) > attributePool;
|
| 620 | MemPoolT< sizeof(XMLText) > textPool;
|
| 621 | MemPoolT< sizeof(XMLComment) > commentPool;
|
Lee Thomason | 5cae897 | 2012-01-24 18:03:07 -0800 | [diff] [blame] | 622 | };
|
| 623 |
|
Lee Thomason | 7c913cd | 2012-01-26 18:32:34 -0800 | [diff] [blame] | 624 |
|
Lee Thomason | 751da52 | 2012-02-10 08:50:51 -0800 | [diff] [blame] | 625 | class XMLStreamer : public XMLVisitor
|
Lee Thomason | 5cae897 | 2012-01-24 18:03:07 -0800 | [diff] [blame] | 626 | {
|
| 627 | public:
|
| 628 | XMLStreamer( FILE* file );
|
| 629 | ~XMLStreamer() {}
|
| 630 |
|
Lee Thomason | 56bdd02 | 2012-02-09 18:16:58 -0800 | [diff] [blame] | 631 | void OpenElement( const char* name );
|
Lee Thomason | 5cae897 | 2012-01-24 18:03:07 -0800 | [diff] [blame] | 632 | void PushAttribute( const char* name, const char* value );
|
| 633 | void CloseElement();
|
| 634 |
|
Lee Thomason | 50f97b2 | 2012-02-11 16:33:40 -0800 | [diff] [blame] | 635 | void PushText( const char* text, bool cdata=false );
|
Lee Thomason | 5cae897 | 2012-01-24 18:03:07 -0800 | [diff] [blame] | 636 | void PushComment( const char* comment );
|
| 637 |
|
Lee Thomason | 751da52 | 2012-02-10 08:50:51 -0800 | [diff] [blame] | 638 | virtual bool VisitEnter( const XMLDocument& /*doc*/ ) { return true; }
|
| 639 | virtual bool VisitExit( const XMLDocument& /*doc*/ ) { return true; }
|
| 640 |
|
| 641 | virtual bool VisitEnter( const XMLElement& element, const XMLAttribute* attribute );
|
| 642 | virtual bool VisitExit( const XMLElement& element );
|
| 643 |
|
| 644 | virtual bool Visit( const XMLText& text );
|
| 645 | virtual bool Visit( const XMLComment& comment );
|
| 646 |
|
| 647 |
|
Lee Thomason | 5cae897 | 2012-01-24 18:03:07 -0800 | [diff] [blame] | 648 | private:
|
| 649 | void SealElement();
|
| 650 | void PrintSpace( int depth );
|
Lee Thomason | 857b868 | 2012-01-25 17:50:25 -0800 | [diff] [blame] | 651 | void PrintString( const char* ); // prints out, after detecting entities.
|
Lee Thomason | 5cae897 | 2012-01-24 18:03:07 -0800 | [diff] [blame] | 652 |
|
| 653 | FILE* fp;
|
| 654 | int depth;
|
| 655 | bool elementJustOpened;
|
Lee Thomason | 56bdd02 | 2012-02-09 18:16:58 -0800 | [diff] [blame] | 656 | int textDepth;
|
| 657 |
|
Lee Thomason | 857b868 | 2012-01-25 17:50:25 -0800 | [diff] [blame] | 658 | enum {
|
Lee Thomason | 951d883 | 2012-01-26 08:47:06 -0800 | [diff] [blame] | 659 | ENTITY_RANGE = 64
|
Lee Thomason | 857b868 | 2012-01-25 17:50:25 -0800 | [diff] [blame] | 660 | };
|
| 661 | bool entityFlag[ENTITY_RANGE];
|
Lee Thomason | 5cae897 | 2012-01-24 18:03:07 -0800 | [diff] [blame] | 662 |
|
Lee Thomason | 2c85a71 | 2012-01-31 08:24:24 -0800 | [diff] [blame] | 663 | DynArray< const char*, 10 > stack;
|
Lee Thomason | 5cae897 | 2012-01-24 18:03:07 -0800 | [diff] [blame] | 664 | };
|
| 665 |
|
| 666 |
|
U-Lama\Lee | e13c3e6 | 2011-12-28 14:36:55 -0800 | [diff] [blame] | 667 | }; // tinyxml2
|
| 668 |
|
U-Lama\Lee | 560bd47 | 2011-12-28 19:42:49 -0800 | [diff] [blame] | 669 |
|
| 670 |
|
U-Lama\Lee | e13c3e6 | 2011-12-28 14:36:55 -0800 | [diff] [blame] | 671 | #endif // TINYXML2_INCLUDED |