tinyxml2.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #ifndef TINYXML2_INCLUDED
  2. #define TINYXML2_INCLUDED
  3. #include <limits.h>
  4. #if defined( _DEBUG ) || defined( DEBUG ) || defined (__DEBUG__)
  5. #ifndef DEBUG
  6. #define DEBUG
  7. #endif
  8. #endif
  9. #if defined(DEBUG)
  10. #if defined(_MSC_VER)
  11. #define TIXMLASSERT( x ) if ( !(x)) { _asm { int 3 } } //if ( !(x)) WinDebugBreak()
  12. #elif defined (ANDROID_NDK)
  13. #include <android/log.h>
  14. #define TIXMLASSERT( x ) if ( !(x)) { __android_log_assert( "assert", "grinliz", "ASSERT in '%s' at %d.", __FILE__, __LINE__ ); }
  15. #else
  16. #include <assert.h>
  17. #define TIXMLASSERT assert
  18. #endif
  19. #else
  20. #define TIXMLASSERT( x ) {}
  21. #endif
  22. namespace tinyxml2
  23. {
  24. class XMLDocument*;
  25. // internal - move to separate namespace
  26. struct CharBuffer
  27. {
  28. size_t length;
  29. char mem[1];
  30. static CharBuffer* Construct( const char* in );
  31. static void Free( CharBuffer* );
  32. };
  33. class XMLNode
  34. {
  35. friend class XMLDocument;
  36. public:
  37. static XMLNode* Identify( const char* p );
  38. protected:
  39. XMLNode( XMLDocument* );
  40. virtual ~XMLNode();
  41. // Utility
  42. static const char* SkipWhiteSpace( const char* p ) { while( isspace( *p ) ) { ++p; } return p; }
  43. static char* SkipWhiteSpace( char* p ) { while( isspace( *p ) ) { ++p; } return p; }
  44. inline static bool StringEqual( const char* p, const char* q, int nChar=INT_MAX ) {
  45. int n = 0;
  46. while( *p && *q && *p == *q && n<nChar ) {
  47. ++p; ++q; ++n;
  48. }
  49. if ( (n == nChar) || ( *p == 0 && *q == 0 ) ) {
  50. return true;
  51. }
  52. return false;
  53. }
  54. /* Parses text. (Not a text node.)
  55. - [ ] EOL normalization.
  56. - [x] Trim leading whitespace
  57. - [ ] Trim trailing whitespace.
  58. - [ ] Leaves inner whitespace
  59. - [ ] Inserts one space between lines.
  60. */
  61. const char* ParseText( char* in, const char* endTag, char** next );
  62. virtual char* ParseDeep( char* ) { TIXMLASSERT( 0 ); }
  63. XMLDocument* document;
  64. XMLNode* parent;
  65. XMLNode* firstChild;
  66. XMLNode* lastChild;
  67. XMLNode* prev;
  68. XMLNode* next;
  69. private:
  70. };
  71. class XMLComment : public XMLNode
  72. {
  73. public:
  74. XMLComment( XMLDocument* doc );
  75. virtual ~XMLComment();
  76. private:
  77. char* value;
  78. };
  79. class XMLDocument
  80. {
  81. public:
  82. XMLDocument();
  83. ~XMLDocument();
  84. bool Parse( const char* );
  85. XMLNode* Root() { return root; }
  86. XMLNode* RootElement();
  87. XMLNode* InsertEndChild( XMLNode* addThis );
  88. private:
  89. XMLDocument( const XMLDocument& ); // intentionally not implemented
  90. virtual char* ParseDeep( char* );
  91. XMLNode* root;
  92. CharBuffer* charBuffer;
  93. };
  94. }; // tinyxml2
  95. #endif // TINYXML2_INCLUDED