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