blob: 2ff58c91c4d3e6631b113febcd7c64c4b06f42b3 [file] [log] [blame]
U-Lama\Leee13c3e62011-12-28 14:36:55 -08001#ifndef TINYXML2_INCLUDED
2#define TINYXML2_INCLUDED
3
U-Lama\Lee4cee6112011-12-31 14:58:18 -08004#include <limits.h>
Lee Thomasonce0763e2012-01-11 15:43:54 -08005#include <ctype.h>
6#include <stdio.h>
U-Lama\Lee4cee6112011-12-31 14:58:18 -08007
8#if defined( _DEBUG ) || defined( DEBUG ) || defined (__DEBUG__)
9 #ifndef DEBUG
10 #define DEBUG
11 #endif
12#endif
13
14
15#if defined(DEBUG)
16 #if defined(_MSC_VER)
17 #define TIXMLASSERT( x ) if ( !(x)) { _asm { int 3 } } //if ( !(x)) WinDebugBreak()
18 #elif defined (ANDROID_NDK)
19 #include <android/log.h>
20 #define TIXMLASSERT( x ) if ( !(x)) { __android_log_assert( "assert", "grinliz", "ASSERT in '%s' at %d.", __FILE__, __LINE__ ); }
21 #else
22 #include <assert.h>
23 #define TIXMLASSERT assert
24 #endif
25#else
26 #define TIXMLASSERT( x ) {}
27#endif
28
U-Lama\Leee13c3e62011-12-28 14:36:55 -080029
30namespace tinyxml2
31{
Lee Thomasonce0763e2012-01-11 15:43:54 -080032class XMLDocument;
U-Lama\Leee13c3e62011-12-28 14:36:55 -080033
U-Lama\Lee560bd472011-12-28 19:42:49 -080034// internal - move to separate namespace
35struct CharBuffer
36{
37 size_t length;
38 char mem[1];
39
40 static CharBuffer* Construct( const char* in );
41 static void Free( CharBuffer* );
42};
43
44
U-Lama\Lee4cee6112011-12-31 14:58:18 -080045class XMLNode
U-Lama\Leee13c3e62011-12-28 14:36:55 -080046{
U-Lama\Lee4cee6112011-12-31 14:58:18 -080047 friend class XMLDocument;
U-Lama\Leee13c3e62011-12-28 14:36:55 -080048public:
U-Lama\Lee560bd472011-12-28 19:42:49 -080049
Lee Thomasonce0763e2012-01-11 15:43:54 -080050 XMLNode* InsertEndChild( XMLNode* addThis );
Lee Thomason85403d82012-01-11 15:55:05 -080051 virtual void Print( FILE* cfile, int depth );
U-Lama\Lee4cee6112011-12-31 14:58:18 -080052
53protected:
Lee Thomason3f57d272012-01-11 15:30:03 -080054 XMLNode( XMLDocument* );
55 virtual ~XMLNode();
56
57 // Utility
58 static const char* SkipWhiteSpace( const char* p ) { while( isspace( *p ) ) { ++p; } return p; }
59 static char* SkipWhiteSpace( char* p ) { while( isspace( *p ) ) { ++p; } return p; }
U-Lama\Lee4cee6112011-12-31 14:58:18 -080060
61 inline static bool StringEqual( const char* p, const char* q, int nChar=INT_MAX ) {
62 int n = 0;
63 while( *p && *q && *p == *q && n<nChar ) {
64 ++p; ++q; ++n;
65 }
66 if ( (n == nChar) || ( *p == 0 && *q == 0 ) ) {
67 return true;
68 }
69 return false;
70 }
71
Lee Thomason3f57d272012-01-11 15:30:03 -080072 /* Parses text. (Not a text node.)
73 - [ ] EOL normalization.
74 - [x] Trim leading whitespace
75 - [ ] Trim trailing whitespace.
76 - [ ] Leaves inner whitespace
77 - [ ] Inserts one space between lines.
78 */
79 const char* ParseText( char* in, const char* endTag, char** next );
80
81 virtual char* ParseDeep( char* ) { TIXMLASSERT( 0 ); }
82
83 XMLDocument* document;
84 XMLNode* parent;
85
86 XMLNode* firstChild;
87 XMLNode* lastChild;
88
89 XMLNode* prev;
90 XMLNode* next;
91
U-Lama\Lee4cee6112011-12-31 14:58:18 -080092private:
Lee Thomason85403d82012-01-11 15:55:05 -080093 void PrintSpace( FILE* cfile, int depth ); // prints leading spaces.
U-Lama\Lee4cee6112011-12-31 14:58:18 -080094
95};
96
97
98class XMLComment : public XMLNode
99{
Lee Thomason3f57d272012-01-11 15:30:03 -0800100public:
101 XMLComment( XMLDocument* doc );
102 virtual ~XMLComment();
U-Lama\Lee4cee6112011-12-31 14:58:18 -0800103
Lee Thomason85403d82012-01-11 15:55:05 -0800104 virtual void Print( FILE* cfile, int depth );
Lee Thomasonce0763e2012-01-11 15:43:54 -0800105
106protected:
107 char* ParseDeep( char* );
108
Lee Thomason3f57d272012-01-11 15:30:03 -0800109private:
Lee Thomasonce0763e2012-01-11 15:43:54 -0800110 const char* value;
U-Lama\Lee4cee6112011-12-31 14:58:18 -0800111};
U-Lama\Leee13c3e62011-12-28 14:36:55 -0800112
113
114class XMLDocument
115{
116public:
117 XMLDocument();
Lee Thomason3f57d272012-01-11 15:30:03 -0800118 ~XMLDocument();
U-Lama\Leee13c3e62011-12-28 14:36:55 -0800119
120 bool Parse( const char* );
Lee Thomasonce0763e2012-01-11 15:43:54 -0800121 void Print( FILE* cfile=stdout, int depth=0 );
U-Lama\Leee13c3e62011-12-28 14:36:55 -0800122
Lee Thomason3f57d272012-01-11 15:30:03 -0800123 XMLNode* Root() { return root; }
124 XMLNode* RootElement();
U-Lama\Lee4cee6112011-12-31 14:58:18 -0800125
Lee Thomason3f57d272012-01-11 15:30:03 -0800126private:
127 XMLDocument( const XMLDocument& ); // intentionally not implemented
Lee Thomasonce0763e2012-01-11 15:43:54 -0800128 char* Identify( char* p, XMLNode** node );
Lee Thomason3f57d272012-01-11 15:30:03 -0800129
130 XMLNode* root;
U-Lama\Lee560bd472011-12-28 19:42:49 -0800131 CharBuffer* charBuffer;
U-Lama\Leee13c3e62011-12-28 14:36:55 -0800132};
133
134
U-Lama\Leee13c3e62011-12-28 14:36:55 -0800135}; // tinyxml2
136
U-Lama\Lee560bd472011-12-28 19:42:49 -0800137
138
U-Lama\Leee13c3e62011-12-28 14:36:55 -0800139#endif // TINYXML2_INCLUDED