blob: f8313639a07ff3da08a51716e5888657ab3f5ef8 [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>
5
6#if defined( _DEBUG ) || defined( DEBUG ) || defined (__DEBUG__)
7 #ifndef DEBUG
8 #define DEBUG
9 #endif
10#endif
11
12
13#if defined(DEBUG)
14 #if defined(_MSC_VER)
15 #define TIXMLASSERT( x ) if ( !(x)) { _asm { int 3 } } //if ( !(x)) WinDebugBreak()
16 #elif defined (ANDROID_NDK)
17 #include <android/log.h>
18 #define TIXMLASSERT( x ) if ( !(x)) { __android_log_assert( "assert", "grinliz", "ASSERT in '%s' at %d.", __FILE__, __LINE__ ); }
19 #else
20 #include <assert.h>
21 #define TIXMLASSERT assert
22 #endif
23#else
24 #define TIXMLASSERT( x ) {}
25#endif
26
U-Lama\Leee13c3e62011-12-28 14:36:55 -080027
28namespace tinyxml2
29{
Lee Thomason3f57d272012-01-11 15:30:03 -080030class XMLDocument*;
U-Lama\Leee13c3e62011-12-28 14:36:55 -080031
U-Lama\Lee560bd472011-12-28 19:42:49 -080032// internal - move to separate namespace
33struct CharBuffer
34{
35 size_t length;
36 char mem[1];
37
38 static CharBuffer* Construct( const char* in );
39 static void Free( CharBuffer* );
40};
41
42
U-Lama\Lee4cee6112011-12-31 14:58:18 -080043class XMLNode
U-Lama\Leee13c3e62011-12-28 14:36:55 -080044{
U-Lama\Lee4cee6112011-12-31 14:58:18 -080045 friend class XMLDocument;
U-Lama\Leee13c3e62011-12-28 14:36:55 -080046public:
U-Lama\Lee560bd472011-12-28 19:42:49 -080047
U-Lama\Lee4cee6112011-12-31 14:58:18 -080048 static XMLNode* Identify( const char* p );
49
50protected:
Lee Thomason3f57d272012-01-11 15:30:03 -080051 XMLNode( XMLDocument* );
52 virtual ~XMLNode();
53
54 // Utility
55 static const char* SkipWhiteSpace( const char* p ) { while( isspace( *p ) ) { ++p; } return p; }
56 static char* SkipWhiteSpace( char* p ) { while( isspace( *p ) ) { ++p; } return p; }
U-Lama\Lee4cee6112011-12-31 14:58:18 -080057
58 inline static bool StringEqual( const char* p, const char* q, int nChar=INT_MAX ) {
59 int n = 0;
60 while( *p && *q && *p == *q && n<nChar ) {
61 ++p; ++q; ++n;
62 }
63 if ( (n == nChar) || ( *p == 0 && *q == 0 ) ) {
64 return true;
65 }
66 return false;
67 }
68
Lee Thomason3f57d272012-01-11 15:30:03 -080069 /* Parses text. (Not a text node.)
70 - [ ] EOL normalization.
71 - [x] Trim leading whitespace
72 - [ ] Trim trailing whitespace.
73 - [ ] Leaves inner whitespace
74 - [ ] Inserts one space between lines.
75 */
76 const char* ParseText( char* in, const char* endTag, char** next );
77
78 virtual char* ParseDeep( char* ) { TIXMLASSERT( 0 ); }
79
80 XMLDocument* document;
81 XMLNode* parent;
82
83 XMLNode* firstChild;
84 XMLNode* lastChild;
85
86 XMLNode* prev;
87 XMLNode* next;
88
U-Lama\Lee4cee6112011-12-31 14:58:18 -080089private:
90
91};
92
93
94class XMLComment : public XMLNode
95{
Lee Thomason3f57d272012-01-11 15:30:03 -080096public:
97 XMLComment( XMLDocument* doc );
98 virtual ~XMLComment();
U-Lama\Lee4cee6112011-12-31 14:58:18 -080099
Lee Thomason3f57d272012-01-11 15:30:03 -0800100private:
101 char* value;
U-Lama\Lee4cee6112011-12-31 14:58:18 -0800102};
U-Lama\Leee13c3e62011-12-28 14:36:55 -0800103
104
105class XMLDocument
106{
107public:
108 XMLDocument();
Lee Thomason3f57d272012-01-11 15:30:03 -0800109 ~XMLDocument();
U-Lama\Leee13c3e62011-12-28 14:36:55 -0800110
111 bool Parse( const char* );
112
Lee Thomason3f57d272012-01-11 15:30:03 -0800113 XMLNode* Root() { return root; }
114 XMLNode* RootElement();
U-Lama\Lee4cee6112011-12-31 14:58:18 -0800115
Lee Thomason3f57d272012-01-11 15:30:03 -0800116 XMLNode* InsertEndChild( XMLNode* addThis );
117
118private:
119 XMLDocument( const XMLDocument& ); // intentionally not implemented
120
121 virtual char* ParseDeep( char* );
122
123 XMLNode* root;
U-Lama\Lee560bd472011-12-28 19:42:49 -0800124 CharBuffer* charBuffer;
U-Lama\Leee13c3e62011-12-28 14:36:55 -0800125};
126
127
128
U-Lama\Lee4cee6112011-12-31 14:58:18 -0800129
130
131
U-Lama\Leee13c3e62011-12-28 14:36:55 -0800132}; // tinyxml2
133
U-Lama\Lee560bd472011-12-28 19:42:49 -0800134
135
U-Lama\Leee13c3e62011-12-28 14:36:55 -0800136#endif // TINYXML2_INCLUDED