24 #ifndef TINYXML2_INCLUDED
25 #define TINYXML2_INCLUDED
27 #if defined(ANDROID_NDK) || defined(__BORLANDC__) || defined(__QNXNTO__)
56 #if defined( _DEBUG ) || defined( DEBUG ) || defined (__DEBUG__)
63 # pragma warning(push)
64 # pragma warning(disable: 4251)
68 # ifdef TINYXML2_EXPORT
69 # define TINYXML2_LIB __declspec(dllexport)
70 # elif defined(TINYXML2_IMPORT)
71 # define TINYXML2_LIB __declspec(dllimport)
76 # define TINYXML2_LIB __attribute__((visibility("default")))
83 # if defined(_MSC_VER)
84 # // "(void)0," is for suppressing C4127 warning in "assert(false)", "assert(true)" and the like
85 # define TIXMLASSERT( x ) if ( !((void)0,(x))) { __debugbreak(); }
86 # elif defined (ANDROID_NDK)
87 # include <android/log.h>
88 # define TIXMLASSERT( x ) if ( !(x)) { __android_log_assert( "assert", "grinliz", "ASSERT in '%s' at %d.", __FILE__, __LINE__ ); }
91 # define TIXMLASSERT assert
94 # define TIXMLASSERT( x ) {}
112 class XMLDeclaration;
161 void SetStr(
const char*
str,
int flags=0 );
163 char*
ParseText(
char*
in,
const char* endTag,
int strFlags );
191 template <
class T,
int INITIAL_SIZE_XML>
285 int newAllocated = cap * 2;
286 T* newMem =
new T[newAllocated];
314 virtual void*
Alloc() = 0;
315 virtual void Free(
void* ) = 0;
317 virtual void Clear() = 0;
324 template<
int ITEM_SIZE >
356 Block* block =
new Block();
359 Item* blockItems = block->items;
361 blockItems[
i].next = &(blockItems[
i + 1]);
363 blockItems[ITEMS_PER_BLOCK - 1].next = 0;
379 virtual void Free(
void* mem ) {
384 Item* item =
static_cast<Item*
>( mem );
386 memset( item, 0xfe,
sizeof( *item ) );
392 printf(
"Mempool %s watermark=%d [%dk] current=%d size=%d nAlloc=%d blocks=%d\n",
535 while( IsWhiteSpace(*p) ) {
542 return const_cast<char*
>( SkipWhiteSpace( const_cast<const char*>(p) ) );
548 return !IsUTF8Continuation(p) && isspace( static_cast<unsigned char>(p) );
556 if ( isalpha( ch ) ) {
559 return ch ==
':' || ch ==
'_';
563 return IsNameStartChar( ch )
569 inline static bool StringEqual(
const char*
p,
const char* q,
int nChar=INT_MAX ) {
576 return strncmp( p, q, nChar ) == 0;
580 return ( p & 0x80 ) != 0;
583 static const char* ReadBOM(
const char*
p,
bool* hasBOM );
586 static const char* GetCharacterRef(
const char*
p,
char*
value,
int*
length );
587 static void ConvertUTF32ToUTF8(
unsigned long input,
char*
output,
int*
length );
590 static void ToStr(
int v,
char*
buffer,
int bufferSize );
591 static void ToStr(
unsigned v,
char*
buffer,
int bufferSize );
592 static void ToStr(
bool v,
char*
buffer,
int bufferSize );
593 static void ToStr(
float v,
char*
buffer,
int bufferSize );
594 static void ToStr(
double v,
char*
buffer,
int bufferSize );
595 static void ToStr(int64_t
v,
char*
buffer,
int bufferSize);
598 static bool ToInt(
const char*
str,
int*
value );
599 static bool ToUnsigned(
const char*
str,
unsigned*
value );
600 static bool ToBool(
const char*
str,
bool*
value );
601 static bool ToFloat(
const char*
str,
float*
value );
602 static bool ToDouble(
const char*
str,
double*
value );
603 static bool ToInt64(
const char*
str, int64_t*
value);
702 const char*
Value()
const;
707 void SetValue(
const char* val,
bool staticMem=
false );
735 const XMLElement* FirstChildElement(
const char*
name = 0 )
const;
769 const XMLElement* PreviousSiblingElement(
const char*
name = 0 )
const ;
785 const XMLElement* NextSiblingElement(
const char*
name = 0 )
const;
801 return InsertEndChild( addThis );
824 void DeleteChildren();
872 virtual bool Accept(
XMLVisitor* visitor )
const = 0;
892 virtual char* ParseDeep(
char*,
StrPair* );
910 void InsertChildPreamble(
XMLNode* insertThis )
const;
934 virtual bool Accept(
XMLVisitor* visitor )
const;
959 char* ParseDeep(
char*,
StrPair* endTag );
981 virtual bool Accept(
XMLVisitor* visitor )
const;
990 char* ParseDeep(
char*,
StrPair* endTag );
1020 virtual bool Accept(
XMLVisitor* visitor )
const;
1029 char* ParseDeep(
char*,
StrPair* endTag );
1055 virtual bool Accept(
XMLVisitor* visitor )
const;
1064 char* ParseDeep(
char*,
StrPair* endTag );
1084 const char* Name()
const;
1087 const char*
Value()
const;
1106 QueryInt64Value(&i);
1113 QueryUnsignedValue( &i );
1119 QueryBoolValue( &b );
1125 QueryDoubleValue( &d );
1131 QueryFloatValue( &f );
1152 void SetAttribute(
const char*
value );
1154 void SetAttribute(
int value );
1156 void SetAttribute(
unsigned value );
1158 void SetAttribute(int64_t
value);
1160 void SetAttribute(
bool value );
1162 void SetAttribute(
double value );
1164 void SetAttribute(
float value );
1167 enum { BUF_SIZE = 200 };
1176 char* ParseDeep(
char*
p,
bool processEntities );
1208 virtual bool Accept(
XMLVisitor* visitor )
const;
1233 const char* Attribute(
const char*
name,
const char*
value=0 )
const;
1241 int IntAttribute(
const char*
name,
int defaultValue = 0)
const;
1243 unsigned UnsignedAttribute(
const char*
name,
unsigned defaultValue = 0)
const;
1245 int64_t Int64Attribute(
const char*
name, int64_t defaultValue = 0)
const;
1247 bool BoolAttribute(
const char*
name,
bool defaultValue =
false)
const;
1249 double DoubleAttribute(
const char*
name,
double defaultValue = 0)
const;
1251 float FloatAttribute(
const char*
name,
float defaultValue = 0)
const;
1336 return QueryIntAttribute( name, value );
1340 return QueryUnsignedAttribute( name, value );
1344 return QueryInt64Attribute(name, value);
1348 return QueryBoolAttribute( name, value );
1352 return QueryDoubleAttribute( name, value );
1356 return QueryFloatAttribute( name, value );
1400 void DeleteAttribute(
const char*
name );
1404 return _rootAttribute;
1437 const char* GetText()
const;
1473 void SetText(
const char* inText );
1475 void SetText(
int value );
1477 void SetText(
unsigned value );
1479 void SetText(int64_t
value);
1481 void SetText(
bool value );
1483 void SetText(
double value );
1485 void SetText(
float value );
1513 XMLError QueryIntText(
int* ival )
const;
1515 XMLError QueryUnsignedText(
unsigned* uval )
const;
1517 XMLError QueryInt64Text(int64_t* uval)
const;
1519 XMLError QueryBoolText(
bool* bval )
const;
1521 XMLError QueryDoubleText(
double* dval )
const;
1523 XMLError QueryFloatText(
float* fval )
const;
1525 int IntText(
int defaultValue = 0)
const;
1528 unsigned UnsignedText(
unsigned defaultValue = 0)
const;
1530 int64_t Int64Text(int64_t defaultValue = 0)
const;
1532 bool BoolText(
bool defaultValue =
false)
const;
1534 double DoubleText(
double defaultValue = 0)
const;
1536 float FloatText(
float defaultValue = 0)
const;
1545 return _closingType;
1551 char* ParseDeep(
char*
p,
StrPair* endTag );
1564 char* ParseAttributes(
char*
p );
1565 static void DeleteAttribute(
XMLAttribute* attribute );
1568 enum { BUF_SIZE = 200 };
1615 XMLError Parse(
const char* xml,
size_t nBytes=(
size_t)(-1) );
1651 XMLError SaveFile( FILE* fp,
bool compact =
false );
1654 return _processEntities;
1676 return FirstChildElement();
1679 return FirstChildElement();
1697 virtual bool Accept(
XMLVisitor* visitor )
const;
1742 void SetError(
XMLError error,
const char* str1,
const char* str2 );
1756 const char* ErrorName()
const;
1760 return _errorStr1.GetStr();
1764 return _errorStr2.GetStr();
1767 void PrintError()
const;
1883 return XMLHandle( _node ? _node->FirstChild() : 0 );
1887 return XMLHandle( _node ? _node->FirstChildElement(
name ) : 0 );
1891 return XMLHandle( _node ? _node->LastChild() : 0 );
1895 return XMLHandle( _node ? _node->LastChildElement(
name ) : 0 );
1899 return XMLHandle( _node ? _node->PreviousSibling() : 0 );
1903 return XMLHandle( _node ? _node->PreviousSiblingElement(
name ) : 0 );
1907 return XMLHandle( _node ? _node->NextSibling() : 0 );
1911 return XMLHandle( _node ? _node->NextSiblingElement(
name ) : 0 );
1920 return ( _node ? _node->ToElement() : 0 );
1924 return ( _node ? _node->ToText() : 0 );
1928 return ( _node ? _node->ToUnknown() : 0 );
1932 return ( _node ? _node->ToDeclaration() : 0 );
1992 return ( _node ? _node->ToElement() : 0 );
1995 return ( _node ? _node->ToText() : 0 );
1998 return ( _node ? _node->ToUnknown() : 0 );
2001 return ( _node ? _node->ToDeclaration() : 0 );
2064 void PushHeader(
bool writeBOM,
bool writeDeclaration );
2068 void OpenElement(
const char*
name,
bool compactMode=
false );
2070 void PushAttribute(
const char*
name,
const char*
value );
2071 void PushAttribute(
const char*
name,
int value );
2072 void PushAttribute(
const char*
name,
unsigned value );
2073 void PushAttribute(
const char*
name, int64_t
value);
2074 void PushAttribute(
const char*
name,
bool value );
2075 void PushAttribute(
const char*
name,
double value );
2077 virtual void CloseElement(
bool compactMode=
false );
2080 void PushText(
const char*
text,
bool cdata=
false );
2082 void PushText(
int value );
2084 void PushText(
unsigned value );
2086 void PushText(int64_t
value);
2088 void PushText(
bool value );
2090 void PushText(
float value );
2092 void PushText(
double value );
2095 void PushComment(
const char*
comment );
2097 void PushDeclaration(
const char*
value );
2098 void PushUnknown(
const char*
value );
2111 virtual bool Visit(
const XMLUnknown& unknown );
2118 return _buffer.Mem();
2126 return _buffer.Size();
2143 virtual void PrintSpace(
int depth );
2146 void SealElementIfJustOpened();
2151 void PrintString(
const char*,
bool restrictedEntitySet );
2164 bool _entityFlag[ENTITY_RANGE];
2165 bool _restrictedEntityFlag[ENTITY_RANGE];
2173 #if defined(_MSC_VER)
2174 # pragma warning(pop)
2177 #endif // TINYXML2_INCLUDED