24 #ifndef TINYXML2_INCLUDED
25 #define TINYXML2_INCLUDED
27 #if defined(ANDROID_NDK) || defined(__BORLANDC__)
54 #if defined( _DEBUG ) || defined( DEBUG ) || defined (__DEBUG__)
62 # if defined(_MSC_VER)
63 # define TIXMLASSERT( x ) if ( !(x)) { __debugbreak(); } //if ( !(x)) WinDebugBreak()
64 # elif defined (ANDROID_NDK)
65 # include <android/log.h>
66 # define TIXMLASSERT( x ) if ( !(x)) { __android_log_assert( "assert", "grinliz", "ASSERT in '%s' at %d.", __FILE__, __LINE__ ); }
69 # define TIXMLASSERT assert
72 # define TIXMLASSERT( x ) {}
76 #if defined(_MSC_VER) && (_MSC_VER >= 1400 )
85 inline int TIXML_SNPRINTF(
char* buffer,
size_t size,
const char* format, ... )
88 va_start( va, format );
89 int result = vsnprintf_s( buffer, size, _TRUNCATE, format, va );
93 #define TIXML_SSCANF sscanf_s
97 #define TIXML_SNPRINTF snprintf
98 #define TIXML_SSCANF sscanf
113 class XMLDeclaration;
143 void Set(
char* start,
char* end,
int flags ) {
158 _start =
const_cast<char*
>(str);
161 void SetStr(
const char* str,
int flags=0 );
163 char*
ParseText(
char* in,
const char* endTag,
int strFlags );
187 template <
class T,
int INIT>
257 int newAllocated = cap * 2;
258 T* newMem =
new T[newAllocated];
286 virtual void*
Alloc() = 0;
287 virtual void Free(
void* ) = 0;
317 Block* block =
new Block();
320 for(
int i=0; i<
COUNT-1; ++i ) {
321 block->chunk[i].next = &block->chunk[i+1];
323 block->chunk[COUNT-1].next = 0;
324 _root = block->chunk;
326 void* result =
_root;
337 virtual void Free(
void* mem ) {
342 Chunk* chunk = (Chunk*)mem;
344 memset( chunk, 0xfe,
sizeof(Chunk) );
350 printf(
"Mempool %s watermark=%d [%dk] current=%d size=%d nAlloc=%d blocks=%d\n",
453 while( !
IsUTF8Continuation(*p) && isspace( *reinterpret_cast<const unsigned char*>(p) ) ) {
468 inline static bool StringEqual(
const char* p,
const char* q,
int nChar=INT_MAX ) {
473 while( *p && *q && *p == *q && n<nChar ) {
478 if ( (n == nChar) || ( *p == 0 && *q == 0 ) ) {
487 return ( anyByte < 128 ) ? isalnum( anyByte ) : 1;
489 inline static int IsAlpha(
unsigned char anyByte ) {
490 return ( anyByte < 128 ) ? isalpha( anyByte ) : 1;
493 static const char*
ReadBOM(
const char* p,
bool* hasBOM );
496 static const char*
GetCharacterRef(
const char* p,
char* value,
int* length );
500 static void ToStr(
int v,
char* buffer,
int bufferSize );
501 static void ToStr(
unsigned v,
char* buffer,
int bufferSize );
502 static void ToStr(
bool v,
char* buffer,
int bufferSize );
503 static void ToStr(
float v,
char* buffer,
int bufferSize );
504 static void ToStr(
double v,
char* buffer,
int bufferSize );
507 static bool ToInt(
const char* str,
int* value );
508 static bool ToUnsigned(
const char* str,
unsigned* value );
509 static bool ToBool(
const char* str,
bool* value );
510 static bool ToFloat(
const char* str,
float* value );
511 static bool ToDouble(
const char* str,
double* value );
615 void SetValue(
const char* val,
bool staticMem=
false );
1060 void SetName(
const char* name );
1062 char*
ParseDeep(
char* p,
bool processEntities );
1085 void SetName(
const char* str,
bool staticMem=
false ) {
1120 const char*
Attribute(
const char* name,
const char* value=0 )
const;
1382 XMLError Parse(
const char* xml,
size_t nBytes=(
size_t)(-1) );
1813 XMLPrinter( FILE* file=0,
bool compact =
false );
1817 void PushHeader(
bool writeBOM,
bool writeDeclaration );
1832 void PushText(
const char* text,
bool cdata=
false );
1882 void PrintString(
const char*,
bool restrictedEntitySet );
1883 void Print(
const char* format, ... );
1911 #endif // TINYXML2_INCLUDED
virtual XMLElement * ToElement()
Safely cast to an Element, or null.
XMLText * NewText(const char *text)
double DoubleAttribute(const char *name) const
See IntAttribute()
virtual bool Visit(const XMLText &text)
Visit a text node.
void SetError(XMLError error, const char *str1, const char *str2)
const XMLDeclaration * ToDeclaration() const
void OpenElement(const char *name)
void CollapseWhitespace()
bool BoolValue() const
Query as a boolean. See IntAttribute()
bool Error() const
Return true if there was an error parsing the document.
const XMLConstHandle FirstChild() const
static void ToStr(int v, char *buffer, int bufferSize)
XMLAttribute * FindOrCreateAttribute(const char *name)
const XMLConstHandle LastChild() const
XMLError QueryIntValue(int *value) const
const XMLText * ToText() const
virtual void Free(void *mem)
static const int TIXML2_PATCH_VERSION
XMLError QueryUnsignedAttribute(const char *name, unsigned int *value) const
See QueryIntAttribute()
virtual const XMLDeclaration * ToDeclaration() const
XMLError Parse(const char *xml, size_t nBytes=(size_t)(-1))
static const char * GetCharacterRef(const char *p, char *value, int *length)
virtual XMLDocument * ToDocument()
Safely cast to a Document, or null.
XMLHandle(XMLNode *node)
Create a handle from any node (at any depth of the tree.) This can be a null pointer.
virtual const XMLComment * ToComment() const
XMLError LoadFile(const char *filename)
void PushComment(const char *comment)
Add a comment.
char * ParseDeep(char *p, StrPair *endTag)
XMLError QueryFloatValue(float *value) const
See QueryIntAttribute.
virtual bool Accept(XMLVisitor *visitor) const
XMLAttribute * _rootAttribute
MemPoolT< sizeof(XMLAttribute) > _attributePool
static const char * SkipWhiteSpace(const char *p)
const T & operator[](int i) const
int CurrentAllocs() const
void SetAttribute(const char *name, unsigned value)
Sets the named attribute to value.
virtual XMLNode * ShallowClone(XMLDocument *document) const =0
__BEGIN_NAMESPACE_STD void * memcpy(void *__restrict __dest, const void *__restrict __src, size_t __n) __THROW __nonnull((1
static bool ToFloat(const char *str, float *value)
virtual XMLComment * ToComment()
Safely cast to a Comment, or null.
char * ParseDeep(char *, StrPair *endTag)
XMLConstHandle & operator=(const XMLConstHandle &ref)
XMLError QueryBoolText(bool *bval) const
See QueryIntText()
virtual const XMLText * ToText() const
virtual bool VisitEnter(const XMLElement &, const XMLAttribute *)
Visit an element.
void PushHeader(bool writeBOM, bool writeDeclaration)
bool CData() const
Returns true if this is a CDATA text element.
void Set(char *start, char *end, int flags)
DynArray< Block *, 10 > _blockPtrs
void Unlink(XMLNode *child)
void PushDeclaration(const char *value)
virtual void Free(void *)=0
void PrintError() const
If there is an error, print it to stdout.
static bool IsWhiteSpace(char p)
XMLHandle LastChildElement(const char *_value=0)
Get the last child element of this handle.
static const char * ReadBOM(const char *p, bool *hasBOM)
char * ParseDeep(char *p, bool processEntities)
const XMLElement * RootElement() const
virtual XMLUnknown * ToUnknown()
Safely cast to an Unknown, or null.
virtual bool Visit(const XMLText &)
Visit a text node.
const XMLAttribute * FindAttribute(const char *name) const
Query a specific attribute in the list.
const XMLNode * FirstChild() const
Get the first child node, or null if none exists.
const char * Name() const
The name of the attribute.
virtual bool ShallowEqual(const XMLNode *) const
static char * SkipWhiteSpace(char *p)
double DoubleValue() const
Query as a double. See IntAttribute()
XMLConstHandle(const XMLNode *node)
XMLNode * PreviousSibling()
static bool ToBool(const char *str, bool *value)
virtual bool VisitExit(const XMLDocument &)
Visit a document.
char * ParseName(char *in)
virtual bool ShallowEqual(const XMLNode *compare) const =0
XMLConstHandle(const XMLNode &node)
void SetAttribute(const char *value)
Set the attribute to a string value.
virtual const XMLText * ToText() const
XMLText & operator=(const XMLText &)
XMLError QueryFloatAttribute(const char *name, float *value) const
See QueryIntAttribute()
virtual const XMLUnknown * ToUnknown() const
const XMLNode * ToNode() const
const XMLConstHandle PreviousSibling() const
virtual XMLText * ToText()
Safely cast to Text, or null.
void Print(const char *format,...)
virtual bool Visit(const XMLComment &)
Visit a comment node.
virtual bool ShallowEqual(const XMLNode *compare) const
int IntAttribute(const char *name) const
XMLHandle LastChild()
Get the last child of this handle.
const char * Value() const
The value of the attribute.
virtual XMLNode * ShallowClone(XMLDocument *) const
void SetAttribute(const char *name, const char *value)
Sets the named attribute to value.
virtual char * ParseDeep(char *, StrPair *)
XMLError QueryDoubleText(double *dval) const
See QueryIntText()
const char * GetErrorStr2() const
Return a possibly helpful secondary diagnostic location or string.
static const int TIXML2_MINOR_VERSION
const XMLUnknown * ToUnknown() const
XMLHandle & operator=(const XMLHandle &ref)
Assignment.
const XMLConstHandle NextSibling() const
XMLElement * NewElement(const char *name)
virtual XMLNode * ShallowClone(XMLDocument *document) const
XMLError QueryDoubleValue(double *value) const
See QueryIntAttribute.
bool ProcessEntities() const
DynArray< char, 20 > _buffer
const XMLConstHandle NextSiblingElement(const char *_value=0) const
XMLError ErrorID() const
Return the errorID.
XMLElement * RootElement()
char * ParseDeep(char *, StrPair *endTag)
static bool ToInt(const char *str, int *value)
void SetName(const char *name)
XMLError SaveFile(const char *filename, bool compact=false)
static bool ToUnsigned(const char *str, unsigned *value)
const XMLNode * Parent() const
Get the parent of this node on the DOM.
void PushText(const char *text, bool cdata=false)
Add a text node.
const XMLAttribute * Next() const
The next attribute in the list.
void operator=(const XMLAttribute &)
XMLError QueryDoubleAttribute(const char *name, double *value) const
See QueryIntAttribute()
const XMLElement * LastChildElement(const char *value=0) const
void SetName(const char *str, bool staticMem=false)
Set the name of the element.
virtual int ItemSize() const
XMLComment * NewComment(const char *comment)
const XMLElement * FirstChildElement(const char *value=0) const
void SetAttribute(const char *name, double value)
Sets the named attribute to value.
static const int TIXML2_MAJOR_VERSION
XMLPrinter(FILE *file=0, bool compact=false)
const char * Value() const
XMLDeclaration & operator=(const XMLDeclaration &)
void DeleteNode(XMLNode *node)
virtual void SetTracked()=0
const char * Attribute(const char *name, const char *value=0) const
virtual bool VisitEnter(const XMLDocument &)
Visit a document.
static bool ToDouble(const char *str, double *value)
MemPoolT< sizeof(XMLComment) > _commentPool
XMLHandle NextSiblingElement(const char *_value=0)
Get the next sibling element of this handle.
const char * GetText() const
XMLError QueryIntText(int *ival) const
bool BoolAttribute(const char *name) const
See IntAttribute()
const XMLConstHandle LastChildElement(const char *_value=0) const
virtual bool VisitExit(const XMLDocument &)
Visit a document.
virtual ~XMLDeclaration()
void SetStr(const char *str, int flags=0)
XMLHandle(XMLNode &node)
Create a handle from a node.
virtual XMLNode * ShallowClone(XMLDocument *document) const
void SetCData(bool isCData)
Declare whether this should be CDATA or standard text.
virtual bool Accept(XMLVisitor *visitor) const
XMLDeclaration(XMLDocument *doc)
XMLDocument * GetDocument()
Get the XMLDocument that owns this XMLNode.
XMLUnknown & operator=(const XMLUnknown &)
XMLNode * InsertFirstChild(XMLNode *addThis)
const XMLDocument * GetDocument() const
Get the XMLDocument that owns this XMLNode.
XMLElement(XMLDocument *doc)
char * ParseAttributes(char *p)
void operator=(const XMLElement &)
virtual XMLDeclaration * ToDeclaration()
Safely cast to a Declaration, or null.
XMLDocument(bool processEntities=true, Whitespace=PRESERVE_WHITESPACE)
constructor
virtual XMLUnknown * ToUnknown()
Safely cast to an Unknown, or null.
char * Identify(char *p, XMLNode **node)
static bool StringEqual(const char *p, const char *q, int nChar=INT_MAX)
virtual bool ShallowEqual(const XMLNode *compare) const
unsigned UnsignedAttribute(const char *name) const
See IntAttribute()
virtual bool VisitExit(const XMLElement &)
Visit an element.
virtual XMLNode * ShallowClone(XMLDocument *document) const
virtual const XMLElement * ToElement() const
virtual bool Visit(const XMLUnknown &)
Visit an unknown node.
void operator=(const XMLDocument &)
XMLConstHandle(const XMLConstHandle &ref)
XMLError QueryFloatText(float *fval) const
See QueryIntText()
const XMLNode * PreviousSibling() const
Get the previous (left) sibling node of this node.
void SetValue(const char *val, bool staticMem=false)
void CloseElement()
If streaming, close the Element.
const XMLConstHandle FirstChildElement(const char *value=0) const
virtual const XMLDeclaration * ToDeclaration() const
XMLNode * LinkEndChild(XMLNode *addThis)
XMLError QueryUnsignedText(unsigned *uval) const
See QueryIntText()
void SetAttribute(const char *name, bool value)
Sets the named attribute to value.
void PushUnknown(const char *value)
const char * GetErrorStr1() const
Return a possibly helpful diagnostic location or string.
static int IsAlphaNum(unsigned char anyByte)
virtual bool Accept(XMLVisitor *visitor) const
void PushAttribute(const char *name, const char *value)
If streaming, add an attribute to an open element.
const XMLElement * NextSiblingElement(const char *value=0) const
Get the next (right) sibling element of this node, with an opitionally supplied name.
DynArray< const char *, 10 > _stack
XMLError QueryIntAttribute(const char *name, int *value) const
static void ConvertUTF32ToUTF8(unsigned long input, char *output, int *length)
XMLNode * ToNode()
Safe cast to XMLNode. This can return null.
void Trace(const char *name)
void DeleteAttribute(const char *name)
XMLHandle NextSibling()
Get the next sibling of this handle.
void PrintString(const char *, bool restrictedEntitySet)
unsigned UnsignedValue() const
Query as an unsigned integer. See IntAttribute()
XMLUnknown(XMLDocument *doc)
XMLError QueryUnsignedValue(unsigned int *value) const
See QueryIntAttribute.
XMLText(XMLDocument *doc)
__BEGIN_NAMESPACE_STD void void __END_NAMESPACE_STD void __BEGIN_NAMESPACE_STD void * memset(void *__s, int __c, size_t __n) __THROW __nonnull((1))
const XMLElement * ToElement() const
virtual bool Accept(XMLVisitor *visitor) const =0
void DeleteChild(XMLNode *node)
virtual XMLText * ToText()
Safely cast to Text, or null.
void SetAttribute(const char *name, int value)
Sets the named attribute to value.
virtual XMLNode * ShallowClone(XMLDocument *document) const
XMLError QueryBoolAttribute(const char *name, bool *value) const
See QueryIntAttribute()
void EnsureCapacity(int cap)
XMLText * ToText()
Safe cast to XMLText. This can return null.
virtual bool Accept(XMLVisitor *visitor) const
const XMLNode * LastChild() const
Get the last child node, or null if none exists.
static int IsUTF8Continuation(const char p)
void PrintSpace(int depth)
XMLUnknown * NewUnknown(const char *text)
XMLHandle PreviousSibling()
Get the previous sibling of this handle.
MemPoolT< sizeof(XMLText) > _textPool
XMLDeclaration * ToDeclaration()
Safe cast to XMLDeclaration. This can return null.
char * ParseDeep(char *, StrPair *endTag)
XMLDeclaration * NewDeclaration(const char *text=0)
bool NoChildren() const
Returns true if this node has no children.
virtual const XMLDocument * ToDocument() const
MemPoolT< sizeof(XMLElement) > _elementPool
const XMLAttribute * FirstAttribute() const
Return the first attribute in the list.
XMLUnknown * ToUnknown()
Safe cast to XMLUnknown. This can return null.
const XMLConstHandle PreviousSiblingElement(const char *_value=0) const
XMLHandle FirstChild()
Get the first child of this handle.
XMLElement * FirstChildElement(const char *value=0)
virtual bool ShallowEqual(const XMLNode *compare) const
virtual const XMLUnknown * ToUnknown() const
XMLElement * ToElement()
Safe cast to XMLElement. This can return null.
XMLNode & operator=(const XMLNode &)
float FloatAttribute(const char *name) const
See IntAttribute()
virtual bool Visit(const XMLDeclaration &)
Visit a declaration.
bool _restrictedEntityFlag[ENTITY_RANGE]
virtual bool VisitEnter(const XMLDocument &)
Visit a document.
XMLElement * NextSiblingElement(const char *value=0)
XMLElement * LastChildElement(const char *value=0)
virtual const XMLElement * ToElement() const
void Print(XMLPrinter *streamer=0)
char * ParseText(char *in, const char *endTag, int strFlags)
XMLError QueryBoolValue(bool *value) const
See QueryIntAttribute.
virtual XMLDocument * ToDocument()
Safely cast to a Document, or null.
virtual int ItemSize() const =0
const XMLElement * PreviousSiblingElement(const char *value=0) const
Get the previous (left) sibling element of this node, with an opitionally supplied name...
Whitespace WhitespaceMode() const
XMLNode * InsertAfterChild(XMLNode *afterThis, XMLNode *addThis)
float FloatValue() const
Query as a float. See IntAttribute()
virtual XMLDeclaration * ToDeclaration()
Safely cast to a Declaration, or null.
XMLHandle PreviousSiblingElement(const char *_value=0)
Get the previous sibling element of this handle.
virtual XMLElement * ToElement()
Safely cast to an Element, or null.
virtual bool Accept(XMLVisitor *visitor) const
XMLNode * InsertEndChild(XMLNode *addThis)
const XMLNode * NextSibling() const
Get the next (right) sibling node of this node.
bool _entityFlag[ENTITY_RANGE]
XMLHandle(const XMLHandle &ref)
Copy constructor.
virtual const XMLDocument * ToDocument() const
XMLElement * PreviousSiblingElement(const char *value=0)
static int IsAlpha(unsigned char anyByte)
const char * CStr() const
const char * Name() const
Get the name of an element (which is the Value() of the node.)
XMLHandle FirstChildElement(const char *value=0)
Get the first child element of this handle.
virtual bool ShallowEqual(const XMLNode *compare) const
void SetInternedStr(const char *str)