2011-12-28 22:36:55 +00:00
|
|
|
#ifndef TINYXML2_INCLUDED
|
|
|
|
#define TINYXML2_INCLUDED
|
|
|
|
|
2011-12-31 22:58:18 +00:00
|
|
|
#include <limits.h>
|
2012-01-11 23:43:54 +00:00
|
|
|
#include <ctype.h>
|
|
|
|
#include <stdio.h>
|
2011-12-31 22:58:18 +00:00
|
|
|
|
|
|
|
#if defined( _DEBUG ) || defined( DEBUG ) || defined (__DEBUG__)
|
|
|
|
#ifndef DEBUG
|
|
|
|
#define DEBUG
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(DEBUG)
|
|
|
|
#if defined(_MSC_VER)
|
|
|
|
#define TIXMLASSERT( x ) if ( !(x)) { _asm { int 3 } } //if ( !(x)) WinDebugBreak()
|
|
|
|
#elif defined (ANDROID_NDK)
|
|
|
|
#include <android/log.h>
|
|
|
|
#define TIXMLASSERT( x ) if ( !(x)) { __android_log_assert( "assert", "grinliz", "ASSERT in '%s' at %d.", __FILE__, __LINE__ ); }
|
|
|
|
#else
|
|
|
|
#include <assert.h>
|
|
|
|
#define TIXMLASSERT assert
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
#define TIXMLASSERT( x ) {}
|
|
|
|
#endif
|
|
|
|
|
2011-12-28 22:36:55 +00:00
|
|
|
|
|
|
|
namespace tinyxml2
|
|
|
|
{
|
2012-01-11 23:43:54 +00:00
|
|
|
class XMLDocument;
|
2011-12-28 22:36:55 +00:00
|
|
|
|
2011-12-29 03:42:49 +00:00
|
|
|
// internal - move to separate namespace
|
|
|
|
struct CharBuffer
|
|
|
|
{
|
|
|
|
size_t length;
|
|
|
|
char mem[1];
|
|
|
|
|
|
|
|
static CharBuffer* Construct( const char* in );
|
|
|
|
static void Free( CharBuffer* );
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-12-31 22:58:18 +00:00
|
|
|
class XMLNode
|
2011-12-28 22:36:55 +00:00
|
|
|
{
|
2011-12-31 22:58:18 +00:00
|
|
|
friend class XMLDocument;
|
2011-12-28 22:36:55 +00:00
|
|
|
public:
|
2011-12-31 22:58:18 +00:00
|
|
|
|
2012-01-11 23:43:54 +00:00
|
|
|
XMLNode* InsertEndChild( XMLNode* addThis );
|
|
|
|
void Print( FILE* cfile, int depth ); // prints leading spaces.
|
2011-12-31 22:58:18 +00:00
|
|
|
|
|
|
|
protected:
|
2012-01-11 23:30:03 +00:00
|
|
|
XMLNode( XMLDocument* );
|
|
|
|
virtual ~XMLNode();
|
|
|
|
|
|
|
|
// Utility
|
|
|
|
static const char* SkipWhiteSpace( const char* p ) { while( isspace( *p ) ) { ++p; } return p; }
|
|
|
|
static char* SkipWhiteSpace( char* p ) { while( isspace( *p ) ) { ++p; } return p; }
|
2011-12-31 22:58:18 +00:00
|
|
|
|
|
|
|
inline static bool StringEqual( const char* p, const char* q, int nChar=INT_MAX ) {
|
|
|
|
int n = 0;
|
|
|
|
while( *p && *q && *p == *q && n<nChar ) {
|
|
|
|
++p; ++q; ++n;
|
|
|
|
}
|
|
|
|
if ( (n == nChar) || ( *p == 0 && *q == 0 ) ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-01-11 23:30:03 +00:00
|
|
|
/* Parses text. (Not a text node.)
|
|
|
|
- [ ] EOL normalization.
|
|
|
|
- [x] Trim leading whitespace
|
|
|
|
- [ ] Trim trailing whitespace.
|
|
|
|
- [ ] Leaves inner whitespace
|
|
|
|
- [ ] Inserts one space between lines.
|
|
|
|
*/
|
|
|
|
const char* ParseText( char* in, const char* endTag, char** next );
|
|
|
|
|
|
|
|
virtual char* ParseDeep( char* ) { TIXMLASSERT( 0 ); }
|
|
|
|
|
|
|
|
XMLDocument* document;
|
|
|
|
XMLNode* parent;
|
|
|
|
|
|
|
|
XMLNode* firstChild;
|
|
|
|
XMLNode* lastChild;
|
|
|
|
|
|
|
|
XMLNode* prev;
|
|
|
|
XMLNode* next;
|
|
|
|
|
2011-12-31 22:58:18 +00:00
|
|
|
private:
|
|
|
|
|
2011-12-28 22:36:55 +00:00
|
|
|
};
|
2011-12-29 03:42:49 +00:00
|
|
|
|
2011-12-28 22:36:55 +00:00
|
|
|
|
2011-12-31 22:58:18 +00:00
|
|
|
class XMLComment : public XMLNode
|
|
|
|
{
|
2012-01-11 23:30:03 +00:00
|
|
|
public:
|
|
|
|
XMLComment( XMLDocument* doc );
|
|
|
|
virtual ~XMLComment();
|
2011-12-31 22:58:18 +00:00
|
|
|
|
2012-01-11 23:43:54 +00:00
|
|
|
void Print( FILE* cfile, int depth );
|
|
|
|
|
|
|
|
protected:
|
|
|
|
char* ParseDeep( char* );
|
|
|
|
|
2012-01-11 23:30:03 +00:00
|
|
|
private:
|
2012-01-11 23:43:54 +00:00
|
|
|
const char* value;
|
2011-12-31 22:58:18 +00:00
|
|
|
};
|
|
|
|
|
2011-12-28 22:36:55 +00:00
|
|
|
|
|
|
|
class XMLDocument
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
XMLDocument();
|
2012-01-11 23:30:03 +00:00
|
|
|
~XMLDocument();
|
2011-12-28 22:36:55 +00:00
|
|
|
|
|
|
|
bool Parse( const char* );
|
2012-01-11 23:43:54 +00:00
|
|
|
void Print( FILE* cfile=stdout, int depth=0 );
|
2011-12-28 22:36:55 +00:00
|
|
|
|
2012-01-11 23:30:03 +00:00
|
|
|
XMLNode* Root() { return root; }
|
|
|
|
XMLNode* RootElement();
|
|
|
|
|
2011-12-28 22:36:55 +00:00
|
|
|
private:
|
2012-01-11 23:30:03 +00:00
|
|
|
XMLDocument( const XMLDocument& ); // intentionally not implemented
|
2012-01-11 23:43:54 +00:00
|
|
|
char* Identify( char* p, XMLNode** node );
|
2011-12-31 22:58:18 +00:00
|
|
|
|
2012-01-11 23:30:03 +00:00
|
|
|
XMLNode* root;
|
2011-12-29 03:42:49 +00:00
|
|
|
CharBuffer* charBuffer;
|
2011-12-28 22:36:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-12-29 03:42:49 +00:00
|
|
|
}; // tinyxml2
|
2011-12-28 22:36:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif // TINYXML2_INCLUDED
|