blob: 22d9d3e7dbf48d823704c89ec7b70baeb7a5d0b7 [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 );
51 void Print( FILE* cfile, int depth ); // prints leading spaces.
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:
93
94};
95
96
97class XMLComment : public XMLNode
98{
Lee Thomason3f57d272012-01-11 15:30:03 -080099public:
100 XMLComment( XMLDocument* doc );
101 virtual ~XMLComment();
U-Lama\Lee4cee6112011-12-31 14:58:18 -0800102
Lee Thomasonce0763e2012-01-11 15:43:54 -0800103 void Print( FILE* cfile, int depth );
104
105protected:
106 char* ParseDeep( char* );
107
Lee Thomason3f57d272012-01-11 15:30:03 -0800108private:
Lee Thomasonce0763e2012-01-11 15:43:54 -0800109 const char* value;
U-Lama\Lee4cee6112011-12-31 14:58:18 -0800110};
U-Lama\Leee13c3e62011-12-28 14:36:55 -0800111
112
113class XMLDocument
114{
115public:
116 XMLDocument();
Lee Thomason3f57d272012-01-11 15:30:03 -0800117 ~XMLDocument();
U-Lama\Leee13c3e62011-12-28 14:36:55 -0800118
119 bool Parse( const char* );
Lee Thomasonce0763e2012-01-11 15:43:54 -0800120 void Print( FILE* cfile=stdout, int depth=0 );
U-Lama\Leee13c3e62011-12-28 14:36:55 -0800121
Lee Thomason3f57d272012-01-11 15:30:03 -0800122 XMLNode* Root() { return root; }
123 XMLNode* RootElement();
U-Lama\Lee4cee6112011-12-31 14:58:18 -0800124
Lee Thomason3f57d272012-01-11 15:30:03 -0800125private:
126 XMLDocument( const XMLDocument& ); // intentionally not implemented
Lee Thomasonce0763e2012-01-11 15:43:54 -0800127 char* Identify( char* p, XMLNode** node );
Lee Thomason3f57d272012-01-11 15:30:03 -0800128
129 XMLNode* root;
U-Lama\Lee560bd472011-12-28 19:42:49 -0800130 CharBuffer* charBuffer;
U-Lama\Leee13c3e62011-12-28 14:36:55 -0800131};
132
133
U-Lama\Leee13c3e62011-12-28 14:36:55 -0800134}; // tinyxml2
135
U-Lama\Lee560bd472011-12-28 19:42:49 -0800136
137
U-Lama\Leee13c3e62011-12-28 14:36:55 -0800138#endif // TINYXML2_INCLUDED