29 #ifndef TINYXML2_INCLUDED 30 #define TINYXML2_INCLUDED 32 #if defined(ANDROID_NDK) || defined(__BORLANDC__) || defined(__QNXNTO__) 61 #if defined( _DEBUG ) || defined( DEBUG ) || defined (__DEBUG__) 68 # pragma warning(push) 69 # pragma warning(disable: 4251) 73 #ifdef USE_IMPORT_EXPORT 74 #ifdef AWS_CORE_EXPORTS 75 #define TINYXML2_LIB __declspec(dllexport) 77 #define TINYXML2_LIB __declspec(dllimport) 78 #endif // AWS_CORE_EXPORTS 79 #endif // USE_IMPORT_EXPORT 84 #endif // TINYXML2_LIB 88 # if defined(_MSC_VER) 89 # // "(void)0," is for suppressing C4127 warning in "assert(false)", "assert(true)" and the like 90 # define TIXMLASSERT( x ) if ( !((void)0,(x))) { __debugbreak(); } //if ( !(x)) WinDebugBreak() 91 # elif defined (ANDROID_NDK) 92 # include <android/log.h> 93 # define TIXMLASSERT( x ) if ( !(x)) { __android_log_assert( "assert", "grinliz", "ASSERT in '%s' at %d.", __FILE__, __LINE__ ); } 96 # define TIXMLASSERT assert 99 # define TIXMLASSERT( x ) {} 103 #if defined(_MSC_VER) && (_MSC_VER >= 1400 ) && (!defined WINCE) 112 inline int TIXML_SNPRINTF(
char* buffer,
size_t size,
const char* format, ...)
115 va_start(va, format);
116 int result = vsnprintf_s(buffer, size, _TRUNCATE, format, va);
120 #define TIXML_SSCANF sscanf_s 122 #define TIXML_SNPRINTF _snprintf 123 #define TIXML_SSCANF sscanf 127 #define TIXML_SNPRINTF snprintf 128 #define TIXML_SSCANF sscanf 165 NEEDS_ENTITY_PROCESSING = 0x01,
166 NEEDS_NEWLINE_NORMALIZATION = 0x02,
169 TEXT_ELEMENT = NEEDS_ENTITY_PROCESSING | NEEDS_NEWLINE_NORMALIZATION,
170 TEXT_ELEMENT_LEAVE_ENTITIES = NEEDS_NEWLINE_NORMALIZATION,
172 ATTRIBUTE_VALUE = NEEDS_ENTITY_PROCESSING | NEEDS_NEWLINE_NORMALIZATION,
173 ATTRIBUTE_VALUE_LEAVE_ENTITIES = NEEDS_NEWLINE_NORMALIZATION,
174 COMMENT = NEEDS_NEWLINE_NORMALIZATION
180 void Set(
char* start,
char* end,
int flags) {
184 _flags = flags | NEEDS_FLUSH;
187 const char* GetStr();
190 return _start == _end;
195 _start =
const_cast<char*
>(str);
198 void SetStr(
const char* str,
int flags = 0);
200 char* ParseText(
char* in,
const char* endTag,
int strFlags);
201 char* ParseName(
char* in);
203 void TransferTo(
StrPair* other);
207 void CollapseWhitespace();
220 void operator=(
StrPair& other);
229 template <
class T,
int INIT>
241 Aws::DeleteArray<T>(_mem);
251 EnsureCapacity(_size + 1);
258 EnsureCapacity(_size + count);
259 T* ret = &_mem[_size];
266 return _mem[--_size];
290 return _mem[_size - 1];
314 void EnsureCapacity(
int cap) {
316 if (cap > _allocated) {
318 int newAllocated = cap * 2;
320 memcpy(newMem, _mem,
sizeof(T)*_size);
322 Aws::DeleteArray<T>(_mem);
325 _allocated = newAllocated;
346 virtual int ItemSize()
const = 0;
347 virtual void* Alloc() = 0;
348 virtual void Free(
void*) = 0;
349 virtual void SetTracked() = 0;
350 virtual void Clear() = 0;
361 MemPoolT() : _root(0), _currentAllocs(0), _nAllocs(0), _maxAllocs(0), _nUntracked(0) {}
368 while (!_blockPtrs.Empty()) {
369 Block* b = _blockPtrs.Pop();
383 return _currentAllocs;
390 _blockPtrs.Push(block);
392 for (
int i = 0; i<COUNT - 1; ++i) {
393 block->chunk[i].next = &block->chunk[i + 1];
395 block->chunk[COUNT - 1].next = 0;
396 _root = block->chunk;
398 void* result = _root;
402 if (_currentAllocs > _maxAllocs) {
403 _maxAllocs = _currentAllocs;
415 Chunk* chunk =
static_cast<Chunk*
>(mem);
417 memset(chunk, 0xfe,
sizeof(Chunk));
423 printf(
"Mempool %s watermark=%d [%dk] current=%d size=%d nAlloc=%d blocks=%d\n",
424 name, _maxAllocs, _maxAllocs*SIZE / 1024, _currentAllocs, SIZE, _nAllocs, _blockPtrs.Size());
444 enum { COUNT = (4 * 1024) / SIZE };
564 while (IsWhiteSpace(*p)) {
571 return const_cast<char*
>(SkipWhiteSpace(const_cast<const char*>(p)));
577 return !IsUTF8Continuation(p) && isspace(static_cast<unsigned char>(p));
588 return ch ==
':' || ch ==
'_';
592 return IsNameStartChar(ch)
598 inline static bool StringEqual(
const char* p,
const char* q,
int nChar = INT_MAX) {
603 while (*p && *q && *p == *q && n<nChar) {
608 if ((n == nChar) || (*p == 0 && *q == 0)) {
615 return (p & 0x80) != 0;
618 static const char* ReadBOM(
const char* p,
bool* hasBOM);
621 static const char* GetCharacterRef(
const char* p,
char* value,
int* length);
622 static void ConvertUTF32ToUTF8(
unsigned long input,
char* output,
int* length);
625 static void ToStr(
int v,
char* buffer,
int bufferSize);
626 static void ToStr(
unsigned v,
char* buffer,
int bufferSize);
627 static void ToStr(
bool v,
char* buffer,
int bufferSize);
628 static void ToStr(
float v,
char* buffer,
int bufferSize);
629 static void ToStr(
double v,
char* buffer,
int bufferSize);
632 static bool ToInt(
const char* str,
int* value);
633 static bool ToUnsigned(
const char* str,
unsigned* value);
634 static bool ToBool(
const char* str,
bool* value);
635 static bool ToFloat(
const char* str,
float* value);
636 static bool ToDouble(
const char* str,
double* value);
733 const char* Value()
const;
738 void SetValue(
const char* val,
bool staticMem =
false);
766 const XMLElement* FirstChildElement(
const char* value = 0)
const;
769 return const_cast<XMLElement*
>(
const_cast<const XMLNode*
>(
this)->FirstChildElement(value));
778 return const_cast<XMLNode*
>(
const_cast<const XMLNode*
>(
this)->LastChild());
784 const XMLElement* LastChildElement(
const char* value = 0)
const;
787 return const_cast<XMLElement*
>(
const_cast<const XMLNode*
>(
this)->LastChildElement(value));
800 const XMLElement* PreviousSiblingElement(
const char* value = 0)
const;
803 return const_cast<XMLElement*
>(
const_cast<const XMLNode*
>(
this)->PreviousSiblingElement(value));
816 const XMLElement* NextSiblingElement(
const char* value = 0)
const;
819 return const_cast<XMLElement*
>(
const_cast<const XMLNode*
>(
this)->NextSiblingElement(value));
832 return InsertEndChild(addThis);
855 void DeleteChildren();
860 void DeleteChild(
XMLNode* node);
879 virtual bool ShallowEqual(
const XMLNode* compare)
const = 0;
903 virtual bool Accept(
XMLVisitor* visitor)
const = 0;
906 virtual char* ParseDeep(
char*,
StrPair*);
925 static void DeleteNode(
XMLNode* node);
926 void InsertChildPreamble(
XMLNode* insertThis)
const;
947 friend class XMLBase;
950 virtual bool Accept(
XMLVisitor* visitor)
const;
968 char* ParseDeep(
char*,
StrPair* endTag);
970 virtual bool ShallowEqual(
const XMLNode* compare)
const;
996 virtual bool Accept(
XMLVisitor* visitor)
const;
998 char* ParseDeep(
char*,
StrPair* endTag);
1000 virtual bool ShallowEqual(
const XMLNode* compare)
const;
1034 virtual bool Accept(
XMLVisitor* visitor)
const;
1036 char* ParseDeep(
char*,
StrPair* endTag);
1038 virtual bool ShallowEqual(
const XMLNode* compare)
const;
1068 virtual bool Accept(
XMLVisitor* visitor)
const;
1070 char* ParseDeep(
char*,
StrPair* endTag);
1072 virtual bool ShallowEqual(
const XMLNode* compare)
const;
1096 const char* Name()
const;
1099 const char* Value()
const;
1118 QueryUnsignedValue(&i);
1130 QueryDoubleValue(&d);
1136 QueryFloatValue(&f);
1144 XMLError QueryIntValue(
int* value)
const;
1146 XMLError QueryUnsignedValue(
unsigned int* value)
const;
1148 XMLError QueryBoolValue(
bool* value)
const;
1150 XMLError QueryDoubleValue(
double* value)
const;
1152 XMLError QueryFloatValue(
float* value)
const;
1155 void SetAttribute(
const char* value);
1157 void SetAttribute(
int value);
1159 void SetAttribute(
unsigned value);
1161 void SetAttribute(
bool value);
1163 void SetAttribute(
double value);
1165 void SetAttribute(
float value);
1168 enum { BUF_SIZE = 200 };
1175 void SetName(
const char* name);
1177 char* ParseDeep(
char* p,
bool processEntities);
1192 friend class XMLBase;
1200 void SetName(
const char* str,
bool staticMem =
false) {
1201 SetValue(str, staticMem);
1210 virtual bool Accept(
XMLVisitor* visitor)
const;
1235 const char* Attribute(
const char* name,
const char* value = 0)
const;
1244 QueryIntAttribute(name, &i);
1250 QueryUnsignedAttribute(name, &i);
1256 QueryBoolAttribute(name, &b);
1262 QueryDoubleAttribute(name, &d);
1268 QueryFloatAttribute(name, &f);
1344 return QueryIntAttribute(name, value);
1348 return QueryUnsignedAttribute(name, value);
1352 return QueryBoolAttribute(name, value);
1356 return QueryDoubleAttribute(name, value);
1360 return QueryFloatAttribute(name, value);
1397 void DeleteAttribute(
const char* name);
1401 return _rootAttribute;
1404 const XMLAttribute* FindAttribute(
const char* name)
const;
1434 const char* GetText()
const;
1470 void SetText(
const char* inText);
1472 void SetText(
int value);
1474 void SetText(
unsigned value);
1476 void SetText(
bool value);
1478 void SetText(
double value);
1480 void SetText(
float value);
1508 XMLError QueryIntText(
int* ival)
const;
1510 XMLError QueryUnsignedText(
unsigned* uval)
const;
1512 XMLError QueryBoolText(
bool* bval)
const;
1514 XMLError QueryDoubleText(
double* dval)
const;
1516 XMLError QueryFloatText(
float* fval)
const;
1525 return _closingType;
1527 char* ParseDeep(
char* p,
StrPair* endTag);
1529 virtual bool ShallowEqual(
const XMLNode* compare)
const;
1542 char* ParseAttributes(
char* p);
1545 enum { BUF_SIZE = 200 };
1590 XMLError Parse(
const char* xml,
size_t nBytes = (
size_t)(-1));
1597 XMLError LoadFile(
const char* filename);
1617 XMLError SaveFile(
const char* filename,
bool compact =
false);
1626 XMLError SaveFile(FILE* fp,
bool compact =
false);
1629 return _processEntities;
1651 return FirstChildElement();
1654 return FirstChildElement();
1672 virtual bool Accept(
XMLVisitor* visitor)
const;
1691 XMLText* NewText(
const char* text);
1715 void DeleteNode(
XMLNode* node);
1717 void SetError(
XMLError error,
const char* str1,
const char* str2);
1727 const char* ErrorName()
const;
1738 void PrintError()
const;
1744 char* Identify(
char* p,
XMLNode** node);
1758 bool _processEntities;
1761 const char* _errorStr1;
1762 const char* _errorStr2;
1854 return XMLHandle(_node ? _node->FirstChild() : 0);
1858 return XMLHandle(_node ? _node->FirstChildElement(value) : 0);
1862 return XMLHandle(_node ? _node->LastChild() : 0);
1866 return XMLHandle(_node ? _node->LastChildElement(_value) : 0);
1870 return XMLHandle(_node ? _node->PreviousSibling() : 0);
1874 return XMLHandle(_node ? _node->PreviousSiblingElement(_value) : 0);
1878 return XMLHandle(_node ? _node->NextSibling() : 0);
1882 return XMLHandle(_node ? _node->NextSiblingElement(_value) : 0);
1891 return ((_node == 0) ? 0 : _node->ToElement());
1895 return ((_node == 0) ? 0 : _node->ToText());
1899 return ((_node == 0) ? 0 : _node->ToUnknown());
1903 return ((_node == 0) ? 0 : _node->ToDeclaration());
1937 return XMLConstHandle(_node ? _node->FirstChildElement(value) : 0);
1943 return XMLConstHandle(_node ? _node->LastChildElement(_value) : 0);
1949 return XMLConstHandle(_node ? _node->PreviousSiblingElement(_value) : 0);
1955 return XMLConstHandle(_node ? _node->NextSiblingElement(_value) : 0);
1963 return ((_node == 0) ? 0 : _node->ToElement());
1966 return ((_node == 0) ? 0 : _node->ToText());
1969 return ((_node == 0) ? 0 : _node->ToUnknown());
1972 return ((_node == 0) ? 0 : _node->ToDeclaration());
2031 XMLPrinter(FILE* file = 0,
bool compact =
false,
int depth = 0);
2035 void PushHeader(
bool writeBOM,
bool writeDeclaration);
2039 void OpenElement(
const char* name,
bool compactMode =
false);
2041 void PushAttribute(
const char* name,
const char* value);
2042 void PushAttribute(
const char* name,
int value);
2043 void PushAttribute(
const char* name,
unsigned value);
2044 void PushAttribute(
const char* name,
bool value);
2045 void PushAttribute(
const char* name,
double value);
2047 virtual void CloseElement(
bool compactMode =
false);
2050 void PushText(
const char* text,
bool cdata =
false);
2052 void PushText(
int value);
2054 void PushText(
unsigned value);
2056 void PushText(
bool value);
2058 void PushText(
float value);
2060 void PushText(
double value);
2063 void PushComment(
const char* comment);
2065 void PushDeclaration(
const char* value);
2066 void PushUnknown(
const char* value);
2074 virtual bool VisitExit(
const XMLElement& element);
2076 virtual bool Visit(
const XMLText& text);
2077 virtual bool Visit(
const XMLComment& comment);
2079 virtual bool Visit(
const XMLUnknown& unknown);
2086 return _buffer.Mem();
2094 return _buffer.Size();
2111 virtual void PrintSpace(
int depth);
2112 void Print(
const char* format, ...);
2114 void SealElementIfJustOpened();
2119 void PrintString(
const char*,
bool restrictedEntitySet);
2125 bool _processEntities;
2132 bool _entityFlag[ENTITY_RANGE];
2133 bool _restrictedEntityFlag[ENTITY_RANGE];
2143 #if defined(_MSC_VER) 2144 # pragma warning(pop) 2147 #endif // TINYXML2_INCLUDED
const XMLNode * LastChild() const
Get the last child node, or null if none exists.
virtual const XMLDocument * ToDocument() const
const XMLDeclaration * ToDeclaration() const
static bool StringEqual(const char *p, const char *q, int nChar=INT_MAX)
virtual const XMLText * ToText() const
XMLNode * PreviousSibling()
XMLConstHandle(const XMLNode &node)
XMLHandle PreviousSibling()
Get the previous sibling of this handle.
void SetCData(bool isCData)
Declare whether this should be CDATA or standard text.
const XMLNode * PreviousSibling() const
Get the previous (left) sibling node of this node.
XMLElement * FirstChildElement(const char *value=0)
DynArray< const char *, 10 > _stack
static const int TIXML2_PATCH_VERSION
static const char * ALLOCATION_TAG
void Delete(T *pointerToT)
const XMLElement * RootElement() const
virtual bool Visit(const XMLText &)
Visit a text node.
virtual const XMLDeclaration * ToDeclaration() const
double DoubleAttribute(const char *name) const
See IntAttribute()
float FloatAttribute(const char *name) const
See IntAttribute()
XMLUnknown * ToUnknown()
Safe cast to XMLUnknown. This can return null.
XMLError ErrorID() const
Return the errorID.
XMLHandle(const XMLHandle &ref)
Copy constructor.
XMLNode * ToNode()
Safe cast to XMLNode. This can return null.
bool BoolValue() const
Query as a boolean. See IntValue()
virtual bool ShallowEqual(const XMLNode *) const
virtual int ItemSize() const
virtual bool VisitExit(const XMLDocument &)
Visit a document.
static bool IsWhiteSpace(char p)
static const char * SkipWhiteSpace(const char *p)
XMLConstHandle(const XMLConstHandle &ref)
virtual XMLText * ToText()
Safely cast to Text, or null.
XMLNode * LinkEndChild(XMLNode *addThis)
void SetAttribute(const char *name, bool value)
Sets the named attribute to value.
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.
const XMLConstHandle LastChild() const
virtual const XMLUnknown * ToUnknown() const
float FloatValue() const
Query as a float. See IntValue()
XMLError QueryBoolAttribute(const char *name, bool *value) const
See QueryIntAttribute()
virtual bool CompactMode(const XMLElement &)
XMLHandle(XMLNode &node)
Create a handle from a node.
XMLHandle & operator=(const XMLHandle &ref)
Assignment.
const XMLConstHandle FirstChild() const
bool Error() const
Return true if there was an error parsing the document.
bool NoChildren() const
Returns true if this node has no children.
int QueryAttribute(const char *name, bool *value) const
virtual const XMLDeclaration * ToDeclaration() const
int QueryAttribute(const char *name, int *value) const
virtual const XMLElement * ToElement() const
XMLDeclaration * ToDeclaration()
Safe cast to XMLDeclaration. This can return null.
virtual const XMLUnknown * ToUnknown() const
XMLText * ToText()
Safe cast to XMLText. This can return null.
virtual XMLDeclaration * ToDeclaration()
Safely cast to a Declaration, or null.
XMLElement * NextSiblingElement(const char *value=0)
static const int TIXML2_MINOR_VERSION
bool BoolAttribute(const char *name) const
See IntAttribute()
virtual const XMLDocument * ToDocument() const
XMLError QueryBoolValue(bool *value) const
See QueryIntValue.
XMLDocument * GetDocument()
Get the XMLDocument that owns this XMLNode.
XMLError QueryIntValue(int *value) const
XMLElement * LastChildElement(const char *value=0)
unsigned UnsignedValue() const
Query as an unsigned integer. See IntValue()
XMLText(XMLDocument *doc)
const XMLConstHandle FirstChildElement(const char *value=0) const
static bool IsUTF8Continuation(const char p)
const T & operator[](int i) const
virtual const XMLText * ToText() const
void SetAttribute(const char *name, const char *value)
Sets the named attribute to value.
virtual const XMLComment * ToComment() const
virtual const XMLElement * ToElement() const
const char * Name() const
Get the name of an element (which is the Value() of the node.)
XMLError QueryUnsignedAttribute(const char *name, unsigned int *value) const
See QueryIntAttribute()
virtual XMLElement * ToElement()
Safely cast to an Element, or null.
const XMLConstHandle NextSiblingElement(const char *_value=0) const
virtual bool Visit(const XMLDeclaration &)
Visit a declaration.
static const int TIXML2_MAJOR_VERSION
void Trace(const char *name)
XMLError QueryDoubleAttribute(const char *name, double *value) const
See QueryIntAttribute()
XMLError QueryIntAttribute(const char *name, int *value) const
void SetAttribute(const char *value)
Set the attribute to a string value.
virtual bool VisitExit(const XMLElement &)
Visit an element.
XMLConstHandle(const XMLNode *node)
const XMLNode * ToNode() const
static char * SkipWhiteSpace(char *p)
virtual bool Visit(const XMLComment &)
Visit a comment node.
virtual XMLComment * ToComment()
Safely cast to a Comment, or null.
int CurrentAllocs() const
virtual XMLNode * ShallowClone(XMLDocument *) const
virtual XMLElement * ToElement()
Safely cast to an Element, or null.
XMLElement * RootElement()
const char * GetErrorStr2() const
Return a possibly helpful secondary diagnostic location or string.
XMLConstHandle & operator=(const XMLConstHandle &ref)
XMLHandle PreviousSiblingElement(const char *_value=0)
Get the previous sibling element of this handle.
int IntAttribute(const char *name) const
void SetInternedStr(const char *str)
bool ProcessEntities() const
void SetAttribute(const char *name, double value)
Sets the named attribute to value.
XMLHandle LastChild()
Get the last child of this handle.
XMLError QueryDoubleValue(double *value) const
See QueryIntValue.
const T & PeekTop() const
void SetName(const char *str, bool staticMem=false)
Set the name of the element.
bool CData() const
Returns true if this is a CDATA text element.
static bool IsNameChar(unsigned char ch)
void Set(char *start, char *end, int flags)
const XMLElement * ToElement() const
unsigned UnsignedAttribute(const char *name) const
See IntAttribute()
XMLError QueryFloatValue(float *value) const
See QueryIntValue.
const XMLNode * FirstChild() const
Get the first child node, or null if none exists.
virtual XMLUnknown * ToUnknown()
Safely cast to an Unknown, or null.
const char * GetErrorStr1() const
Return a possibly helpful diagnostic location or string.
const XMLConstHandle PreviousSibling() const
XMLError QueryUnsignedValue(unsigned int *value) const
See QueryIntValue.
const XMLNode * NextSibling() const
Get the next (right) sibling node of this node.
Whitespace WhitespaceMode() const
double DoubleValue() const
Query as a double. See IntValue()
const XMLDocument * GetDocument() const
Get the XMLDocument that owns this XMLNode.
XMLElement * ToElement()
Safe cast to XMLElement. This can return null.
XMLHandle(XMLNode *node)
Create a handle from any node (at any depth of the tree.) This can be a null pointer.
AWS_CORE_API void Free(void *memoryPtr)
virtual XMLText * ToText()
Safely cast to Text, or null.
const XMLText * ToText() const
int QueryAttribute(const char *name, float *value) const
virtual bool VisitExit(const XMLDocument &)
Visit a document.
int QueryAttribute(const char *name, double *value) const
XMLHandle NextSibling()
Get the next sibling of this handle.
int QueryAttribute(const char *name, unsigned int *value) const
void SetAttribute(const char *name, float value)
Sets the named attribute to value.
virtual bool VisitEnter(const XMLElement &, const XMLAttribute *)
Visit an element.
const XMLNode * Parent() const
Get the parent of this node on the DOM.
virtual void Free(void *mem)
virtual XMLUnknown * ToUnknown()
Safely cast to an Unknown, or null.
const XMLAttribute * FirstAttribute() const
Return the first attribute in the list.
XMLHandle FirstChild()
Get the first child of this handle.
XMLElement * PreviousSiblingElement(const char *value=0)
XMLHandle NextSiblingElement(const char *_value=0)
Get the next sibling element of this handle.
const XMLConstHandle LastChildElement(const char *_value=0) const
XMLHandle FirstChildElement(const char *value=0)
Get the first child element of this handle.
virtual XMLDeclaration * ToDeclaration()
Safely cast to a Declaration, or null.
const XMLUnknown * ToUnknown() const
const XMLConstHandle PreviousSiblingElement(const char *_value=0) const
virtual XMLDocument * ToDocument()
Safely cast to a Document, or null.
const XMLAttribute * Next() const
The next attribute in the list.
const char * CStr() const
const XMLConstHandle NextSibling() const
virtual bool VisitEnter(const XMLDocument &)
Visit a document.
virtual XMLDocument * ToDocument()
Safely cast to a Document, or null.
JSON (JavaScript Object Notation).
XMLError QueryFloatAttribute(const char *name, float *value) const
See QueryIntAttribute()
static bool IsNameStartChar(unsigned char ch)
void SetAttribute(const char *name, int value)
Sets the named attribute to value.
virtual bool Visit(const XMLUnknown &)
Visit an unknown node.