24 #ifndef TINYXML2_INCLUDED
25 #define TINYXML2_INCLUDED
50 #if defined( _DEBUG ) || defined( DEBUG ) || defined (__DEBUG__)
59 #define TIXMLASSERT( x ) if ( !(x)) { __debugbreak(); } //if ( !(x)) WinDebugBreak()
60 #elif defined (ANDROID_NDK)
61 #include <android/log.h>
62 #define TIXMLASSERT( x ) if ( !(x)) { __android_log_assert( "assert", "grinliz", "ASSERT in '%s' at %d.", __FILE__, __LINE__ ); }
65 #define TIXMLASSERT assert
68 #define TIXMLASSERT( x ) {}
72 #if defined(_MSC_VER) && (_MSC_VER >= 1400 )
81 inline int TIXML_SNPRINTF(
char* buffer,
size_t size,
const char* format, ... ) {
83 va_start( va, format );
84 int result = vsnprintf_s( buffer, size, _TRUNCATE, format, va );
88 #define TIXML_SSCANF sscanf_s
92 #define TIXML_SNPRINTF snprintf
93 #define TIXML_SSCANF sscanf
96 static const int TIXML2_MAJOR_VERSION = 1;
97 static const int TIXML2_MINOR_VERSION = 0;
98 static const int TIXML2_PATCH_VERSION = 8;
138 void Set(
char* _start,
char* _end,
int _flags ) {
148 char*
ParseText(
char* in,
const char* endTag,
int strFlags );
173 template <
class T,
int INIT>
223 int newAllocated = cap * 2;
224 T* newMem =
new T[newAllocated];
225 memcpy( newMem,
mem,
sizeof(T)*
size );
250 virtual void*
Alloc() = 0;
251 virtual void Free(
void* ) = 0;
265 for(
int i=0; i<
blockPtrs.Size(); ++i ) {
276 Block* block =
new Block();
279 for(
int i=0; i<
COUNT-1; ++i ) {
280 block->chunk[i].next = &block->chunk[i+1];
282 block->chunk[COUNT-1].next = 0;
293 virtual void Free(
void* mem ) {
296 Chunk* chunk = (Chunk*)mem;
298 memset( chunk, 0xfe,
sizeof(Chunk) );
304 printf(
"Mempool %s watermark=%d [%dk] current=%d size=%d nAlloc=%d blocks=%d\n",
384 inline static bool StringEqual(
const char* p,
const char* q,
int nChar=INT_MAX ) {
389 while( *p && *q && *p == *q && n<nChar ) {
392 if ( (n == nChar) || ( *p == 0 && *q == 0 ) ) {
398 inline static int IsAlphaNum(
unsigned char anyByte ) {
return ( anyByte < 128 ) ? isalnum( anyByte ) : 1; }
399 inline static int IsAlpha(
unsigned char anyByte ) {
return ( anyByte < 128 ) ? isalpha( anyByte ) : 1; }
401 static const char*
ReadBOM(
const char* p,
bool* hasBOM );
404 static const char*
GetCharacterRef(
const char* p,
char* value,
int* length );
408 static void ToStr(
int v,
char* buffer,
int bufferSize );
409 static void ToStr(
unsigned v,
char* buffer,
int bufferSize );
410 static void ToStr(
bool v,
char* buffer,
int bufferSize );
411 static void ToStr(
float v,
char* buffer,
int bufferSize );
412 static void ToStr(
double v,
char* buffer,
int bufferSize );
415 static bool ToInt(
const char* str,
int* value );
416 static bool ToUnsigned(
const char* str,
unsigned* value );
417 static bool ToBool(
const char* str,
bool* value );
418 static bool ToFloat(
const char* str,
float* value );
419 static bool ToDouble(
const char* str,
double* value );
486 void SetValue(
const char* val,
bool staticMem=
false );
842 char*
ParseDeep(
char* p,
bool processEntities );
892 const char*
Attribute(
const char* name,
const char*
value=0 )
const;
1081 int Parse(
const char* xml,
size_t nBytes=(
size_t)(-1) );
1088 int LoadFile(
const char* filename );
1104 int SaveFile(
const char* filename,
bool compact =
false );
1113 int SaveFile( FILE* fp,
bool compact =
false );
1192 void SetError(
int error,
const char* str1,
const char* str2 );
1416 XMLPrinter( FILE* file=0,
bool compact =
false );
1420 void PushHeader(
bool writeBOM,
bool writeDeclaration );
1435 void PushText(
const char* text,
bool cdata=
false );
1479 void PrintString(
const char*,
bool restrictedEntitySet );
1480 void Print(
const char* format, ... );
1508 #endif // TINYXML2_INCLUDED
static char * SkipWhiteSpace(char *p)
void PushComment(const char *comment)
Add a comment.
const char * Attribute(const char *name, const char *value=0) const
XMLConstHandle(const XMLNode &_node)
virtual const XMLUnknown * ToUnknown() const
XMLNode * InsertFirstChild(XMLNode *addThis)
virtual bool Accept(XMLVisitor *visitor) const
static bool ToFloat(const char *str, float *value)
virtual bool ShallowEqual(const XMLNode *compare) const
XMLDeclaration(XMLDocument *doc)
int QueryUnsignedValue(unsigned int *value) const
See QueryIntAttribute.
const XMLConstHandle FirstChild() const
int QueryBoolValue(bool *value) const
See QueryIntAttribute.
const XMLUnknown * ToUnknown() const
XMLHandle LastChild()
Get the last child of this handle.
virtual int ItemSize() const =0
virtual void Free(void *)=0
virtual const XMLDeclaration * ToDeclaration() const
virtual const XMLDeclaration * ToDeclaration() const
void SetName(const char *str, bool staticMem=false)
Set the name of the element.
const XMLElement * PreviousSiblingElement(const char *value=0) const
Get the previous (left) sibling element of this node, with an opitionally supplied name...
XMLHandle LastChildElement(const char *_value=0)
Get the last child element of this handle.
void SetAttribute(const char *name, unsigned _value)
Sets the named attribute to value.
void Unlink(XMLNode *child)
DynArray< char, 20 > buffer
virtual ~XMLDeclaration()
MemPoolT< sizeof(XMLText) > textPool
virtual XMLText * ToText()
Safely cast to Text, or null.
const char * Value() const
The value of the attribute.
virtual bool VisitEnter(const XMLElement &, const XMLAttribute *)
Visit an element.
int QueryUnsignedAttribute(const char *name, unsigned int *_value) const
See QueryIntAttribute()
XMLNode & operator=(const XMLNode &)
XMLHandle FirstChildElement(const char *value=0)
Get the first child element of this handle.
XMLText & operator=(const XMLText &)
virtual bool VisitExit(const XMLElement &)
Visit an element.
const XMLNode * PreviousSibling() const
Get the previous (left) sibling node of this node.
XMLDeclaration & operator=(const XMLDeclaration &)
const XMLAttribute * Next() const
The next attribute in the list.
static void ConvertUTF32ToUTF8(unsigned long input, char *output, int *length)
char * ParseDeep(char *, StrPair *endTag)
const XMLElement * ToElement() const
void DeleteChild(XMLNode *node)
void Set(char *_start, char *_end, int _flags)
static bool StringEqual(const char *p, const char *q, int nChar=INT_MAX)
char * ParseDeep(char *, StrPair *endTag)
XMLConstHandle(const XMLNode *_node)
XMLComment & operator=(const XMLComment &)
virtual const XMLText * ToText() const
virtual void Free(void *mem)
virtual const XMLDocument * ToDocument() const
void SetAttribute(const char *name, double _value)
Sets the named attribute to value.
const char * GetErrorStr1() const
Return a possibly helpful diagnostic location or string.
void DeleteNode(XMLNode *node)
void Trace(const char *name)
XMLElement(XMLDocument *doc)
virtual int ItemSize() const
MemPoolT< sizeof(XMLElement) > elementPool
XMLHandle NextSibling()
Get the next sibling of this handle.
float FloatAttribute(const char *name) const
See IntAttribute()
virtual XMLText * ToText()
Safely cast to Text, or null.
char * ParseText(char *in, const char *endTag, int strFlags)
XMLElement * ToElement()
Safe cast to XMLElement. This can return null.
XMLHandle(XMLNode &_node)
Create a handle from a node.
const char * GetErrorStr2() const
Return a possibly helpful secondary diagnostic location or string.
static void ToStr(int v, char *buffer, int bufferSize)
XMLComment * NewComment(const char *comment)
bool CData() const
Returns true if this is a CDATA text element.
int QueryIntAttribute(const char *name, int *_value) const
XMLHandle NextSiblingElement(const char *_value=0)
Get the next sibling element of this handle.
virtual bool Visit(const XMLUnknown &)
Visit an unknown node.
const XMLNode * ToNode() const
virtual XMLDocument * ToDocument()
Safely cast to a Document, or null.
const XMLConstHandle NextSibling() const
const XMLElement * LastChildElement(const char *value=0) const
static bool IsWhiteSpace(char p)
virtual XMLUnknown * ToUnknown()
Safely cast to an Unknown, or null.
XMLConstHandle(const XMLConstHandle &ref)
char * ParseDeep(char *p, StrPair *endTag)
const XMLDeclaration * ToDeclaration() const
XMLAttribute * rootAttribute
const XMLConstHandle NextSiblingElement(const char *_value=0) const
const XMLConstHandle PreviousSiblingElement(const char *_value=0) const
virtual XMLNode * ShallowClone(XMLDocument *document) const
virtual bool Accept(XMLVisitor *visitor) const
virtual const XMLText * ToText() const
int QueryFloatText(float *_value) const
See QueryIntText()
int Parse(const char *xml, size_t nBytes=(size_t)(-1))
const XMLElement * RootElement() const
DynArray< Block *, 10 > blockPtrs
int ErrorID() const
Return the errorID.
const char * Name() const
Get the name of an element (which is the Value() of the node.)
int LoadFile(const char *filename)
void PushUnknown(const char *value)
XMLElement * PreviousSiblingElement(const char *_value=0)
XMLElement * NewElement(const char *name)
bool Error() const
Return true if there was an error parsing the document.
int QueryFloatAttribute(const char *name, float *_value) const
See QueryIntAttribute()
const XMLNode * NextSibling() const
Get the next (right) sibling node of this node.
static bool ToDouble(const char *str, double *value)
XMLConstHandle & operator=(const XMLConstHandle &ref)
XMLNode * InsertAfterChild(XMLNode *afterThis, XMLNode *addThis)
int QueryIntValue(int *value) const
void DeleteAttribute(const char *name)
virtual bool ShallowEqual(const XMLNode *compare) const
virtual XMLNode * ShallowClone(XMLDocument *) const
char * ParseName(char *in)
void operator=(const XMLAttribute &)
virtual XMLNode * ShallowClone(XMLDocument *document) const
virtual bool Accept(XMLVisitor *visitor) const
void Print(const char *format,...)
char * ParseDeep(char *, StrPair *endTag)
virtual bool VisitEnter(const XMLDocument &)
Visit a document.
int QueryDoubleAttribute(const char *name, double *_value) const
See QueryIntAttribute()
virtual bool Visit(const XMLComment &)
Visit a comment node.
virtual XMLElement * ToElement()
Safely cast to an Element, or null.
bool BoolValue() const
Query as a boolean. See IntAttribute()
const XMLElement * NextSiblingElement(const char *value=0) const
Get the next (right) sibling element of this node, with an opitionally supplied name.
static int IsAlpha(unsigned char anyByte)
XMLElement * LastChildElement(const char *_value=0)
int IntAttribute(const char *name) const
const XMLAttribute * FirstAttribute() const
Return the first attribute in the list.
XMLDeclaration * NewDeclaration(const char *text=0)
virtual XMLDeclaration * ToDeclaration()
Safely cast to a Declaration, or null.
int QueryBoolAttribute(const char *name, bool *_value) const
See QueryIntAttribute()
void operator=(const XMLDocument &)
void SetName(const char *name)
virtual bool Visit(const XMLDeclaration &)
Visit a declaration.
char * ParseAttributes(char *p)
virtual bool Accept(XMLVisitor *visitor) const
XMLAttribute * FindOrCreateAttribute(const char *name)
int QueryIntText(int *_value) const
const XMLDocument * GetDocument() const
Get the XMLDocument that owns this XMLNode.
virtual bool ShallowEqual(const XMLNode *compare) const
double DoubleAttribute(const char *name) const
See IntAttribute()
void PushAttribute(const char *name, const char *value)
If streaming, add an attribute to an open element.
void PushDeclaration(const char *value)
virtual XMLDocument * ToDocument()
Safely cast to a Document, or null.
char * ParseDeep(char *, StrPair *endTag)
XMLElement * RootElement()
XMLPrinter(FILE *file=0, bool compact=false)
static const char * GetCharacterRef(const char *p, char *value, int *length)
const XMLNode * LastChild() const
Get the last child node, or null if none exists.
virtual bool Accept(XMLVisitor *visitor) const
XMLNode * InsertEndChild(XMLNode *addThis)
virtual const XMLUnknown * ToUnknown() const
static const char * SkipWhiteSpace(const char *p)
void SetError(int error, const char *str1, const char *str2)
void SetCData(bool _isCData)
Declare whether this should be CDATA or standard text.
void operator=(const XMLElement &)
virtual bool ShallowEqual(const XMLNode *compare) const =0
const XMLConstHandle PreviousSibling() const
void SetStr(const char *str, int flags=0)
void SetAttribute(const char *name, int _value)
Sets the named attribute to value.
virtual XMLComment * ToComment()
Safely cast to a Comment, or null.
virtual const XMLDocument * ToDocument() const
void Print(XMLPrinter *streamer=0)
const XMLAttribute * FindAttribute(const char *name) const
Query a specific attribute in the list.
XMLUnknown & operator=(const XMLUnknown &)
const XMLElement * FirstChildElement(const char *value=0) const
XMLUnknown * ToUnknown()
Safe cast to XMLUnknown. This can return null.
virtual XMLNode * ShallowClone(XMLDocument *document) const
void SetAttribute(const char *name, bool _value)
Sets the named attribute to value.
void SetInternedStr(const char *str)
void SetValue(const char *val, bool staticMem=false)
const char * CStr() const
bool restrictedEntityFlag[ENTITY_RANGE]
static int IsAlphaNum(unsigned char anyByte)
MemPoolT< sizeof(XMLComment) > commentPool
XMLComment(XMLDocument *doc)
int QueryDoubleText(double *_value) const
See QueryIntText()
virtual bool Visit(const XMLText &text)
Visit a text node.
virtual const XMLComment * ToComment() const
virtual char * ParseDeep(char *, StrPair *)
virtual XMLElement * ToElement()
Safely cast to an Element, or null.
void EnsureCapacity(int cap)
virtual const XMLComment * ToComment() const
void PushHeader(bool writeBOM, bool writeDeclaration)
XMLHandle PreviousSibling()
Get the previous sibling of this handle.
virtual bool VisitExit(const XMLDocument &)
Visit a document.
const char * Value() const
XMLHandle(XMLNode *_node)
Create a handle from any node (at any depth of the tree.) This can be a null pointer.
virtual XMLNode * ShallowClone(XMLDocument *document) const
const T & operator[](int i) const
int SaveFile(const char *filename, bool compact=false)
virtual bool Visit(const XMLText &)
Visit a text node.
XMLUnknown(XMLDocument *doc)
void OpenElement(const char *name)
const char * Name() const
The name of the attribute.
XMLHandle PreviousSiblingElement(const char *_value=0)
Get the previous sibling element of this handle.
bool NoChildren() const
Returns true if this node has no children.
XMLDeclaration * ToDeclaration()
Safe cast to XMLDeclaration. This can return null.
XMLText * ToText()
Safe cast to XMLText. This can return null.
const XMLNode * Parent() const
Get the parent of this node on the DOM.
const XMLConstHandle LastChild() const
XMLElement * NextSiblingElement(const char *_value=0)
int CurrentAllocs() const
char * Identify(char *p, XMLNode **node)
XMLElement * FirstChildElement(const char *_value=0)
const XMLText * ToText() const
XMLHandle FirstChild()
Get the first child of this handle.
XMLNode * PreviousSibling()
const XMLConstHandle LastChildElement(const char *_value=0) const
XMLText * NewText(const char *text)
char * ParseDeep(char *p, bool processEntities)
double DoubleValue() const
Query as a double. See IntAttribute()
void SetAttribute(const char *name, const char *_value)
Sets the named attribute to value.
static bool ToUnsigned(const char *str, unsigned *value)
static bool ToBool(const char *str, bool *value)
static const char * ReadBOM(const char *p, bool *hasBOM)
DynArray< const char *, 10 > stack
XMLDocument * GetDocument()
Get the XMLDocument that owns this XMLNode.
MemPoolT< sizeof(XMLAttribute) > attributePool
unsigned UnsignedValue() const
Query as an unsigned integer. See IntAttribute()
const XMLNode * FirstChild() const
Get the first child node, or null if none exists.
XMLUnknown * NewUnknown(const char *text)
const XMLConstHandle FirstChildElement(const char *value=0) const
void CloseElement()
If streaming, close the Element.
const char * GetText() const
virtual XMLDeclaration * ToDeclaration()
Safely cast to a Declaration, or null.
XMLNode * ToNode()
Safe cast to XMLNode. This can return null.
static int IsUTF8Continuation(const char p)
float FloatValue() const
Query as a float. See IntAttribute()
bool BoolAttribute(const char *name) const
See IntAttribute()
virtual XMLNode * ShallowClone(XMLDocument *document) const
int QueryFloatValue(float *value) const
See QueryIntAttribute.
virtual bool ShallowEqual(const XMLNode *compare) const
virtual bool VisitEnter(const XMLDocument &)
Visit a document.
int QueryDoubleValue(double *value) const
See QueryIntAttribute.
virtual bool Accept(XMLVisitor *visitor) const
int QueryBoolText(bool *_value) const
See QueryIntText()
virtual XMLUnknown * ToUnknown()
Safely cast to an Unknown, or null.
XMLDocument(bool processEntities=true, Whitespace=PRESERVE_WHITESPACE)
constructor
int QueryUnsignedText(unsigned *_value) const
See QueryIntText()
void PrintString(const char *, bool restrictedEntitySet)
void PrintError() const
If there is an error, print it to stdout.
void CollapseWhitespace()
static bool ToInt(const char *str, int *value)
Whitespace WhitespaceMode() const
void PrintSpace(int depth)
virtual bool ShallowEqual(const XMLNode *compare) const
XMLText(XMLDocument *doc)
virtual bool VisitExit(const XMLDocument &)
Visit a document.
unsigned UnsignedAttribute(const char *name) const
See IntAttribute()
virtual const XMLElement * ToElement() const
XMLHandle(const XMLHandle &ref)
Copy constructor.
bool entityFlag[ENTITY_RANGE]
XMLNode * LinkEndChild(XMLNode *addThis)
virtual const XMLElement * ToElement() const
bool ProcessEntities() const
void SetAttribute(const char *value)
Set the attribute to a string value.
void PushText(const char *text, bool cdata=false)
Add a text node.
virtual bool ShallowEqual(const XMLNode *) const
virtual XMLNode * ShallowClone(XMLDocument *document) const =0
virtual XMLComment * ToComment()
Safely cast to a Comment, or null.
virtual bool Accept(XMLVisitor *visitor) const =0
XMLHandle & operator=(const XMLHandle &ref)
Assignment.