24#ifndef TINYXML2_INCLUDED
25#define TINYXML2_INCLUDED
27#include <scolPlugin.h>
48#if defined( _DEBUG ) || defined( DEBUG ) || defined (__DEBUG__)
57# define TIXMLASSERT( x ) if ( !(x)) { __debugbreak(); }
58# elif defined (ANDROID_NDK)
59# include <android/log.h>
60# define TIXMLASSERT( x ) if ( !(x)) { __android_log_assert( "assert", "grinliz", "ASSERT in '%s' at %d.", __FILE__, __LINE__ ); }
63# define TIXMLASSERT assert
66# define TIXMLASSERT( x ) {}
70#if defined(_MSC_VER) && (_MSC_VER >= 1400 )
79inline int TIXML_SNPRINTF(
char* buffer,
size_t size,
const char* format, ... )
82 va_start( va, format );
83 int result = vsnprintf_s( buffer, size, _TRUNCATE, format, va );
87#define TIXML_SSCANF sscanf_s
91#define TIXML_SNPRINTF snprintf
92#define TIXML_SSCANF sscanf
95static const int TIXML2_MAJOR_VERSION = 1;
96static const int TIXML2_MINOR_VERSION = 0;
97static const int TIXML2_PATCH_VERSION = 9;
134 StrPair() : _flags( 0 ), _start( 0 ), _end( 0 ) {}
137 void Set(
char* start,
char* end,
int flags ) {
141 _flags = flags | NEEDS_FLUSH;
147 return _start == _end;
152 _start =
const_cast<char*
>(str);
155 void SetStr(
const char* str,
int flags=0 );
157 char*
ParseText(
char* in,
const char* endTag,
int strFlags );
162 void CollapseWhitespace();
181template <
class T,
int INIT>
192 if ( _mem != _pool ) {
198 EnsureCapacity( _size+1 );
203 EnsureCapacity( _size+count );
204 T* ret = &_mem[_size];
210 return _mem[--_size];
249 void EnsureCapacity(
int cap ) {
250 if ( cap > _allocated ) {
251 int newAllocated = cap * 2;
252 T* newMem =
new T[newAllocated];
253 memcpy( newMem, _mem,
sizeof(T)*_size );
254 if ( _mem != _pool ) {
258 _allocated = newAllocated;
281 virtual void Free(
void* ) = 0;
292 MemPoolT() : _root(0), _currentAllocs(0), _nAllocs(0), _maxAllocs(0) {}
295 for(
int i=0; i<_blockPtrs.
Size(); ++i ) {
296 delete _blockPtrs[i];
304 return _currentAllocs;
310 Block* block =
new Block();
311 _blockPtrs.
Push( block );
313 for(
int i=0; i<
COUNT-1; ++i ) {
314 block->chunk[i].next = &block->chunk[i+1];
316 block->chunk[
COUNT-1].next = 0;
317 _root = block->chunk;
319 void* result = _root;
323 if ( _currentAllocs > _maxAllocs ) {
324 _maxAllocs = _currentAllocs;
329 virtual void Free(
void* mem ) {
334 Chunk* chunk = (Chunk*)mem;
336 memset( chunk, 0xfe,
sizeof(Chunk) );
342 printf(
"Mempool %s watermark=%d [%dk] current=%d size=%d nAlloc=%d blocks=%d\n",
343 name, _maxAllocs, _maxAllocs*SIZE/1024, _currentAllocs, SIZE, _nAllocs, _blockPtrs.
Size() );
356 DynArray< Block*, 10 > _blockPtrs;
436 while( !
IsUTF8Continuation(*p) && std::isspace( *
reinterpret_cast<const unsigned char*
>(p) ) ) {
442 while( !
IsUTF8Continuation(*p) && std::isspace( *
reinterpret_cast<unsigned char*
>(p) ) ) {
451 inline static bool StringEqual(
const char* p,
const char* q,
int nChar=INT_MAX ) {
456 while( *p && *q && *p == *q && n<nChar ) {
461 if ( (n == nChar) || ( *p == 0 && *q == 0 ) ) {
470 return ( anyByte < 128 ) ? std::isalnum( anyByte ) : 1;
472 inline static int IsAlpha(
unsigned char anyByte ) {
473 return ( anyByte < 128 ) ? std::isalpha( anyByte ) : 1;
476 static const char*
ReadBOM(
const char* p,
bool* hasBOM );
479 static const char*
GetCharacterRef(
const char* p,
char* value,
int* length );
483 static void ToStr(
int v,
char* buffer,
int bufferSize );
484 static void ToStr(
unsigned v,
char* buffer,
int bufferSize );
485 static void ToStr(
bool v,
char* buffer,
int bufferSize );
486 static void ToStr(
float v,
char* buffer,
int bufferSize );
487 static void ToStr(
double v,
char* buffer,
int bufferSize );
490 static bool ToInt(
const char* str,
int* value );
491 static bool ToUnsigned(
const char* str,
unsigned* value );
492 static bool ToBool(
const char* str,
bool* value );
493 static bool ToFloat(
const char* str,
float* value );
494 static bool ToDouble(
const char* str,
double* value );
598 void SetValue(
const char* val,
bool staticMem=
false );
1036 enum { BUF_SIZE = 200 };
1038 XMLAttribute() : _next( 0 ) {}
1039 virtual ~XMLAttribute() {}
1041 XMLAttribute(
const XMLAttribute& );
1042 void operator=(
const XMLAttribute& );
1043 void SetName(
const char* name );
1045 char* ParseDeep(
char* p,
bool processEntities );
1047 mutable StrPair _name;
1048 mutable StrPair _value;
1049 XMLAttribute* _next;
1068 void SetName(
const char* str,
bool staticMem=
false ) {
1103 const char*
Attribute(
const char* name,
const char* value=0 )
const;
1226 return _rootAttribute;
1304 return _closingType;
1317 XMLAttribute* FindOrCreateAttribute(
const char* name );
1319 char* ParseAttributes(
char* p );
1365 XMLError Parse(
const char* xml,
size_t nBytes=(
size_t)(-1) );
1400 return _processEntities;
1524 void InitDocument();
1527 bool _processEntities;
1530 const char* _errorStr1;
1531 const char* _errorStr2;
1660 return ( ( _node && _node->
ToText() ) ? _node->
ToText() : 0 );
1731 return ( ( _node && _node->
ToText() ) ? _node->
ToText() : 0 );
1796 XMLPrinter( std::FILE* file=0,
bool compact =
false );
1800 void PushHeader(
bool writeBOM,
bool writeDeclaration );
1815 void PushText(
const char* text,
bool cdata=
false );
1851 return _buffer.
Mem();
1859 return _buffer.
Size();
1864 void PrintSpace(
int depth );
1865 void PrintString(
const char*,
bool restrictedEntitySet );
1866 void Print(
const char* format, ... );
1868 bool _elementJustOpened;
1873 bool _processEntities;
1880 bool _entityFlag[ENTITY_RANGE];
1881 bool _restrictedEntityFlag[ENTITY_RANGE];
1883 DynArray< const char*, 10 > _stack;
const T & operator[](int i) const
virtual int ItemSize() const =0
virtual void Free(void *)=0
void Trace(const char *name)
virtual int ItemSize() const
virtual void Free(void *mem)
int CurrentAllocs() const
@ ATTRIBUTE_VALUE_LEAVE_ENTITIES
@ NEEDS_ENTITY_PROCESSING
@ NEEDS_NEWLINE_NORMALIZATION
@ TEXT_ELEMENT_LEAVE_ENTITIES
void SetStr(const char *str, int flags=0)
void SetInternedStr(const char *str)
void Set(char *start, char *end, int flags)
char * ParseName(char *in)
char * ParseText(char *in, const char *endTag, int strFlags)
XMLError QueryFloatValue(float *value) const
See QueryIntAttribute.
unsigned UnsignedValue() const
Query as an unsigned integer. See IntAttribute()
float FloatValue() const
Query as a float. See IntAttribute()
XMLError QueryDoubleValue(double *value) const
See QueryIntAttribute.
void SetAttribute(const char *value)
Set the attribute to a string value.
XMLError QueryUnsignedValue(unsigned int *value) const
See QueryIntAttribute.
double DoubleValue() const
Query as a double. See IntAttribute()
const char * Name() const
The name of the attribute.
XMLError QueryBoolValue(bool *value) const
See QueryIntAttribute.
XMLError QueryIntValue(int *value) const
bool BoolValue() const
Query as a boolean. See IntAttribute()
const XMLAttribute * Next() const
The next attribute in the list.
const char * Value() const
The value of the attribute.
XMLConstHandle(const XMLNode *node)
const XMLText * ToText() const
XMLConstHandle & operator=(const XMLConstHandle &ref)
const XMLElement * ToElement() const
XMLConstHandle(const XMLConstHandle &ref)
const XMLUnknown * ToUnknown() const
const XMLDeclaration * ToDeclaration() const
const XMLConstHandle NextSiblingElement(const char *_value=0) const
XMLConstHandle(const XMLNode &node)
const XMLConstHandle FirstChildElement(const char *value=0) const
const XMLConstHandle LastChild() const
const XMLNode * ToNode() const
const XMLConstHandle PreviousSibling() const
const XMLConstHandle PreviousSiblingElement(const char *_value=0) const
const XMLConstHandle LastChildElement(const char *_value=0) const
const XMLConstHandle NextSibling() const
const XMLConstHandle FirstChild() const
XMLDeclaration & operator=(const XMLDeclaration &)
char * ParseDeep(char *, StrPair *endTag)
XMLDeclaration(const XMLDeclaration &)
virtual const XMLDeclaration * ToDeclaration() const
virtual XMLDeclaration * ToDeclaration()
Safely cast to a Declaration, or null.
virtual ~XMLDeclaration()
virtual bool Accept(XMLVisitor *visitor) const
virtual XMLNode * ShallowClone(XMLDocument *document) const
virtual bool ShallowEqual(const XMLNode *compare) const
XMLElement * RootElement()
XMLError Parse(const char *xml, size_t nBytes=(size_t)(-1))
void PrintError() const
If there is an error, print it to stdout.
char * Identify(char *p, XMLNode **node)
XMLError LoadFile(std::FILE *)
void Print(XMLPrinter *streamer=0)
XMLError LoadFile(const char *filename)
bool Error() const
Return true if there was an error parsing the document.
XMLComment * NewComment(const char *comment)
XMLElement * NewElement(const char *name)
XMLUnknown * NewUnknown(const char *text)
XMLError SaveFile(std::FILE *fp, bool compact=false)
const XMLElement * RootElement() const
bool ProcessEntities() const
virtual bool ShallowEqual(const XMLNode *) const
XMLError SaveFile(const char *filename, bool compact=false)
Whitespace WhitespaceMode() const
virtual XMLDocument * ToDocument()
Safely cast to a Document, or null.
const char * GetErrorStr1() const
Return a possibly helpful diagnostic location or string.
virtual bool Accept(XMLVisitor *visitor) const
void DeleteNode(XMLNode *node)
virtual const XMLDocument * ToDocument() const
const char * GetErrorStr2() const
Return a possibly helpful secondary diagnostic location or string.
XMLText * NewText(const char *text)
void SetError(XMLError error, const char *str1, const char *str2)
XMLDeclaration * NewDeclaration(const char *text=0)
virtual XMLNode * ShallowClone(XMLDocument *) const
XMLError ErrorID() const
Return the errorID.
bool BoolAttribute(const char *name) const
See IntAttribute()
XMLError QueryDoubleText(double *_value) const
See QueryIntText()
const char * GetText() const
void SetAttribute(const char *name, const char *value)
Sets the named attribute to value.
XMLError QueryBoolAttribute(const char *name, bool *value) const
See QueryIntAttribute()
const XMLAttribute * FindAttribute(const char *name) const
Query a specific attribute in the list.
XMLError QueryUnsignedText(unsigned *_value) const
See QueryIntText()
void SetAttribute(const char *name, double value)
Sets the named attribute to value.
XMLError QueryUnsignedAttribute(const char *name, unsigned int *value) const
See QueryIntAttribute()
unsigned UnsignedAttribute(const char *name) const
See IntAttribute()
XMLError QueryFloatText(float *_value) const
See QueryIntText()
const char * Attribute(const char *name, const char *value=0) const
const XMLAttribute * FirstAttribute() const
Return the first attribute in the list.
XMLError QueryIntText(int *_value) const
XMLError QueryDoubleAttribute(const char *name, double *value) const
See QueryIntAttribute()
virtual bool ShallowEqual(const XMLNode *compare) const
float FloatAttribute(const char *name) const
See IntAttribute()
double DoubleAttribute(const char *name) const
See IntAttribute()
XMLError QueryIntAttribute(const char *name, int *value) const
void SetName(const char *str, bool staticMem=false)
Set the name of the element.
virtual const XMLElement * ToElement() const
virtual bool Accept(XMLVisitor *visitor) const
XMLError QueryBoolText(bool *_value) const
See QueryIntText()
void SetAttribute(const char *name, bool value)
Sets the named attribute to value.
char * ParseDeep(char *p, StrPair *endTag)
void SetAttribute(const char *name, int value)
Sets the named attribute to value.
virtual XMLNode * ShallowClone(XMLDocument *document) const
virtual XMLElement * ToElement()
Safely cast to an Element, or null.
const char * Name() const
Get the name of an element (which is the Value() of the node.)
XMLError QueryFloatAttribute(const char *name, float *value) const
See QueryIntAttribute()
int IntAttribute(const char *name) const
void SetAttribute(const char *name, unsigned value)
Sets the named attribute to value.
void DeleteAttribute(const char *name)
XMLHandle PreviousSiblingElement(const char *_value=0)
Get the previous sibling element of this handle.
XMLHandle LastChildElement(const char *_value=0)
Get the last child element of this handle.
XMLHandle PreviousSibling()
Get the previous sibling of this handle.
XMLHandle NextSiblingElement(const char *_value=0)
Get the next sibling element of this handle.
XMLHandle FirstChild()
Get the first child of this handle.
XMLNode * ToNode()
Safe cast to XMLNode. This can return null.
XMLDeclaration * ToDeclaration()
Safe cast to XMLDeclaration. This can return null.
XMLHandle FirstChildElement(const char *value=0)
Get the first child element of this handle.
XMLHandle(XMLNode *node)
Create a handle from any node (at any depth of the tree.) This can be a null pointer.
XMLHandle LastChild()
Get the last child of this handle.
XMLHandle & operator=(const XMLHandle &ref)
Assignment.
XMLHandle(XMLNode &node)
Create a handle from a node.
XMLHandle NextSibling()
Get the next sibling of this handle.
XMLElement * ToElement()
Safe cast to XMLElement. This can return null.
XMLText * ToText()
Safe cast to XMLText. This can return null.
XMLUnknown * ToUnknown()
Safe cast to XMLUnknown. This can return null.
XMLHandle(const XMLHandle &ref)
Copy constructor.
const char * Value() const
virtual const XMLText * ToText() const
void SetValue(const char *val, bool staticMem=false)
virtual XMLText * ToText()
Safely cast to Text, or null.
const XMLElement * LastChildElement(const char *value=0) const
virtual XMLDeclaration * ToDeclaration()
Safely cast to a Declaration, or null.
XMLElement * NextSiblingElement(const char *value=0)
void DeleteChild(XMLNode *node)
const XMLElement * NextSiblingElement(const char *value=0) const
Get the next (right) sibling element of this node, with an opitionally supplied name.
XMLDocument * GetDocument()
Get the XMLDocument that owns this XMLNode.
const XMLNode * Parent() const
Get the parent of this node on the DOM.
const XMLElement * FirstChildElement(const char *value=0) const
XMLNode & operator=(const XMLNode &)
XMLNode * PreviousSibling()
virtual XMLComment * ToComment()
Safely cast to a Comment, or null.
virtual XMLDocument * ToDocument()
Safely cast to a Document, or null.
const XMLNode * LastChild() const
Get the last child node, or null if none exists.
const XMLDocument * GetDocument() const
Get the XMLDocument that owns this XMLNode.
virtual const XMLElement * ToElement() const
virtual char * ParseDeep(char *, StrPair *)
virtual bool ShallowEqual(const XMLNode *compare) const =0
virtual bool Accept(XMLVisitor *visitor) const =0
virtual XMLNode * ShallowClone(XMLDocument *document) const =0
XMLNode * InsertAfterChild(XMLNode *afterThis, XMLNode *addThis)
const XMLNode * PreviousSibling() const
Get the previous (left) sibling node of this node.
virtual const XMLDeclaration * ToDeclaration() const
virtual XMLElement * ToElement()
Safely cast to an Element, or null.
XMLElement * PreviousSiblingElement(const char *value=0)
virtual XMLUnknown * ToUnknown()
Safely cast to an Unknown, or null.
const XMLElement * PreviousSiblingElement(const char *value=0) const
Get the previous (left) sibling element of this node, with an opitionally supplied name.
virtual const XMLUnknown * ToUnknown() const
const XMLNode * FirstChild() const
Get the first child node, or null if none exists.
bool NoChildren() const
Returns true if this node has no children.
XMLNode * InsertFirstChild(XMLNode *addThis)
virtual const XMLDocument * ToDocument() const
XMLNode * InsertEndChild(XMLNode *addThis)
XMLNode * LinkEndChild(XMLNode *addThis)
virtual const XMLComment * ToComment() const
XMLElement * LastChildElement(const char *value=0)
XMLElement * FirstChildElement(const char *value=0)
const XMLNode * NextSibling() const
Get the next (right) sibling node of this node.
virtual bool VisitExit(const XMLDocument &)
Visit a document.
void PushHeader(bool writeBOM, bool writeDeclaration)
void PushText(const char *text, bool cdata=false)
Add a text node.
void PushDeclaration(const char *value)
void PushAttribute(const char *name, const char *value)
If streaming, add an attribute to an open element.
virtual bool VisitEnter(const XMLDocument &)
Visit a document.
void OpenElement(const char *name)
void PushUnknown(const char *value)
const char * CStr() const
virtual bool Visit(const XMLText &text)
Visit a text node.
void CloseElement()
If streaming, close the Element.
void PushComment(const char *comment)
Add a comment.
virtual const XMLText * ToText() const
virtual bool Accept(XMLVisitor *visitor) const
virtual XMLNode * ShallowClone(XMLDocument *document) const
virtual bool ShallowEqual(const XMLNode *compare) const
virtual XMLText * ToText()
Safely cast to Text, or null.
XMLText & operator=(const XMLText &)
char * ParseDeep(char *, StrPair *endTag)
bool CData() const
Returns true if this is a CDATA text element.
void SetCData(bool isCData)
Declare whether this should be CDATA or standard text.
XMLText(XMLDocument *doc)
char * ParseDeep(char *, StrPair *endTag)
virtual XMLUnknown * ToUnknown()
Safely cast to an Unknown, or null.
virtual bool Accept(XMLVisitor *visitor) const
XMLUnknown(const XMLUnknown &)
virtual XMLNode * ShallowClone(XMLDocument *document) const
virtual const XMLUnknown * ToUnknown() const
XMLUnknown & operator=(const XMLUnknown &)
virtual bool ShallowEqual(const XMLNode *compare) const
static int IsAlpha(unsigned char anyByte)
static const char * SkipWhiteSpace(const char *p)
static bool ToUnsigned(const char *str, unsigned *value)
static int IsUTF8Continuation(const char p)
static void ConvertUTF32ToUTF8(unsigned long input, char *output, int *length)
static bool IsWhiteSpace(char p)
static bool ToFloat(const char *str, float *value)
static void ToStr(int v, char *buffer, int bufferSize)
static const char * GetCharacterRef(const char *p, char *value, int *length)
static char * SkipWhiteSpace(char *p)
static int IsAlphaNum(unsigned char anyByte)
static bool StringEqual(const char *p, const char *q, int nChar=INT_MAX)
static bool ToInt(const char *str, int *value)
static bool ToDouble(const char *str, double *value)
static bool ToBool(const char *str, bool *value)
static const char * ReadBOM(const char *p, bool *hasBOM)
virtual bool Visit(const XMLUnknown &)
Visit an unknown node.
virtual bool VisitExit(const XMLDocument &)
Visit a document.
virtual bool VisitExit(const XMLElement &)
Visit an element.
virtual bool VisitEnter(const XMLDocument &)
Visit a document.
virtual bool Visit(const XMLComment &)
Visit a comment node.
virtual bool Visit(const XMLDeclaration &)
Visit a declaration.
virtual bool Visit(const XMLText &)
Visit a text node.
virtual bool VisitEnter(const XMLElement &, const XMLAttribute *)
Visit an element.
@ XML_ERROR_MISMATCHED_ELEMENT
@ XML_ERROR_EMPTY_DOCUMENT
@ XML_ERROR_ELEMENT_MISMATCH
@ XML_ERROR_PARSING_ATTRIBUTE
@ XML_ERROR_FILE_NOT_FOUND
@ XML_ERROR_IDENTIFYING_TAG
@ XML_ERROR_PARSING_COMMENT
@ XML_ERROR_FILE_READ_ERROR
@ XML_ERROR_PARSING_UNKNOWN
@ XML_ERROR_PARSING_CDATA
@ XML_ERROR_PARSING_DECLARATION
@ XML_WRONG_ATTRIBUTE_TYPE
@ XML_ERROR_PARSING_ELEMENT
@ XML_ERROR_FILE_COULD_NOT_BE_OPENED
@ XML_CAN_NOT_CONVERT_TEXT