#ifndef TINYXML2_INCLUDED #define TINYXML2_INCLUDED #include #include #include #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 #define TIXMLASSERT( x ) if ( !(x)) { __android_log_assert( "assert", "grinliz", "ASSERT in '%s' at %d.", __FILE__, __LINE__ ); } #else #include #define TIXMLASSERT assert #endif #else #define TIXMLASSERT( x ) {} #endif namespace tinyxml2 { class XMLDocument; class XMLElement; class XMLAttribute; class XMLComment; class XMLNode; class XMLText; class XMLStreamer; /* // internal - move to separate namespace struct CharBuffer { size_t length; char mem[1]; static CharBuffer* Construct( const char* in ); static void Free( CharBuffer* ); }; */ class StrPair { public: enum { NEEDS_ENTITY_PROCESSING = 0x01, NEEDS_NEWLINE_NORMALIZATION = 0x02, TEXT_ELEMENT = NEEDS_ENTITY_PROCESSING | NEEDS_NEWLINE_NORMALIZATION, ATTRIBUTE_NAME = 0, ATTRIBUTE_VALUE = NEEDS_ENTITY_PROCESSING | NEEDS_NEWLINE_NORMALIZATION, COMMENT = NEEDS_NEWLINE_NORMALIZATION, }; StrPair() : flags( 0 ), start( 0 ), end( 0 ) {} void Set( char* start, char* end, int flags ) { this->start = start; this->end = end; this->flags = flags | NEEDS_FLUSH; } const char* GetStr(); bool Empty() const { return start == end; } private: enum { NEEDS_FLUSH = 0x100 }; // After parsing, if *end != 0, it can be set to zero. int flags; char* start; char* end; }; class XMLBase { public: XMLBase() {} virtual ~XMLBase() {} protected: static const char* SkipWhiteSpace( const char* p ) { while( isspace( *p ) ) { ++p; } return p; } static char* SkipWhiteSpace( char* p ) { while( isspace( *p ) ) { ++p; } return p; } inline static bool StringEqual( const char* p, const char* q, int nChar=INT_MAX ) { int n = 0; if ( p == q ) { return true; } while( *p && *q && *p == *q && n 0 }; class StringPtrStack { public: StringPtrStack(); ~StringPtrStack(); void Push( const char* str ); const char* Pop(); int NumPositive() const { return nPositive; } private: enum { INIT=10 // fixme, super small for testing }; char** mem; char* pool[INIT]; int inUse; int allocated; // bytes allocated int nPositive; // number of non-null pointers }; class XMLStreamer { public: XMLStreamer( FILE* file ); ~XMLStreamer() {} void OpenElement( const char* name, bool textParent ); void PushAttribute( const char* name, const char* value ); void CloseElement(); void PushText( const char* text ); void PushComment( const char* comment ); private: void SealElement(); void PrintSpace( int depth ); void PrintString( const char* ); // prints out, after detecting entities. FILE* fp; int depth; bool elementJustOpened; enum { ENTITY_RANGE = 64 }; bool entityFlag[ENTITY_RANGE]; StringPtrStack stack; StringStack text; }; }; // tinyxml2 #endif // TINYXML2_INCLUDED