diff --git a/plugins/processing/riemannian/src/3rd-party/tinyxml2.cpp b/plugins/processing/riemannian/src/3rd-party/tinyxml2.cpp index 532a8e55be4ee7d064c5a48bfe0b73fda2d781f8..1ab61eb00fc3945c86171bfe4166c408638d81e7 100644 --- a/plugins/processing/riemannian/src/3rd-party/tinyxml2.cpp +++ b/plugins/processing/riemannian/src/3rd-party/tinyxml2.cpp @@ -23,12 +23,17 @@ distribution. #include "tinyxml2.h" -#include <new> -#include <cstddef> -#include <cstdarg> +#include <new> // yes, this one new style header, is in the Android SDK. +#if defined(ANDROID_NDK) || defined(__BORLANDC__) || defined(__QNXNTO__) +# include <stddef.h> +# include <stdarg.h> +#else +# include <cstddef> +# include <cstdarg> +#endif -#if defined(_MSC_VER) && (_MSC_VER >= 1400 ) -// Microsoft Visual Studio, version 2005 and higher. +#if defined(_MSC_VER) && (_MSC_VER >= 1400 ) && (!defined WINCE) +// Microsoft Visual Studio, version 2005 and higher. Not WinCE. /*int _snprintf_s( char *buffer, size_t sizeOfBuffer, @@ -36,22 +41,51 @@ distribution. const char *format [, argument] ... );*/ -static int TIXML_SNPRINTF(char* buffer, const size_t size, const char* format, ...) +static inline int TIXML_SNPRINTF(char* buffer, size_t size, const char* format, ...) { va_list va; va_start(va, format); - const int result = vsnprintf_s(buffer, size, _TRUNCATE, format, va); + int result = vsnprintf_s(buffer, size, _TRUNCATE, format, va); va_end(va); return result; } -static int TIXML_VSNPRINTF(char* buffer, const size_t size, const char* format, va_list va) +static inline int TIXML_VSNPRINTF(char* buffer, size_t size, const char* format, va_list va) { - return vsnprintf_s(buffer, size, _TRUNCATE, format, va); + int result = vsnprintf_s(buffer, size, _TRUNCATE, format, va); + return result; } #define TIXML_VSCPRINTF _vscprintf #define TIXML_SSCANF sscanf_s +#elif defined _MSC_VER +// Microsoft Visual Studio 2003 and earlier or WinCE +#define TIXML_SNPRINTF _snprintf +#define TIXML_VSNPRINTF _vsnprintf +#define TIXML_SSCANF sscanf +#if (_MSC_VER < 1400 ) && (!defined WINCE) + // Microsoft Visual Studio 2003 and not WinCE. +#define TIXML_VSCPRINTF _vscprintf // VS2003's C runtime has this, but VC6 C runtime or WinCE SDK doesn't have. +#else + // Microsoft Visual Studio 2003 and earlier or WinCE. +static inline int TIXML_VSCPRINTF(const char* format, va_list va) +{ + int len = 512; + for (;;) { + len = len * 2; + char* str = new char[len](); + const int required = _vsnprintf(str, len, format, va); + delete[] str; + if (required != -1) { + TIXMLASSERT(required >= 0); + len = required; + break; + } + } + TIXMLASSERT(len >= 0); + return len; +} +#endif #else // GCC version 3 and higher //#warning( "Using sn* functions." ) @@ -67,9 +101,9 @@ static inline int TIXML_VSCPRINTF(const char* format, va_list va) #endif -static const char LINE_FEED = char(0x0a); // all line endings are normalized to LF +static const char LINE_FEED = (char)0x0a; // all line endings are normalized to LF static const char LF = LINE_FEED; -static const char CARRIAGE_RETURN = char(0x0d); // CR gets filtered out +static const char CARRIAGE_RETURN = (char)0x0d; // CR gets filtered out static const char CR = CARRIAGE_RETURN; static const char SINGLE_QUOTE = '\''; static const char DOUBLE_QUOTE = '\"'; @@ -84,8 +118,8 @@ static const unsigned char TIXML_UTF_LEAD_2 = 0xbfU; namespace tinyxml2 { - struct Entity - { + + struct Entity { const char* pattern; int length; char value; @@ -93,13 +127,20 @@ namespace tinyxml2 static const int NUM_ENTITIES = 5; static const Entity entities[NUM_ENTITIES] = { - { "quot", 4, DOUBLE_QUOTE }, - { "amp", 3, '&' }, - { "apos", 4, SINGLE_QUOTE }, - { "lt", 2, '<' }, - { "gt", 2, '>' } + { "quot", 4, DOUBLE_QUOTE }, + { "amp", 3, '&' }, + { "apos", 4, SINGLE_QUOTE }, + { "lt", 2, '<' }, + { "gt", 2, '>' } }; + + StrPair::~StrPair() + { + Reset(); + } + + void StrPair::TransferTo(StrPair* other) { if (this == other) { return; } @@ -118,25 +159,27 @@ namespace tinyxml2 other->_end = _end; _flags = 0; - _start = nullptr; - _end = nullptr; + _start = 0; + _end = 0; } void StrPair::Reset() { - if (_flags & NEEDS_DELETE) { delete[] _start; } + if (_flags & NEEDS_DELETE) { + delete[] _start; + } _flags = 0; - _start = nullptr; - _end = nullptr; + _start = 0; + _end = 0; } - void StrPair::SetStr(const char* str, const int flags) + void StrPair::SetStr(const char* str, int flags) { TIXMLASSERT(str); Reset(); - const size_t len = strlen(str); + size_t len = strlen(str); TIXMLASSERT(_start == 0); _start = new char[len + 1]; memcpy(_start, str, len + 1); @@ -145,43 +188,45 @@ namespace tinyxml2 } - char* StrPair::ParseText(char* in, const char* endTag, const int strFlags, int* curLineNumPtr) + char* StrPair::ParseText(char* p, const char* endTag, int strFlags, int* curLineNumPtr) { TIXMLASSERT(p); TIXMLASSERT(endTag && *endTag); TIXMLASSERT(curLineNumPtr); - char* start = in; - const char endChar = *endTag; - const size_t length = strlen(endTag); + char* start = p; + char endChar = *endTag; + size_t length = strlen(endTag); // Inner loop of text parsing. - while (*in) - { - if (*in == endChar && strncmp(in, endTag, length) == 0) - { - Set(start, in, strFlags); - return in + length; + while (*p) { + if (*p == endChar && strncmp(p, endTag, length) == 0) { + Set(start, p, strFlags); + return p + length; + } + else if (*p == '\n') { + ++(*curLineNumPtr); } - if (*in == '\n') { ++(*curLineNumPtr); } - ++in; + ++p; TIXMLASSERT(p); } - return nullptr; + return 0; } - char* StrPair::ParseName(char* in) + char* StrPair::ParseName(char* p) { - if (!in || !(*in)) { return nullptr; } - if (!XMLUtil::IsNameStartChar(*in)) { return nullptr; } + if (!p || !(*p)) { return 0; } + if (!XMLUtil::IsNameStartChar(*p)) { return 0; } - char* const start = in; - ++in; - while (*in && XMLUtil::IsNameChar(*in)) { ++in; } + char* const start = p; + ++p; + while (*p && XMLUtil::IsNameChar(*p)) { + ++p; + } - Set(start, in, 0); - return in; + Set(start, p, 0); + return p; } @@ -190,19 +235,18 @@ namespace tinyxml2 // Adjusting _start would cause undefined behavior on delete[] TIXMLASSERT((_flags & NEEDS_DELETE) == 0); // Trim leading space. - _start = XMLUtil::SkipWhiteSpace(_start, nullptr); + _start = XMLUtil::SkipWhiteSpace(_start, 0); - if (*_start) - { + if (*_start) { const char* p = _start; // the read pointer char* q = _start; // the write pointer - while (*p) - { - if (XMLUtil::IsWhiteSpace(*p)) - { - p = XMLUtil::SkipWhiteSpace(p, nullptr); - if (*p == 0) { break; } // don't write to q; this trims the trailing space. + while (*p) { + if (XMLUtil::IsWhiteSpace(*p)) { + p = XMLUtil::SkipWhiteSpace(p, 0); + if (*p == 0) { + break; // don't write to q; this trims the trailing space. + } *q = ' '; ++q; } @@ -219,56 +263,55 @@ namespace tinyxml2 { TIXMLASSERT(_start); TIXMLASSERT(_end); - if (_flags & NEEDS_FLUSH) - { + if (_flags & NEEDS_FLUSH) { *_end = 0; _flags ^= NEEDS_FLUSH; - if (_flags) - { + if (_flags) { const char* p = _start; // the read pointer char* q = _start; // the write pointer - while (p < _end) - { - if ((_flags & NEEDS_NEWLINE_NORMALIZATION) && *p == CR) - { + while (p < _end) { + if ((_flags & NEEDS_NEWLINE_NORMALIZATION) && *p == CR) { // CR-LF pair becomes LF // CR alone becomes LF // LF-CR becomes LF - if (*(p + 1) == LF) { p += 2; } - else { ++p; } + if (*(p + 1) == LF) { + p += 2; + } + else { + ++p; + } *q = LF; ++q; } - else if ((_flags & NEEDS_NEWLINE_NORMALIZATION) && *p == LF) - { - if (*(p + 1) == CR) { p += 2; } - else { ++p; } + else if ((_flags & NEEDS_NEWLINE_NORMALIZATION) && *p == LF) { + if (*(p + 1) == CR) { + p += 2; + } + else { + ++p; + } *q = LF; ++q; } - else if ((_flags & NEEDS_ENTITY_PROCESSING) && *p == '&') - { + else if ((_flags & NEEDS_ENTITY_PROCESSING) && *p == '&') { // Entities handled by tinyXML2: // - special entities in the entity table [in/out] // - numeric character reference [in] // 中 or 中 - if (*(p + 1) == '#') - { + if (*(p + 1) == '#') { const int buflen = 10; char buf[buflen] = { 0 }; int len = 0; char* adjusted = const_cast<char*>(XMLUtil::GetCharacterRef(p, buf, &len)); - if (adjusted == nullptr) - { + if (adjusted == 0) { *q = *p; ++p; ++q; } - else - { + else { TIXMLASSERT(0 <= len && len <= buflen); TIXMLASSERT(q + len <= adjusted); p = adjusted; @@ -276,14 +319,12 @@ namespace tinyxml2 q += len; } } - else - { + else { bool entityFound = false; - for (auto entity : entities) - { + for (int i = 0; i < NUM_ENTITIES; ++i) { + const Entity& entity = entities[i]; if (strncmp(p + 1, entity.pattern, entity.length) == 0 - && *(p + entity.length + 1) == ';') - { + && *(p + entity.length + 1) == ';') { // Found an entity - convert. *q = entity.value; ++q; @@ -292,16 +333,14 @@ namespace tinyxml2 break; } } - if (!entityFound) - { + if (!entityFound) { // fixme: treat as error? ++p; ++q; } } } - else - { + else { *q = *p; ++p; ++q; @@ -311,7 +350,9 @@ namespace tinyxml2 } // The loop below has plenty going on, and this // is a less useful mode. Break it out. - if (_flags & NEEDS_WHITESPACE_COLLAPSING) { CollapseWhitespace(); } + if (_flags & NEEDS_WHITESPACE_COLLAPSING) { + CollapseWhitespace(); + } _flags = (_flags & NEEDS_DELETE); } TIXMLASSERT(_start); @@ -336,18 +377,17 @@ namespace tinyxml2 } - const char* XMLUtil::ReadBOM(const char* p, bool* hasBOM) + const char* XMLUtil::ReadBOM(const char* p, bool* bom) { TIXMLASSERT(p); TIXMLASSERT(bom); - *hasBOM = false; + *bom = false; const unsigned char* pu = reinterpret_cast<const unsigned char*>(p); // Check for BOM: if (*(pu + 0) == TIXML_UTF_LEAD_0 && *(pu + 1) == TIXML_UTF_LEAD_1 - && *(pu + 2) == TIXML_UTF_LEAD_2) - { - *hasBOM = true; + && *(pu + 2) == TIXML_UTF_LEAD_2) { + *bom = true; p += 3; } TIXMLASSERT(p); @@ -361,12 +401,19 @@ namespace tinyxml2 const unsigned long BYTE_MARK = 0x80; const unsigned long FIRST_BYTE_MARK[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC }; - if (input < 0x80) { *length = 1; } - else if (input < 0x800) { *length = 2; } - else if (input < 0x10000) { *length = 3; } - else if (input < 0x200000) { *length = 4; } - else - { + if (input < 0x80) { + *length = 1; + } + else if (input < 0x800) { + *length = 2; + } + else if (input < 0x10000) { + *length = 3; + } + else if (input < 0x200000) { + *length = 4; + } + else { *length = 0; // This code won't convert this correctly anyway. return; } @@ -375,29 +422,28 @@ namespace tinyxml2 // Scary scary fall throughs are annotated with carefully designed comments // to suppress compiler warnings such as -Wimplicit-fallthrough in gcc - switch (*length) - { - case 4: - --output; - *output = char((input | BYTE_MARK) & BYTE_MASK); - input >>= 6; - //fall through - case 3: - --output; - *output = char((input | BYTE_MARK) & BYTE_MASK); - input >>= 6; - //fall through - case 2: - --output; - *output = char((input | BYTE_MARK) & BYTE_MASK); - input >>= 6; - //fall through - case 1: - --output; - *output = char(input | FIRST_BYTE_MARK[*length]); - break; - default: - TIXMLASSERT(false); + switch (*length) { + case 4: + --output; + *output = (char)((input | BYTE_MARK) & BYTE_MASK); + input >>= 6; + //fall through + case 3: + --output; + *output = (char)((input | BYTE_MARK) & BYTE_MASK); + input >>= 6; + //fall through + case 2: + --output; + *output = (char)((input | BYTE_MARK) & BYTE_MASK); + input >>= 6; + //fall through + case 1: + --output; + *output = (char)(input | FIRST_BYTE_MARK[*length]); + break; + default: + TIXMLASSERT(false); } } @@ -407,36 +453,39 @@ namespace tinyxml2 // Presume an entity, and pull it out. *length = 0; - if (*(p + 1) == '#' && *(p + 2)) - { + if (*(p + 1) == '#' && *(p + 2)) { unsigned long ucs = 0; TIXMLASSERT(sizeof(ucs) >= 4); ptrdiff_t delta = 0; unsigned mult = 1; static const char SEMICOLON = ';'; - if (*(p + 2) == 'x') - { + if (*(p + 2) == 'x') { // Hexadecimal. const char* q = p + 3; - if (!(*q)) { return nullptr; } + if (!(*q)) { return 0; } q = strchr(q, SEMICOLON); - if (!q) { return nullptr; } + if (!q) { return 0; } TIXMLASSERT(*q == SEMICOLON); delta = q - p; --q; - while (*q != 'x') - { + while (*q != 'x') { unsigned int digit = 0; - if (*q >= '0' && *q <= '9') { digit = *q - '0'; } - else if (*q >= 'a' && *q <= 'f') { digit = *q - 'a' + 10; } - else if (*q >= 'A' && *q <= 'F') { digit = *q - 'A' + 10; } - else { return nullptr; } + if (*q >= '0' && *q <= '9') { + digit = *q - '0'; + } + else if (*q >= 'a' && *q <= 'f') { + digit = *q - 'a' + 10; + } + else if (*q >= 'A' && *q <= 'F') { + digit = *q - 'A' + 10; + } + else { return 0; } TIXMLASSERT(digit < 16); TIXMLASSERT(digit == 0 || mult <= UINT_MAX / digit); const unsigned int digitScaled = mult * digit; @@ -447,24 +496,21 @@ namespace tinyxml2 --q; } } - else - { + else { // Decimal. const char* q = p + 2; - if (!(*q)) { return nullptr; } + if (!(*q)) { return 0; } q = strchr(q, SEMICOLON); - if (!q) { return nullptr; } + if (!q) { return 0; } TIXMLASSERT(*q == SEMICOLON); delta = q - p; --q; - while (*q != '#') - { - if (*q >= '0' && *q <= '9') - { + while (*q != '#') { + if (*q >= '0' && *q <= '9') { const unsigned int digit = *q - '0'; TIXMLASSERT(digit < 10); TIXMLASSERT(digit == 0 || mult <= UINT_MAX / digit); @@ -472,7 +518,7 @@ namespace tinyxml2 TIXMLASSERT(ucs <= ULONG_MAX - digitScaled); ucs += digitScaled; } - else { return nullptr; } + else { return 0; } TIXMLASSERT(mult <= UINT_MAX / 10); mult *= 10; --q; @@ -486,19 +532,19 @@ namespace tinyxml2 } - void XMLUtil::ToStr(const int v, char* buffer, const int bufferSize) + void XMLUtil::ToStr(int v, char* buffer, int bufferSize) { TIXML_SNPRINTF(buffer, bufferSize, "%d", v); } - void XMLUtil::ToStr(const unsigned v, char* buffer, const int bufferSize) + void XMLUtil::ToStr(unsigned v, char* buffer, int bufferSize) { TIXML_SNPRINTF(buffer, bufferSize, "%u", v); } - void XMLUtil::ToStr(const bool v, char* buffer, const int bufferSize) + void XMLUtil::ToStr(bool v, char* buffer, int bufferSize) { TIXML_SNPRINTF(buffer, bufferSize, "%s", v ? writeBoolTrue : writeBoolFalse); } @@ -507,50 +553,49 @@ namespace tinyxml2 ToStr() of a number is a very tricky topic. https://github.com/leethomason/tinyxml2/issues/106 */ - void XMLUtil::ToStr(const float v, char* buffer, const int bufferSize) + void XMLUtil::ToStr(float v, char* buffer, int bufferSize) { TIXML_SNPRINTF(buffer, bufferSize, "%.8g", v); } - void XMLUtil::ToStr(const double v, char* buffer, const int bufferSize) + void XMLUtil::ToStr(double v, char* buffer, int bufferSize) { TIXML_SNPRINTF(buffer, bufferSize, "%.17g", v); } - void XMLUtil::ToStr(const int64_t v, char* buffer, const int bufferSize) + void XMLUtil::ToStr(int64_t v, char* buffer, int bufferSize) { // horrible syntax trick to make the compiler happy about %lld - TIXML_SNPRINTF(buffer, bufferSize, "%lld", static_cast<long long>(v)); + TIXML_SNPRINTF(buffer, bufferSize, "%lld", (long long)v); } bool XMLUtil::ToInt(const char* str, int* value) { - return (TIXML_SSCANF(str, "%d", value) == 1); + if (TIXML_SSCANF(str, "%d", value) == 1) { return true; } + return false; } - bool XMLUtil::ToUnsigned(const char* str, unsigned* value) + bool XMLUtil::ToUnsigned(const char* str, unsigned *value) { - return (TIXML_SSCANF(str, "%u", value) == 1); + if (TIXML_SSCANF(str, "%u", value) == 1) { return true; } + return false; } bool XMLUtil::ToBool(const char* str, bool* value) { int ival = 0; - if (ToInt(str, &ival)) - { - *value = ival != 0; + if (ToInt(str, &ival)) { + *value = (ival == 0) ? false : true; return true; } - if (StringEqual(str, "true")) - { + if (StringEqual(str, "true")) { *value = true; return true; } - if (StringEqual(str, "false")) - { + else if (StringEqual(str, "false")) { *value = false; return true; } @@ -560,22 +605,23 @@ namespace tinyxml2 bool XMLUtil::ToFloat(const char* str, float* value) { - return (TIXML_SSCANF(str, "%f", value) == 1); + if (TIXML_SSCANF(str, "%f", value) == 1) { return true; } + return false; } bool XMLUtil::ToDouble(const char* str, double* value) { - return (TIXML_SSCANF(str, "%lf", value) == 1); + if (TIXML_SSCANF(str, "%lf", value) == 1) { return true; } + return false; } bool XMLUtil::ToInt64(const char* str, int64_t* value) { long long v = 0; // horrible syntax trick to make the compiler happy about %lld - if (TIXML_SSCANF(str, "%lld", &v) == 1) - { - *value = int64_t(v); + if (TIXML_SSCANF(str, "%lld", &v) == 1) { + *value = (int64_t)v; return true; } return false; @@ -589,9 +635,8 @@ namespace tinyxml2 char* const start = p; int const startLine = _parseCurLineNum; p = XMLUtil::SkipWhiteSpace(p, &_parseCurLineNum); - if (!*p) - { - *node = nullptr; + if (!*p) { + *node = 0; TIXMLASSERT(p); return p; } @@ -611,41 +656,35 @@ namespace tinyxml2 TIXMLASSERT(sizeof(XMLComment) == sizeof(XMLUnknown)); // use same memory pool TIXMLASSERT(sizeof(XMLComment) == sizeof(XMLDeclaration)); // use same memory pool - XMLNode* returnNode = nullptr; - if (XMLUtil::StringEqual(p, xmlHeader, xmlHeaderLen)) - { + XMLNode* returnNode = 0; + if (XMLUtil::StringEqual(p, xmlHeader, xmlHeaderLen)) { returnNode = CreateUnlinkedNode<XMLDeclaration>(_commentPool); returnNode->_parseLineNum = _parseCurLineNum; p += xmlHeaderLen; } - else if (XMLUtil::StringEqual(p, commentHeader, commentHeaderLen)) - { + else if (XMLUtil::StringEqual(p, commentHeader, commentHeaderLen)) { returnNode = CreateUnlinkedNode<XMLComment>(_commentPool); returnNode->_parseLineNum = _parseCurLineNum; p += commentHeaderLen; } - else if (XMLUtil::StringEqual(p, cdataHeader, cdataHeaderLen)) - { + else if (XMLUtil::StringEqual(p, cdataHeader, cdataHeaderLen)) { XMLText* text = CreateUnlinkedNode<XMLText>(_textPool); returnNode = text; returnNode->_parseLineNum = _parseCurLineNum; p += cdataHeaderLen; text->SetCData(true); } - else if (XMLUtil::StringEqual(p, dtdHeader, dtdHeaderLen)) - { + else if (XMLUtil::StringEqual(p, dtdHeader, dtdHeaderLen)) { returnNode = CreateUnlinkedNode<XMLUnknown>(_commentPool); returnNode->_parseLineNum = _parseCurLineNum; p += dtdHeaderLen; } - else if (XMLUtil::StringEqual(p, elementHeader, elementHeaderLen)) - { + else if (XMLUtil::StringEqual(p, elementHeader, elementHeaderLen)) { returnNode = CreateUnlinkedNode<XMLElement>(_elementPool); returnNode->_parseLineNum = _parseCurLineNum; p += elementHeaderLen; } - else - { + else { returnNode = CreateUnlinkedNode<XMLText>(_textPool); returnNode->_parseLineNum = _parseCurLineNum; // Report line of first non-whitespace character p = start; // Back it up, all the text counts. @@ -662,11 +701,11 @@ namespace tinyxml2 bool XMLDocument::Accept(XMLVisitor* visitor) const { TIXMLASSERT(visitor); - if (visitor->VisitEnter(*this)) - { - for (const XMLNode* node = FirstChild(); node; node = node->NextSibling()) - { - if (!node->Accept(visitor)) { break; } + if (visitor->VisitEnter(*this)) { + for (const XMLNode* node = FirstChild(); node; node = node->NextSibling()) { + if (!node->Accept(visitor)) { + break; + } } } return visitor->VisitExit(*this); @@ -675,38 +714,51 @@ namespace tinyxml2 // --------- XMLNode ----------- // - XMLNode::XMLNode(XMLDocument* doc) - : _document(doc), _parent(nullptr), _parseLineNum(0), _firstChild(nullptr), - _lastChild(nullptr), _prev(nullptr), _next(nullptr), _userData(nullptr), _memPool(nullptr) { } + XMLNode::XMLNode(XMLDocument* doc) : + _document(doc), + _parent(0), + _value(), + _parseLineNum(0), + _firstChild(0), _lastChild(0), + _prev(0), _next(0), + _userData(0), + _memPool(0) + { + } XMLNode::~XMLNode() { DeleteChildren(); - if (_parent) { _parent->Unlink(this); } + if (_parent) { + _parent->Unlink(this); + } } const char* XMLNode::Value() const { // Edge case: XMLDocuments don't have a Value. Return null. if (this->ToDocument()) - return nullptr; + return 0; return _value.GetStr(); } - void XMLNode::SetValue(const char* str, const bool staticMem) + void XMLNode::SetValue(const char* str, bool staticMem) { - if (staticMem) { _value.SetInternedStr(str); } - else { _value.SetStr(str); } + if (staticMem) { + _value.SetInternedStr(str); + } + else { + _value.SetStr(str); + } } XMLNode* XMLNode::DeepClone(XMLDocument* target) const { XMLNode* clone = this->ShallowClone(target); - if (!clone) return nullptr; + if (!clone) return 0; - for (const XMLNode* child = this->FirstChild(); child; child = child->NextSibling()) - { + for (const XMLNode* child = this->FirstChild(); child; child = child->NextSibling()) { XMLNode* childClone = child->DeepClone(target); TIXMLASSERT(childClone); clone->InsertEndChild(childClone); @@ -716,12 +768,11 @@ namespace tinyxml2 void XMLNode::DeleteChildren() { - while (_firstChild) - { + while (_firstChild) { TIXMLASSERT(_lastChild); DeleteChild(_firstChild); } - _firstChild = _lastChild = nullptr; + _firstChild = _lastChild = 0; } @@ -730,14 +781,22 @@ namespace tinyxml2 TIXMLASSERT(child); TIXMLASSERT(child->_document == _document); TIXMLASSERT(child->_parent == this); - if (child == _firstChild) { _firstChild = _firstChild->_next; } - if (child == _lastChild) { _lastChild = _lastChild->_prev; } + if (child == _firstChild) { + _firstChild = _firstChild->_next; + } + if (child == _lastChild) { + _lastChild = _lastChild->_prev; + } - if (child->_prev) { child->_prev->_next = child->_next; } - if (child->_next) { child->_next->_prev = child->_prev; } - child->_next = nullptr; - child->_prev = nullptr; - child->_parent = nullptr; + if (child->_prev) { + child->_prev->_next = child->_next; + } + if (child->_next) { + child->_next->_prev = child->_prev; + } + child->_next = 0; + child->_prev = 0; + child->_parent = 0; } @@ -757,30 +816,27 @@ namespace tinyxml2 XMLNode* XMLNode::InsertEndChild(XMLNode* addThis) { TIXMLASSERT(addThis); - if (addThis->_document != _document) - { + if (addThis->_document != _document) { TIXMLASSERT(false); - return nullptr; + return 0; } InsertChildPreamble(addThis); - if (_lastChild) - { + if (_lastChild) { TIXMLASSERT(_firstChild); TIXMLASSERT(_lastChild->_next == 0); _lastChild->_next = addThis; addThis->_prev = _lastChild; _lastChild = addThis; - addThis->_next = nullptr; + addThis->_next = 0; } - else - { + else { TIXMLASSERT(_firstChild == 0); _firstChild = _lastChild = addThis; - addThis->_prev = nullptr; - addThis->_next = nullptr; + addThis->_prev = 0; + addThis->_next = 0; } addThis->_parent = this; return addThis; @@ -790,15 +846,13 @@ namespace tinyxml2 XMLNode* XMLNode::InsertFirstChild(XMLNode* addThis) { TIXMLASSERT(addThis); - if (addThis->_document != _document) - { + if (addThis->_document != _document) { TIXMLASSERT(false); - return nullptr; + return 0; } InsertChildPreamble(addThis); - if (_firstChild) - { + if (_firstChild) { TIXMLASSERT(_lastChild); TIXMLASSERT(_firstChild->_prev == 0); @@ -806,15 +860,14 @@ namespace tinyxml2 addThis->_next = _firstChild; _firstChild = addThis; - addThis->_prev = nullptr; + addThis->_prev = 0; } - else - { + else { TIXMLASSERT(_lastChild == 0); _firstChild = _lastChild = addThis; - addThis->_prev = nullptr; - addThis->_next = nullptr; + addThis->_prev = 0; + addThis->_next = 0; } addThis->_parent = this; return addThis; @@ -824,21 +877,18 @@ namespace tinyxml2 XMLNode* XMLNode::InsertAfterChild(XMLNode* afterThis, XMLNode* addThis) { TIXMLASSERT(addThis); - if (addThis->_document != _document) - { + if (addThis->_document != _document) { TIXMLASSERT(false); - return nullptr; + return 0; } TIXMLASSERT(afterThis); - if (afterThis->_parent != this) - { + if (afterThis->_parent != this) { TIXMLASSERT(false); - return nullptr; + return 0; } - if (afterThis == addThis) - { + if (afterThis == addThis) { // Current state: BeforeThis -> AddThis -> OneAfterAddThis // Now AddThis must disappear from it's location and then // reappear between BeforeThis and OneAfterAddThis. @@ -846,8 +896,7 @@ namespace tinyxml2 return addThis; } - if (afterThis->_next == nullptr) - { + if (afterThis->_next == 0) { // The last node or the only node. return InsertEndChild(addThis); } @@ -861,47 +910,45 @@ namespace tinyxml2 } + + const XMLElement* XMLNode::FirstChildElement(const char* name) const { - for (const XMLNode* node = _firstChild; node; node = node->_next) - { + for (const XMLNode* node = _firstChild; node; node = node->_next) { const XMLElement* element = node->ToElementWithName(name); if (element) { return element; } } - return nullptr; + return 0; } const XMLElement* XMLNode::LastChildElement(const char* name) const { - for (const XMLNode* node = _lastChild; node; node = node->_prev) - { + for (const XMLNode* node = _lastChild; node; node = node->_prev) { const XMLElement* element = node->ToElementWithName(name); if (element) { return element; } } - return nullptr; + return 0; } const XMLElement* XMLNode::NextSiblingElement(const char* name) const { - for (const XMLNode* node = _next; node; node = node->_next) - { + for (const XMLNode* node = _next; node; node = node->_next) { const XMLElement* element = node->ToElementWithName(name); if (element) { return element; } } - return nullptr; + return 0; } const XMLElement* XMLNode::PreviousSiblingElement(const char* name) const { - for (const XMLNode* node = _prev; node; node = node->_prev) - { + for (const XMLNode* node = _prev; node; node = node->_prev) { const XMLElement* element = node->ToElementWithName(name); if (element) { return element; } } - return nullptr; + return 0; } @@ -925,31 +972,32 @@ namespace tinyxml2 // 'parentEnd' is the end tag for the parent, which is filled in and returned. XMLDocument::DepthTracker tracker(_document); + if (_document->Error()) + return 0; - if (_document->Error()) { return nullptr; } - - while (p && *p) - { - XMLNode* node = nullptr; + while (p && *p) { + XMLNode* node = 0; p = _document->Identify(p, &node); TIXMLASSERT(p); - if (node == nullptr) { break; } + if (node == 0) { + break; + } - const int initialLineNum = node->_parseLineNum; + int initialLineNum = node->_parseLineNum; StrPair endTag; p = node->ParseDeep(p, &endTag, curLineNumPtr); - if (!p) - { + if (!p) { DeleteNode(node); - if (!_document->Error()) { _document->SetError(XML_ERROR_PARSING, initialLineNum, nullptr); } + if (!_document->Error()) { + _document->SetError(XML_ERROR_PARSING, initialLineNum, 0); + } break; } XMLDeclaration* decl = node->ToDeclaration(); - if (decl) - { + if (decl) { // Declarations are only allowed at document level // // Multiple declarations are allowed but all declarations @@ -960,16 +1008,19 @@ namespace tinyxml2 // declarations have so far been addded. bool wellLocated = false; - if (ToDocument()) - { - if (FirstChild()) - { - wellLocated = FirstChild() && FirstChild()->ToDeclaration() && LastChild() && LastChild()->ToDeclaration(); + if (ToDocument()) { + if (FirstChild()) { + wellLocated = + FirstChild() && + FirstChild()->ToDeclaration() && + LastChild() && + LastChild()->ToDeclaration(); + } + else { + wellLocated = true; } - else { wellLocated = true; } } - if (!wellLocated) - { + if (!wellLocated) { _document->SetError(XML_ERROR_PARSING_DECLARATION, initialLineNum, "XMLDeclaration value=%s", decl->Value()); DeleteNode(node); break; @@ -977,12 +1028,12 @@ namespace tinyxml2 } XMLElement* ele = node->ToElement(); - if (ele) - { + if (ele) { // We read the end tag. Return it to the parent. - if (ele->ClosingType() == XMLElement::CLOSING) - { - if (parentEndTag) { ele->_value.TransferTo(parentEndTag); } + if (ele->ClosingType() == XMLElement::CLOSING) { + if (parentEndTag) { + ele->_value.TransferTo(parentEndTag); + } node->_memPool->SetTracked(); // created and then immediately deleted. DeleteNode(node); return p; @@ -991,17 +1042,20 @@ namespace tinyxml2 // Handle an end tag returned to this level. // And handle a bunch of annoying errors. bool mismatch = false; - if (endTag.Empty()) - { - if (ele->ClosingType() == XMLElement::OPEN) { mismatch = true; } + if (endTag.Empty()) { + if (ele->ClosingType() == XMLElement::OPEN) { + mismatch = true; + } } - else - { - if (ele->ClosingType() != XMLElement::OPEN) { mismatch = true; } - else if (!XMLUtil::StringEqual(endTag.GetStr(), ele->Name())) { mismatch = true; } + else { + if (ele->ClosingType() != XMLElement::OPEN) { + mismatch = true; + } + else if (!XMLUtil::StringEqual(endTag.GetStr(), ele->Name())) { + mismatch = true; + } } - if (mismatch) - { + if (mismatch) { _document->SetError(XML_ERROR_MISMATCHED_ELEMENT, initialLineNum, "XMLElement name=%s", ele->Name()); DeleteNode(node); break; @@ -1009,29 +1063,33 @@ namespace tinyxml2 } InsertEndChild(node); } - return nullptr; + return 0; } - /*static*/ - void XMLNode::DeleteNode(XMLNode* node) + /*static*/ void XMLNode::DeleteNode(XMLNode* node) { - if (node == nullptr) { return; } + if (node == 0) { + return; + } TIXMLASSERT(node->_document); - if (!node->ToDocument()) { node->_document->MarkInUse(node); } + if (!node->ToDocument()) { + node->_document->MarkInUse(node); + } MemPool* pool = node->_memPool; node->~XMLNode(); pool->Free(node); } - void XMLNode::InsertChildPreamble(XMLNode* insertThis) + void XMLNode::InsertChildPreamble(XMLNode* insertThis) const { TIXMLASSERT(insertThis); TIXMLASSERT(insertThis->_document == _document); - if (insertThis->_parent) { insertThis->_parent->Unlink(insertThis); } - else - { + if (insertThis->_parent) { + insertThis->_parent->Unlink(insertThis); + } + else { insertThis->_document->MarkInUse(insertThis); insertThis->_memPool->SetTracked(); } @@ -1040,37 +1098,43 @@ namespace tinyxml2 const XMLElement* XMLNode::ToElementWithName(const char* name) const { const XMLElement* element = this->ToElement(); - if (element == nullptr) { return nullptr; } - if (name == nullptr) { return element; } + if (element == 0) { return 0; } + if (name == 0) { return element; } if (XMLUtil::StringEqual(element->Name(), name)) { return element; } - return nullptr; + return 0; } // --------- XMLText ---------- // char* XMLText::ParseDeep(char* p, StrPair*, int* curLineNumPtr) { - if (this->CData()) - { + if (this->CData()) { p = _value.ParseText(p, "]]>", StrPair::NEEDS_NEWLINE_NORMALIZATION, curLineNumPtr); - if (!p) { _document->SetError(XML_ERROR_PARSING_CDATA, _parseLineNum, nullptr); } + if (!p) { + _document->SetError(XML_ERROR_PARSING_CDATA, _parseLineNum, 0); + } return p; } - int flags = _document->ProcessEntities() ? StrPair::TEXT_ELEMENT : StrPair::TEXT_ELEMENT_LEAVE_ENTITIES; - if (_document->WhitespaceMode() == COLLAPSE_WHITESPACE) - { - flags |= StrPair::NEEDS_WHITESPACE_COLLAPSING; - } + else { + int flags = _document->ProcessEntities() ? StrPair::TEXT_ELEMENT : StrPair::TEXT_ELEMENT_LEAVE_ENTITIES; + if (_document->WhitespaceMode() == COLLAPSE_WHITESPACE) { + flags |= StrPair::NEEDS_WHITESPACE_COLLAPSING; + } - p = _value.ParseText(p, "<", flags, curLineNumPtr); - if (p && *p) { return p - 1; } - if (!p) { _document->SetError(XML_ERROR_PARSING_TEXT, _parseLineNum, nullptr); } - return nullptr; + p = _value.ParseText(p, "<", flags, curLineNumPtr); + if (p && *p) { return p - 1; } + if (!p) { + _document->SetError(XML_ERROR_PARSING_TEXT, _parseLineNum, 0); + } + } + return 0; } XMLNode* XMLText::ShallowClone(XMLDocument* doc) const { - if (!doc) { doc = _document; } + if (!doc) { + doc = _document; + } XMLText* text = doc->NewText(Value()); // fixme: this will always allocate memory. Intern? text->SetCData(this->CData()); return text; @@ -1091,24 +1155,35 @@ namespace tinyxml2 return visitor->Visit(*this); } + // --------- XMLComment ---------- // - XMLComment::XMLComment(XMLDocument* doc) : XMLNode(doc) { } + XMLComment::XMLComment(XMLDocument* doc) : XMLNode(doc) + { + } + + + XMLComment::~XMLComment() + { + } - XMLComment::~XMLComment() = default; char* XMLComment::ParseDeep(char* p, StrPair*, int* curLineNumPtr) { // Comment parses as text. p = _value.ParseText(p, "-->", StrPair::COMMENT, curLineNumPtr); - if (p == nullptr) { _document->SetError(XML_ERROR_PARSING_COMMENT, _parseLineNum, nullptr); } + if (p == 0) { + _document->SetError(XML_ERROR_PARSING_COMMENT, _parseLineNum, 0); + } return p; } XMLNode* XMLComment::ShallowClone(XMLDocument* doc) const { - if (!doc) { doc = _document; } + if (!doc) { + doc = _document; + } XMLComment* comment = doc->NewComment(Value()); // fixme: this will always allocate memory. Intern? return comment; } @@ -1131,24 +1206,33 @@ namespace tinyxml2 // --------- XMLDeclaration ---------- // - XMLDeclaration::XMLDeclaration(XMLDocument* doc) : XMLNode(doc) { } + XMLDeclaration::XMLDeclaration(XMLDocument* doc) : XMLNode(doc) + { + } - XMLDeclaration::~XMLDeclaration() = default; //printf( "~XMLDeclaration\n" ); + XMLDeclaration::~XMLDeclaration() + { + //printf( "~XMLDeclaration\n" ); + } char* XMLDeclaration::ParseDeep(char* p, StrPair*, int* curLineNumPtr) { // Declaration parses as text. p = _value.ParseText(p, "?>", StrPair::NEEDS_NEWLINE_NORMALIZATION, curLineNumPtr); - if (p == nullptr) { _document->SetError(XML_ERROR_PARSING_DECLARATION, _parseLineNum, nullptr); } + if (p == 0) { + _document->SetError(XML_ERROR_PARSING_DECLARATION, _parseLineNum, 0); + } return p; } XMLNode* XMLDeclaration::ShallowClone(XMLDocument* doc) const { - if (!doc) { doc = _document; } + if (!doc) { + doc = _document; + } XMLDeclaration* dec = doc->NewDeclaration(Value()); // fixme: this will always allocate memory. Intern? return dec; } @@ -1162,6 +1246,7 @@ namespace tinyxml2 } + bool XMLDeclaration::Accept(XMLVisitor* visitor) const { TIXMLASSERT(visitor); @@ -1170,22 +1255,32 @@ namespace tinyxml2 // --------- XMLUnknown ---------- // - XMLUnknown::XMLUnknown(XMLDocument* doc) : XMLNode(doc) { } + XMLUnknown::XMLUnknown(XMLDocument* doc) : XMLNode(doc) + { + } + + + XMLUnknown::~XMLUnknown() + { + } - XMLUnknown::~XMLUnknown() = default; char* XMLUnknown::ParseDeep(char* p, StrPair*, int* curLineNumPtr) { // Unknown parses as text. p = _value.ParseText(p, ">", StrPair::NEEDS_NEWLINE_NORMALIZATION, curLineNumPtr); - if (!p) { _document->SetError(XML_ERROR_PARSING_UNKNOWN, _parseLineNum, nullptr); } + if (!p) { + _document->SetError(XML_ERROR_PARSING_UNKNOWN, _parseLineNum, 0); + } return p; } XMLNode* XMLUnknown::ShallowClone(XMLDocument* doc) const { - if (!doc) { doc = _document; } + if (!doc) { + doc = _document; + } XMLUnknown* text = doc->NewUnknown(Value()); // fixme: this will always allocate memory. Intern? return text; } @@ -1207,22 +1302,29 @@ namespace tinyxml2 // --------- XMLAttribute ---------- // - const char* XMLAttribute::Name() const { return _name.GetStr(); } - const char* XMLAttribute::Value() const { return _value.GetStr(); } + const char* XMLAttribute::Name() const + { + return _name.GetStr(); + } + + const char* XMLAttribute::Value() const + { + return _value.GetStr(); + } - char* XMLAttribute::ParseDeep(char* p, const bool processEntities, int* curLineNumPtr) const + char* XMLAttribute::ParseDeep(char* p, bool processEntities, int* curLineNumPtr) { // Parse using the name rules: bug fix, was using ParseText before p = _name.ParseName(p); - if (!p || !*p) { return nullptr; } + if (!p || !*p) { return 0; } // Skip white space before = p = XMLUtil::SkipWhiteSpace(p, curLineNumPtr); - if (*p != '=') { return nullptr; } + if (*p != '=') { return 0; } ++p; // move up to opening quote p = XMLUtil::SkipWhiteSpace(p, curLineNumPtr); - if (*p != '\"' && *p != '\'') { return nullptr; } + if (*p != '\"' && *p != '\'') { return 0; } char endTag[2] = { *p, 0 }; ++p; // move past opening quote @@ -1232,7 +1334,10 @@ namespace tinyxml2 } - void XMLAttribute::SetName(const char* name) { _name.SetStr(name); } + void XMLAttribute::SetName(const char* n) + { + _name.SetStr(n); + } XMLError XMLAttribute::QueryIntValue(int* value) const @@ -1277,65 +1382,70 @@ namespace tinyxml2 } - void XMLAttribute::SetAttribute(const char* value) + void XMLAttribute::SetAttribute(const char* v) { - _value.SetStr(value); + _value.SetStr(v); } - void XMLAttribute::SetAttribute(const int value) + void XMLAttribute::SetAttribute(int v) { char buf[BUF_SIZE]; - XMLUtil::ToStr(value, buf, BUF_SIZE); + XMLUtil::ToStr(v, buf, BUF_SIZE); _value.SetStr(buf); } - void XMLAttribute::SetAttribute(const unsigned value) + void XMLAttribute::SetAttribute(unsigned v) { char buf[BUF_SIZE]; - XMLUtil::ToStr(value, buf, BUF_SIZE); + XMLUtil::ToStr(v, buf, BUF_SIZE); _value.SetStr(buf); } - void XMLAttribute::SetAttribute(const int64_t value) + void XMLAttribute::SetAttribute(int64_t v) { char buf[BUF_SIZE]; - XMLUtil::ToStr(value, buf, BUF_SIZE); + XMLUtil::ToStr(v, buf, BUF_SIZE); _value.SetStr(buf); } - void XMLAttribute::SetAttribute(const bool value) + + void XMLAttribute::SetAttribute(bool v) { char buf[BUF_SIZE]; - XMLUtil::ToStr(value, buf, BUF_SIZE); + XMLUtil::ToStr(v, buf, BUF_SIZE); _value.SetStr(buf); } - void XMLAttribute::SetAttribute(const double value) + void XMLAttribute::SetAttribute(double v) { char buf[BUF_SIZE]; - XMLUtil::ToStr(value, buf, BUF_SIZE); + XMLUtil::ToStr(v, buf, BUF_SIZE); _value.SetStr(buf); } - void XMLAttribute::SetAttribute(const float value) + void XMLAttribute::SetAttribute(float v) { char buf[BUF_SIZE]; - XMLUtil::ToStr(value, buf, BUF_SIZE); + XMLUtil::ToStr(v, buf, BUF_SIZE); _value.SetStr(buf); } // --------- XMLElement ---------- // - XMLElement::XMLElement(XMLDocument* doc) : XMLNode(doc) { } + XMLElement::XMLElement(XMLDocument* doc) : XMLNode(doc), + _closingType(OPEN), + _rootAttribute(0) + { + } + XMLElement::~XMLElement() { - while (_rootAttribute) - { + while (_rootAttribute) { XMLAttribute* next = _rootAttribute->_next; DeleteAttribute(_rootAttribute); _rootAttribute = next; @@ -1345,58 +1455,57 @@ namespace tinyxml2 const XMLAttribute* XMLElement::FindAttribute(const char* name) const { - for (XMLAttribute* a = _rootAttribute; a; a = a->_next) - { + for (XMLAttribute* a = _rootAttribute; a; a = a->_next) { if (XMLUtil::StringEqual(a->Name(), name)) { return a; } } - return nullptr; + return 0; } const char* XMLElement::Attribute(const char* name, const char* value) const { const XMLAttribute* a = FindAttribute(name); - if (!a) { return nullptr; } + if (!a) { return 0; } if (!value || XMLUtil::StringEqual(a->Value(), value)) { return a->Value(); } - return nullptr; + return 0; } - int XMLElement::IntAttribute(const char* name, const int defaultValue) const + int XMLElement::IntAttribute(const char* name, int defaultValue) const { int i = defaultValue; QueryIntAttribute(name, &i); return i; } - unsigned XMLElement::UnsignedAttribute(const char* name, const unsigned defaultValue) const + unsigned XMLElement::UnsignedAttribute(const char* name, unsigned defaultValue) const { unsigned i = defaultValue; QueryUnsignedAttribute(name, &i); return i; } - int64_t XMLElement::Int64Attribute(const char* name, const int64_t defaultValue) const + int64_t XMLElement::Int64Attribute(const char* name, int64_t defaultValue) const { int64_t i = defaultValue; QueryInt64Attribute(name, &i); return i; } - bool XMLElement::BoolAttribute(const char* name, const bool defaultValue) const + bool XMLElement::BoolAttribute(const char* name, bool defaultValue) const { bool b = defaultValue; QueryBoolAttribute(name, &b); return b; } - double XMLElement::DoubleAttribute(const char* name, const double defaultValue) const + double XMLElement::DoubleAttribute(const char* name, double defaultValue) const { double d = defaultValue; QueryDoubleAttribute(name, &d); return d; } - float XMLElement::FloatAttribute(const char* name, const float defaultValue) const + float XMLElement::FloatAttribute(const char* name, float defaultValue) const { float f = defaultValue; QueryFloatAttribute(name, &f); @@ -1406,73 +1515,72 @@ namespace tinyxml2 const char* XMLElement::GetText() const { if (FirstChild() && FirstChild()->ToText()) { return FirstChild()->Value(); } - return nullptr; + return 0; } - void XMLElement::SetText(const char* inText) + void XMLElement::SetText(const char* inText) { - if (FirstChild() && FirstChild()->ToText()) { FirstChild()->SetValue(inText); } - else - { - XMLText* theText = GetDocument()->NewText(inText); + if (FirstChild() && FirstChild()->ToText()) + FirstChild()->SetValue(inText); + else { + XMLText* theText = GetDocument()->NewText(inText); InsertFirstChild(theText); } } - void XMLElement::SetText(const int value) + void XMLElement::SetText(int v) { char buf[BUF_SIZE]; - XMLUtil::ToStr(value, buf, BUF_SIZE); + XMLUtil::ToStr(v, buf, BUF_SIZE); SetText(buf); } - void XMLElement::SetText(const unsigned value) + void XMLElement::SetText(unsigned v) { char buf[BUF_SIZE]; - XMLUtil::ToStr(value, buf, BUF_SIZE); + XMLUtil::ToStr(v, buf, BUF_SIZE); SetText(buf); } - void XMLElement::SetText(const int64_t value) + void XMLElement::SetText(int64_t v) { char buf[BUF_SIZE]; - XMLUtil::ToStr(value, buf, BUF_SIZE); + XMLUtil::ToStr(v, buf, BUF_SIZE); SetText(buf); } - void XMLElement::SetText(const bool value) + void XMLElement::SetText(bool v) { char buf[BUF_SIZE]; - XMLUtil::ToStr(value, buf, BUF_SIZE); + XMLUtil::ToStr(v, buf, BUF_SIZE); SetText(buf); } - void XMLElement::SetText(const float value) + void XMLElement::SetText(float v) { char buf[BUF_SIZE]; - XMLUtil::ToStr(value, buf, BUF_SIZE); + XMLUtil::ToStr(v, buf, BUF_SIZE); SetText(buf); } - void XMLElement::SetText(const double value) + void XMLElement::SetText(double v) { char buf[BUF_SIZE]; - XMLUtil::ToStr(value, buf, BUF_SIZE); + XMLUtil::ToStr(v, buf, BUF_SIZE); SetText(buf); } XMLError XMLElement::QueryIntText(int* ival) const { - if (FirstChild() && FirstChild()->ToText()) - { + if (FirstChild() && FirstChild()->ToText()) { const char* t = FirstChild()->Value(); if (XMLUtil::ToInt(t, ival)) { return XML_SUCCESS; } return XML_CAN_NOT_CONVERT_TEXT; @@ -1483,8 +1591,7 @@ namespace tinyxml2 XMLError XMLElement::QueryUnsignedText(unsigned* uval) const { - if (FirstChild() && FirstChild()->ToText()) - { + if (FirstChild() && FirstChild()->ToText()) { const char* t = FirstChild()->Value(); if (XMLUtil::ToUnsigned(t, uval)) { return XML_SUCCESS; } return XML_CAN_NOT_CONVERT_TEXT; @@ -1495,8 +1602,7 @@ namespace tinyxml2 XMLError XMLElement::QueryInt64Text(int64_t* ival) const { - if (FirstChild() && FirstChild()->ToText()) - { + if (FirstChild() && FirstChild()->ToText()) { const char* t = FirstChild()->Value(); if (XMLUtil::ToInt64(t, ival)) { return XML_SUCCESS; } return XML_CAN_NOT_CONVERT_TEXT; @@ -1507,8 +1613,7 @@ namespace tinyxml2 XMLError XMLElement::QueryBoolText(bool* bval) const { - if (FirstChild() && FirstChild()->ToText()) - { + if (FirstChild() && FirstChild()->ToText()) { const char* t = FirstChild()->Value(); if (XMLUtil::ToBool(t, bval)) { return XML_SUCCESS; } return XML_CAN_NOT_CONVERT_TEXT; @@ -1519,8 +1624,7 @@ namespace tinyxml2 XMLError XMLElement::QueryDoubleText(double* dval) const { - if (FirstChild() && FirstChild()->ToText()) - { + if (FirstChild() && FirstChild()->ToText()) { const char* t = FirstChild()->Value(); if (XMLUtil::ToDouble(t, dval)) { return XML_SUCCESS; } return XML_CAN_NOT_CONVERT_TEXT; @@ -1531,8 +1635,7 @@ namespace tinyxml2 XMLError XMLElement::QueryFloatText(float* fval) const { - if (FirstChild() && FirstChild()->ToText()) - { + if (FirstChild() && FirstChild()->ToText()) { const char* t = FirstChild()->Value(); if (XMLUtil::ToFloat(t, fval)) { return XML_SUCCESS; } return XML_CAN_NOT_CONVERT_TEXT; @@ -1540,42 +1643,42 @@ namespace tinyxml2 return XML_NO_TEXT_NODE; } - int XMLElement::IntText(const int defaultValue) const + int XMLElement::IntText(int defaultValue) const { int i = defaultValue; QueryIntText(&i); return i; } - unsigned XMLElement::UnsignedText(const unsigned defaultValue) const + unsigned XMLElement::UnsignedText(unsigned defaultValue) const { unsigned i = defaultValue; QueryUnsignedText(&i); return i; } - int64_t XMLElement::Int64Text(const int64_t defaultValue) const + int64_t XMLElement::Int64Text(int64_t defaultValue) const { int64_t i = defaultValue; QueryInt64Text(&i); return i; } - bool XMLElement::BoolText(const bool defaultValue) const + bool XMLElement::BoolText(bool defaultValue) const { bool b = defaultValue; QueryBoolText(&b); return b; } - double XMLElement::DoubleText(const double defaultValue) const + double XMLElement::DoubleText(double defaultValue) const { double d = defaultValue; QueryDoubleText(&d); return d; } - float XMLElement::FloatText(const float defaultValue) const + float XMLElement::FloatText(float defaultValue) const { float f = defaultValue; QueryFloatText(&f); @@ -1585,23 +1688,23 @@ namespace tinyxml2 XMLAttribute* XMLElement::FindOrCreateAttribute(const char* name) { - XMLAttribute* last = nullptr; - XMLAttribute* attrib = nullptr; - for (attrib = _rootAttribute; attrib; last = attrib, attrib = attrib->_next) - { - if (XMLUtil::StringEqual(attrib->Name(), name)) { break; } + XMLAttribute* last = 0; + XMLAttribute* attrib = 0; + for (attrib = _rootAttribute; + attrib; + last = attrib, attrib = attrib->_next) { + if (XMLUtil::StringEqual(attrib->Name(), name)) { + break; + } } - if (!attrib) - { + if (!attrib) { attrib = CreateAttribute(); TIXMLASSERT(attrib); - if (last) - { + if (last) { TIXMLASSERT(last->_next == 0); last->_next = attrib; } - else - { + else { TIXMLASSERT(_rootAttribute == 0); _rootAttribute = attrib; } @@ -1613,13 +1716,15 @@ namespace tinyxml2 void XMLElement::DeleteAttribute(const char* name) { - XMLAttribute* prev = nullptr; - for (XMLAttribute* a = _rootAttribute; a; a = a->_next) - { - if (XMLUtil::StringEqual(name, a->Name())) - { - if (prev) { prev->_next = a->_next; } - else { _rootAttribute = a->_next; } + XMLAttribute* prev = 0; + for (XMLAttribute* a = _rootAttribute; a; a = a->_next) { + if (XMLUtil::StringEqual(name, a->Name())) { + if (prev) { + prev->_next = a->_next; + } + else { + _rootAttribute = a->_next; + } DeleteAttribute(a); break; } @@ -1630,67 +1735,58 @@ namespace tinyxml2 char* XMLElement::ParseAttributes(char* p, int* curLineNumPtr) { - XMLAttribute* prevAttribute = nullptr; + XMLAttribute* prevAttribute = 0; // Read the attributes. - while (p) - { + while (p) { p = XMLUtil::SkipWhiteSpace(p, curLineNumPtr); - if (!(*p)) - { + if (!(*p)) { _document->SetError(XML_ERROR_PARSING_ELEMENT, _parseLineNum, "XMLElement name=%s", Name()); - return nullptr; + return 0; } // attribute. - if (XMLUtil::IsNameStartChar(*p)) - { + if (XMLUtil::IsNameStartChar(*p)) { XMLAttribute* attrib = CreateAttribute(); TIXMLASSERT(attrib); attrib->_parseLineNum = _document->_parseCurLineNum; - const int attrLineNum = attrib->_parseLineNum; + int attrLineNum = attrib->_parseLineNum; p = attrib->ParseDeep(p, _document->ProcessEntities(), curLineNumPtr); - if (!p || Attribute(attrib->Name())) - { + if (!p || Attribute(attrib->Name())) { DeleteAttribute(attrib); _document->SetError(XML_ERROR_PARSING_ATTRIBUTE, attrLineNum, "XMLElement name=%s", Name()); - return nullptr; + return 0; } // There is a minor bug here: if the attribute in the source xml // document is duplicated, it will not be detected and the // attribute will be doubly added. However, tracking the 'prevAttribute' // avoids re-scanning the attribute list. Preferring performance for // now, may reconsider in the future. - if (prevAttribute) - { + if (prevAttribute) { TIXMLASSERT(prevAttribute->_next == 0); prevAttribute->_next = attrib; } - else - { + else { TIXMLASSERT(_rootAttribute == 0); _rootAttribute = attrib; } prevAttribute = attrib; } - // end of the tag - else if (*p == '>') - { + // end of the tag + else if (*p == '>') { ++p; break; } - // end of the tag - else if (*p == '/' && *(p + 1) == '>') - { + // end of the tag + else if (*p == '/' && *(p + 1) == '>') { _closingType = CLOSED; return p + 2; // done; sealed element. } - else - { - _document->SetError(XML_ERROR_PARSING_ELEMENT, _parseLineNum, nullptr); - return nullptr; + else { + _document->SetError(XML_ERROR_PARSING_ELEMENT, _parseLineNum, 0); + return 0; } } return p; @@ -1698,7 +1794,9 @@ namespace tinyxml2 void XMLElement::DeleteAttribute(XMLAttribute* attribute) { - if (attribute == nullptr) { return; } + if (attribute == 0) { + return; + } MemPool* pool = attribute->_memPool; attribute->~XMLAttribute(); pool->Free(attribute); @@ -1707,7 +1805,7 @@ namespace tinyxml2 XMLAttribute* XMLElement::CreateAttribute() { TIXMLASSERT(sizeof(XMLAttribute) == _document->_attributePool.ItemSize()); - XMLAttribute* attrib = new(_document->_attributePool.Alloc()) XMLAttribute(); + XMLAttribute* attrib = new (_document->_attributePool.Alloc()) XMLAttribute(); TIXMLASSERT(attrib); attrib->_memPool = &_document->_attributePool; attrib->_memPool->SetTracked(); @@ -1726,14 +1824,13 @@ namespace tinyxml2 // The closing element is the </element> form. It is // parsed just like a regular element then deleted from // the DOM. - if (*p == '/') - { + if (*p == '/') { _closingType = CLOSING; ++p; } p = _value.ParseName(p); - if (_value.Empty()) { return nullptr; } + if (_value.Empty()) { return 0; } p = ParseAttributes(p, curLineNumPtr); if (!p || !*p || _closingType != OPEN) { return p; } @@ -1743,12 +1840,14 @@ namespace tinyxml2 } + XMLNode* XMLElement::ShallowClone(XMLDocument* doc) const { - if (!doc) { doc = _document; } + if (!doc) { + doc = _document; + } XMLElement* element = doc->NewElement(Value()); // fixme: this will always allocate memory. Intern? - for (const XMLAttribute* a = FirstAttribute(); a; a = a->Next()) - { + for (const XMLAttribute* a = FirstAttribute(); a; a = a->Next()) { element->SetAttribute(a->Name(), a->Value()); // fixme: this will always allocate memory. Intern? } return element; @@ -1759,18 +1858,21 @@ namespace tinyxml2 { TIXMLASSERT(compare); const XMLElement* other = compare->ToElement(); - if (other && XMLUtil::StringEqual(other->Name(), Name())) - { + if (other && XMLUtil::StringEqual(other->Name(), Name())) { + const XMLAttribute* a = FirstAttribute(); const XMLAttribute* b = other->FirstAttribute(); - while (a && b) - { + while (a && b) { if (!XMLUtil::StringEqual(a->Value(), b->Value())) { return false; } a = a->Next(); b = b->Next(); } - return !(a || b); + if (a || b) { + // different count + return false; + } + return true; } return false; } @@ -1779,11 +1881,11 @@ namespace tinyxml2 bool XMLElement::Accept(XMLVisitor* visitor) const { TIXMLASSERT(visitor); - if (visitor->VisitEnter(*this, _rootAttribute)) - { - for (const XMLNode* node = FirstChild(); node; node = node->NextSibling()) - { - if (!node->Accept(visitor)) { break; } + if (visitor->VisitEnter(*this, _rootAttribute)) { + for (const XMLNode* node = FirstChild(); node; node = node->NextSibling()) { + if (!node->Accept(visitor)) { + break; + } } } return visitor->VisitExit(*this); @@ -1816,15 +1918,32 @@ namespace tinyxml2 }; - XMLDocument::XMLDocument(bool processEntities, Whitespace whitespaceMode) - : XMLNode(nullptr), _processEntities(processEntities), _whitespaceMode(whitespaceMode) + XMLDocument::XMLDocument(bool processEntities, Whitespace whitespaceMode) : + XMLNode(0), + _writeBOM(false), + _processEntities(processEntities), + _errorID(XML_SUCCESS), + _whitespaceMode(whitespaceMode), + _errorStr(), + _errorLineNum(0), + _charBuffer(0), + _parseCurLineNum(0), + _parsingDepth(0), + _unlinked(), + _elementPool(), + _attributePool(), + _textPool(), + _commentPool() { // avoid VC++ C4355 warning about 'this' in initializer list (C4355 is off by default in VS2012+) _document = this; } - XMLDocument::~XMLDocument() { Clear(); } + XMLDocument::~XMLDocument() + { + Clear(); + } void XMLDocument::MarkInUse(XMLNode* node) @@ -1832,10 +1951,8 @@ namespace tinyxml2 TIXMLASSERT(node); TIXMLASSERT(node->_parent == 0); - for (int i = 0; i < _unlinked.Size(); ++i) - { - if (node == _unlinked[i]) - { + for (int i = 0; i < _unlinked.Size(); ++i) { + if (node == _unlinked[i]) { _unlinked.SwapRemove(i); break; } @@ -1845,23 +1962,46 @@ namespace tinyxml2 void XMLDocument::Clear() { DeleteChildren(); - while (_unlinked.Size()) { DeleteNode(_unlinked[0]); } // Will remove from _unlinked as part of delete. + while (_unlinked.Size()) { + DeleteNode(_unlinked[0]); // Will remove from _unlinked as part of delete. + } + +#ifdef TINYXML2_DEBUG + const bool hadError = Error(); +#endif ClearError(); delete[] _charBuffer; - _charBuffer = nullptr; + _charBuffer = 0; _parsingDepth = 0; + +#if 0 + _textPool.Trace("text"); + _elementPool.Trace("element"); + _commentPool.Trace("comment"); + _attributePool.Trace("attribute"); +#endif + +#ifdef TINYXML2_DEBUG + if (!hadError) { + TIXMLASSERT(_elementPool.CurrentAllocs() == _elementPool.Untracked()); + TIXMLASSERT(_attributePool.CurrentAllocs() == _attributePool.Untracked()); + TIXMLASSERT(_textPool.CurrentAllocs() == _textPool.Untracked()); + TIXMLASSERT(_commentPool.CurrentAllocs() == _commentPool.Untracked()); + } +#endif } void XMLDocument::DeepCopy(XMLDocument* target) const { TIXMLASSERT(target); - if (target == this) { return; } // technically success - a no-op. + if (target == this) { + return; // technically success - a no-op. + } target->Clear(); - for (const XMLNode* node = this->FirstChild(); node; node = node->NextSibling()) - { + for (const XMLNode* node = this->FirstChild(); node; node = node->NextSibling()) { target->InsertEndChild(node->DeepClone(target)); } } @@ -1893,7 +2033,7 @@ namespace tinyxml2 XMLDeclaration* XMLDocument::NewDeclaration(const char* str) { XMLDeclaration* dec = CreateUnlinkedNode<XMLDeclaration>(_commentPool); - dec->SetValue(str ? str : R"(xml version="1.0" encoding="UTF-8")"); + dec->SetValue(str ? str : "xml version=\"1.0\" encoding=\"UTF-8\""); return dec; } @@ -1909,23 +2049,23 @@ namespace tinyxml2 { TIXMLASSERT(filepath); TIXMLASSERT(mode); -#if defined(_MSC_VER) && (_MSC_VER >= 1400 ) - FILE* fp = nullptr; - const errno_t err = fopen_s(&fp, filepath, mode); - if (err) { return nullptr; } +#if defined(_MSC_VER) && (_MSC_VER >= 1400 ) && (!defined WINCE) + FILE* fp = 0; + errno_t err = fopen_s(&fp, filepath, mode); + if (err) { return 0; } #else FILE* fp = fopen(filepath, mode); #endif return fp; } - void XMLDocument::DeleteNode(XMLNode* node) - { + void XMLDocument::DeleteNode(XMLNode* node) { TIXMLASSERT(node); TIXMLASSERT(node->_document == this); - if (node->_parent) { node->_parent->DeleteChild(node); } - else - { + if (node->_parent) { + node->_parent->DeleteChild(node); + } + else { // Isn't in the tree. // Use the parent delete. // Also, we need to mark it tracked: we 'know' @@ -1939,8 +2079,7 @@ namespace tinyxml2 XMLError XMLDocument::LoadFile(const char* filename) { - if (!filename) - { + if (!filename) { TIXMLASSERT(false); SetError(XML_ERROR_FILE_COULD_NOT_BE_OPENED, 0, "filename=<null>"); return _errorID; @@ -1948,8 +2087,7 @@ namespace tinyxml2 Clear(); FILE* fp = callfopen(filename, "rb"); - if (!fp) - { + if (!fp) { SetError(XML_ERROR_FILE_NOT_FOUND, 0, "filename=%s", filename); return _errorID; } @@ -1964,16 +2102,21 @@ namespace tinyxml2 // -Wtype-limits warning. This piece makes the compiler select code with a check when a check // is useful and code with no check when a check is redundant depending on how size_t and unsigned long // types sizes relate to each other. - template <bool = sizeof(unsigned long) >= sizeof(size_t)> - struct LongFitsIntoSizeTMinusOne - { - static bool Fits(const unsigned long value) { return value < size_t(-1); } + template + <bool = (sizeof(unsigned long) >= sizeof(size_t))> + struct LongFitsIntoSizeTMinusOne { + static bool Fits(unsigned long value) + { + return value < (size_t)-1; + } }; template <> - struct LongFitsIntoSizeTMinusOne<false> - { - static bool Fits(unsigned long) { return true; } + struct LongFitsIntoSizeTMinusOne<false> { + static bool Fits(unsigned long) + { + return true; + } }; XMLError XMLDocument::LoadFile(FILE* fp) @@ -1981,42 +2124,37 @@ namespace tinyxml2 Clear(); fseek(fp, 0, SEEK_SET); - if (fgetc(fp) == EOF && ferror(fp) != 0) - { - SetError(XML_ERROR_FILE_READ_ERROR, 0, nullptr); + if (fgetc(fp) == EOF && ferror(fp) != 0) { + SetError(XML_ERROR_FILE_READ_ERROR, 0, 0); return _errorID; } fseek(fp, 0, SEEK_END); const long filelength = ftell(fp); fseek(fp, 0, SEEK_SET); - if (filelength == -1L) - { - SetError(XML_ERROR_FILE_READ_ERROR, 0, nullptr); + if (filelength == -1L) { + SetError(XML_ERROR_FILE_READ_ERROR, 0, 0); return _errorID; } TIXMLASSERT(filelength >= 0); - if (!LongFitsIntoSizeTMinusOne<>::Fits(filelength)) - { + if (!LongFitsIntoSizeTMinusOne<>::Fits(filelength)) { // Cannot handle files which won't fit in buffer together with null terminator - SetError(XML_ERROR_FILE_READ_ERROR, 0, nullptr); + SetError(XML_ERROR_FILE_READ_ERROR, 0, 0); return _errorID; } - if (filelength == 0) - { - SetError(XML_ERROR_EMPTY_DOCUMENT, 0, nullptr); + if (filelength == 0) { + SetError(XML_ERROR_EMPTY_DOCUMENT, 0, 0); return _errorID; } const size_t size = filelength; TIXMLASSERT(_charBuffer == 0); _charBuffer = new char[size + 1]; - const size_t read = fread(_charBuffer, 1, size, fp); - if (read != size) - { - SetError(XML_ERROR_FILE_READ_ERROR, 0, nullptr); + size_t read = fread(_charBuffer, 1, size, fp); + if (read != size) { + SetError(XML_ERROR_FILE_READ_ERROR, 0, 0); return _errorID; } @@ -2027,18 +2165,16 @@ namespace tinyxml2 } - XMLError XMLDocument::SaveFile(const char* filename, const bool compact) + XMLError XMLDocument::SaveFile(const char* filename, bool compact) { - if (!filename) - { + if (!filename) { TIXMLASSERT(false); SetError(XML_ERROR_FILE_COULD_NOT_BE_OPENED, 0, "filename=<null>"); return _errorID; } FILE* fp = callfopen(filename, "w"); - if (!fp) - { + if (!fp) { SetError(XML_ERROR_FILE_COULD_NOT_BE_OPENED, 0, "filename=%s", filename); return _errorID; } @@ -2048,7 +2184,7 @@ namespace tinyxml2 } - XMLError XMLDocument::SaveFile(FILE* fp, const bool compact) + XMLError XMLDocument::SaveFile(FILE* fp, bool compact) { // Clear any error from the last save, otherwise it will get reported // for *this* call. @@ -2059,24 +2195,24 @@ namespace tinyxml2 } - XMLError XMLDocument::Parse(const char* xml, size_t len) + XMLError XMLDocument::Parse(const char* p, size_t len) { Clear(); - if (len == 0 || !xml || !*xml) - { - SetError(XML_ERROR_EMPTY_DOCUMENT, 0, nullptr); + if (len == 0 || !p || !*p) { + SetError(XML_ERROR_EMPTY_DOCUMENT, 0, 0); return _errorID; } - if (len == size_t(-1)) { len = strlen(xml); } + if (len == (size_t)(-1)) { + len = strlen(p); + } TIXMLASSERT(_charBuffer == 0); _charBuffer = new char[len + 1]; - memcpy(_charBuffer, xml, len); + memcpy(_charBuffer, p, len); _charBuffer[len] = 0; Parse(); - if (Error()) - { + if (Error()) { // clean up now essentially dangling memory. // and the parse fail can put objects in the // pools that are dead and inaccessible. @@ -2092,30 +2228,30 @@ namespace tinyxml2 void XMLDocument::Print(XMLPrinter* streamer) const { - if (streamer) { Accept(streamer); } - else - { + if (streamer) { + Accept(streamer); + } + else { XMLPrinter stdoutStreamer(stdout); Accept(&stdoutStreamer); } } - void XMLDocument::SetError(const XMLError error, const int lineNum, const char* format, ...) + void XMLDocument::SetError(XMLError error, int lineNum, const char* format, ...) { TIXMLASSERT(error >= 0 && error < XML_ERROR_COUNT); _errorID = error; _errorLineNum = lineNum; _errorStr.Reset(); - const size_t BUFFER_SIZE = 1000; + size_t BUFFER_SIZE = 1000; char* buffer = new char[BUFFER_SIZE]; TIXMLASSERT(sizeof(error) <= sizeof(int)); TIXML_SNPRINTF(buffer, BUFFER_SIZE, "Error=%s ErrorID=%d (0x%x) Line number=%d", ErrorIDToName(error), int(error), int(error), lineNum); - if (format) - { + if (format) { size_t len = strlen(buffer); TIXML_SNPRINTF(buffer + len, BUFFER_SIZE - len, ": "); len = strlen(buffer); @@ -2130,8 +2266,7 @@ namespace tinyxml2 } - /*static*/ - const char* XMLDocument::ErrorIDToName(const XMLError errorID) + /*static*/ const char* XMLDocument::ErrorIDToName(XMLError errorID) { TIXMLASSERT(errorID >= 0 && errorID < XML_ERROR_COUNT); const char* errorName = _errorNames[errorID]; @@ -2139,11 +2274,21 @@ namespace tinyxml2 return errorName; } - const char* XMLDocument::ErrorStr() const { return _errorStr.Empty() ? "" : _errorStr.GetStr(); } + const char* XMLDocument::ErrorStr() const + { + return _errorStr.Empty() ? "" : _errorStr.GetStr(); + } + - void XMLDocument::PrintError() const { printf("%s\n", ErrorStr()); } + void XMLDocument::PrintError() const + { + printf("%s\n", ErrorStr()); + } - const char* XMLDocument::ErrorName() const { return ErrorIDToName(_errorID); } + const char* XMLDocument::ErrorName() const + { + return ErrorIDToName(_errorID); + } void XMLDocument::Parse() { @@ -2154,19 +2299,17 @@ namespace tinyxml2 char* p = _charBuffer; p = XMLUtil::SkipWhiteSpace(p, &_parseCurLineNum); p = const_cast<char*>(XMLUtil::ReadBOM(p, &_writeBOM)); - if (!*p) - { - SetError(XML_ERROR_EMPTY_DOCUMENT, 0, nullptr); + if (!*p) { + SetError(XML_ERROR_EMPTY_DOCUMENT, 0, 0); return; } - ParseDeep(p, nullptr, &_parseCurLineNum); + ParseDeep(p, 0, &_parseCurLineNum); } void XMLDocument::PushDepth() { _parsingDepth++; - if (_parsingDepth == TINYXML2_MAX_ELEMENT_DEPTH) - { + if (_parsingDepth == TINYXML2_MAX_ELEMENT_DEPTH) { SetError(XML_ELEMENT_DEPTH_EXCEEDED, _parseCurLineNum, "Element nesting is too deep."); } } @@ -2177,36 +2320,43 @@ namespace tinyxml2 --_parsingDepth; } - XMLPrinter::XMLPrinter(FILE* file, const bool compact, const int depth) - : _fp(file), _depth(depth), _compactMode(compact) + XMLPrinter::XMLPrinter(FILE* file, bool compact, int depth) : + _elementJustOpened(false), + _stack(), + _firstElement(true), + _fp(file), + _depth(depth), + _textDepth(-1), + _processEntities(true), + _compactMode(compact), + _buffer() { - for (int i = 0; i < ENTITY_RANGE; ++i) - { + for (int i = 0; i < ENTITY_RANGE; ++i) { _entityFlag[i] = false; _restrictedEntityFlag[i] = false; } - for (auto entitie : entities) - { - const char entityValue = entitie.value; - const unsigned char flagIndex = static_cast<unsigned char>(entityValue); + for (int i = 0; i < NUM_ENTITIES; ++i) { + const char entityValue = entities[i].value; + const unsigned char flagIndex = (unsigned char)entityValue; TIXMLASSERT(flagIndex < ENTITY_RANGE); _entityFlag[flagIndex] = true; } - _restrictedEntityFlag[static_cast<unsigned char>('&')] = true; - _restrictedEntityFlag[static_cast<unsigned char>('<')] = true; - _restrictedEntityFlag[static_cast<unsigned char>('>')] = true; // not required, but consistency is nice + _restrictedEntityFlag[(unsigned char)'&'] = true; + _restrictedEntityFlag[(unsigned char)'<'] = true; + _restrictedEntityFlag[(unsigned char)'>'] = true; // not required, but consistency is nice _buffer.Push(0); } void XMLPrinter::Print(const char* format, ...) { - va_list va; + va_list va; va_start(va, format); - if (_fp) { vfprintf(_fp, format, va); } - else - { + if (_fp) { + vfprintf(_fp, format, va); + } + else { const int len = TIXML_VSCPRINTF(format, va); // Close out and re-start the va-args va_end(va); @@ -2220,23 +2370,25 @@ namespace tinyxml2 } - void XMLPrinter::Write(const char* data, const size_t size) + void XMLPrinter::Write(const char* data, size_t size) { - if (_fp) { fwrite(data, sizeof(char), size, _fp); } - else - { - char* p = _buffer.PushArr(int(size)) - 1; // back up over the null terminator. + if (_fp) { + fwrite(data, sizeof(char), size, _fp); + } + else { + char* p = _buffer.PushArr(static_cast<int>(size)) - 1; // back up over the null terminator. memcpy(p, data, size); p[size] = 0; } } - void XMLPrinter::Putc(const char ch) + void XMLPrinter::Putc(char ch) { - if (_fp) { fputc(ch, _fp); } - else - { + if (_fp) { + fputc(ch, _fp); + } + else { char* p = _buffer.PushArr(sizeof(char)) - 1; // back up over the null terminator. p[0] = ch; p[1] = 0; @@ -2244,52 +2396,46 @@ namespace tinyxml2 } - void XMLPrinter::PrintSpace(const int depth) + void XMLPrinter::PrintSpace(int depth) { - for (int i = 0; i < depth; ++i) { Write(" "); } + for (int i = 0; i < depth; ++i) { + Write(" "); + } } - void XMLPrinter::PrintString(const char* p, const bool restricted) + void XMLPrinter::PrintString(const char* p, bool restricted) { // Look for runs of bytes between entities to print. const char* q = p; - if (_processEntities) - { + if (_processEntities) { const bool* flag = restricted ? _restrictedEntityFlag : _entityFlag; - while (*q) - { + while (*q) { TIXMLASSERT(p <= q); // Remember, char is sometimes signed. (How many times has that bitten me?) - if (*q > 0 && *q < ENTITY_RANGE) - { + if (*q > 0 && *q < ENTITY_RANGE) { // Check for entities. If one is found, flush // the stream up until the entity, write the // entity, and keep looking. - if (flag[static_cast<unsigned char>(*q)]) - { - while (p < q) - { + if (flag[(unsigned char)(*q)]) { + while (p < q) { const size_t delta = q - p; - const int toPrint = (INT_MAX < delta) ? INT_MAX : int(delta); + const int toPrint = (INT_MAX < delta) ? INT_MAX : (int)delta; Write(p, toPrint); p += toPrint; } bool entityPatternPrinted = false; - for (auto entitie : entities) - { - if (entitie.value == *q) - { + for (int i = 0; i < NUM_ENTITIES; ++i) { + if (entities[i].value == *q) { Putc('&'); - Write(entitie.pattern, entitie.length); + Write(entities[i].pattern, entities[i].length); Putc(';'); entityPatternPrinted = true; break; } } - if (!entityPatternPrinted) - { + if (!entityPatternPrinted) { // TIXMLASSERT( entityPatternPrinted ) causes gcc -Wunused-but-set-variable in release TIXMLASSERT(false); } @@ -2301,35 +2447,41 @@ namespace tinyxml2 } // Flush the remaining string. This will be the entire // string if an entity wasn't found. - if (p < q) - { + if (p < q) { const size_t delta = q - p; - const int toPrint = (INT_MAX < delta) ? INT_MAX : int(delta); + const int toPrint = (INT_MAX < delta) ? INT_MAX : (int)delta; Write(p, toPrint); } } - else { Write(p); } + else { + Write(p); + } } - void XMLPrinter::PushHeader(const bool writeBOM, const bool writeDeclaration) + void XMLPrinter::PushHeader(bool writeBOM, bool writeDec) { - if (writeBOM) - { + if (writeBOM) { static const unsigned char bom[] = { TIXML_UTF_LEAD_0, TIXML_UTF_LEAD_1, TIXML_UTF_LEAD_2, 0 }; Write(reinterpret_cast<const char*>(bom)); } - if (writeDeclaration) { PushDeclaration("xml version=\"1.0\""); } + if (writeDec) { + PushDeclaration("xml version=\"1.0\""); + } } - void XMLPrinter::OpenElement(const char* name, const bool compactMode) + void XMLPrinter::OpenElement(const char* name, bool compactMode) { SealElementIfJustOpened(); _stack.Push(name); - if (_textDepth < 0 && !_firstElement && !compactMode) { Putc('\n'); } - if (!compactMode) { PrintSpace(_depth); } + if (_textDepth < 0 && !_firstElement && !compactMode) { + Putc('\n'); + } + if (!compactMode) { + PrintSpace(_depth); + } Write("<"); Write(name); @@ -2351,56 +2503,56 @@ namespace tinyxml2 } - void XMLPrinter::PushAttribute(const char* name, const int value) + void XMLPrinter::PushAttribute(const char* name, int v) { char buf[BUF_SIZE]; - XMLUtil::ToStr(value, buf, BUF_SIZE); + XMLUtil::ToStr(v, buf, BUF_SIZE); PushAttribute(name, buf); } - void XMLPrinter::PushAttribute(const char* name, const unsigned value) + void XMLPrinter::PushAttribute(const char* name, unsigned v) { char buf[BUF_SIZE]; - XMLUtil::ToStr(value, buf, BUF_SIZE); + XMLUtil::ToStr(v, buf, BUF_SIZE); PushAttribute(name, buf); } - void XMLPrinter::PushAttribute(const char* name, const int64_t value) + void XMLPrinter::PushAttribute(const char* name, int64_t v) { char buf[BUF_SIZE]; - XMLUtil::ToStr(value, buf, BUF_SIZE); + XMLUtil::ToStr(v, buf, BUF_SIZE); PushAttribute(name, buf); } - void XMLPrinter::PushAttribute(const char* name, const bool value) + void XMLPrinter::PushAttribute(const char* name, bool v) { char buf[BUF_SIZE]; - XMLUtil::ToStr(value, buf, BUF_SIZE); + XMLUtil::ToStr(v, buf, BUF_SIZE); PushAttribute(name, buf); } - void XMLPrinter::PushAttribute(const char* name, const double value) + void XMLPrinter::PushAttribute(const char* name, double v) { char buf[BUF_SIZE]; - XMLUtil::ToStr(value, buf, BUF_SIZE); + XMLUtil::ToStr(v, buf, BUF_SIZE); PushAttribute(name, buf); } - void XMLPrinter::CloseElement(const bool compactMode) + void XMLPrinter::CloseElement(bool compactMode) { --_depth; const char* name = _stack.Pop(); - if (_elementJustOpened) { Write("/>"); } - else - { - if (_textDepth < 0 && !compactMode) - { + if (_elementJustOpened) { + Write("/>"); + } + else { + if (_textDepth < 0 && !compactMode) { Putc('\n'); PrintSpace(_depth); } @@ -2409,42 +2561,49 @@ namespace tinyxml2 Write(">"); } - if (_textDepth == _depth) { _textDepth = -1; } - if (_depth == 0 && !compactMode) { Putc('\n'); } + if (_textDepth == _depth) { + _textDepth = -1; + } + if (_depth == 0 && !compactMode) { + Putc('\n'); + } _elementJustOpened = false; } void XMLPrinter::SealElementIfJustOpened() { - if (!_elementJustOpened) { return; } + if (!_elementJustOpened) { + return; + } _elementJustOpened = false; Putc('>'); } - void XMLPrinter::PushText(const char* text, const bool cdata) + void XMLPrinter::PushText(const char* text, bool cdata) { _textDepth = _depth - 1; SealElementIfJustOpened(); - if (cdata) - { + if (cdata) { Write("<![CDATA["); Write(text); Write("]]>"); } - else { PrintString(text, true); } + else { + PrintString(text, true); + } } - void XMLPrinter::PushText(const int64_t value) + void XMLPrinter::PushText(int64_t value) { char buf[BUF_SIZE]; XMLUtil::ToStr(value, buf, BUF_SIZE); PushText(buf, false); } - void XMLPrinter::PushText(const int value) + void XMLPrinter::PushText(int value) { char buf[BUF_SIZE]; XMLUtil::ToStr(value, buf, BUF_SIZE); @@ -2452,7 +2611,7 @@ namespace tinyxml2 } - void XMLPrinter::PushText(const unsigned value) + void XMLPrinter::PushText(unsigned value) { char buf[BUF_SIZE]; XMLUtil::ToStr(value, buf, BUF_SIZE); @@ -2460,7 +2619,7 @@ namespace tinyxml2 } - void XMLPrinter::PushText(const bool value) + void XMLPrinter::PushText(bool value) { char buf[BUF_SIZE]; XMLUtil::ToStr(value, buf, BUF_SIZE); @@ -2468,7 +2627,7 @@ namespace tinyxml2 } - void XMLPrinter::PushText(const float value) + void XMLPrinter::PushText(float value) { char buf[BUF_SIZE]; XMLUtil::ToStr(value, buf, BUF_SIZE); @@ -2476,7 +2635,7 @@ namespace tinyxml2 } - void XMLPrinter::PushText(const double value) + void XMLPrinter::PushText(double value) { char buf[BUF_SIZE]; XMLUtil::ToStr(value, buf, BUF_SIZE); @@ -2487,8 +2646,7 @@ namespace tinyxml2 void XMLPrinter::PushComment(const char* comment) { SealElementIfJustOpened(); - if (_textDepth < 0 && !_firstElement && !_compactMode) - { + if (_textDepth < 0 && !_firstElement && !_compactMode) { Putc('\n'); PrintSpace(_depth); } @@ -2503,8 +2661,7 @@ namespace tinyxml2 void XMLPrinter::PushDeclaration(const char* value) { SealElementIfJustOpened(); - if (_textDepth < 0 && !_firstElement && !_compactMode) - { + if (_textDepth < 0 && !_firstElement && !_compactMode) { Putc('\n'); PrintSpace(_depth); } @@ -2519,8 +2676,7 @@ namespace tinyxml2 void XMLPrinter::PushUnknown(const char* value) { SealElementIfJustOpened(); - if (_textDepth < 0 && !_firstElement && !_compactMode) - { + if (_textDepth < 0 && !_firstElement && !_compactMode) { Putc('\n'); PrintSpace(_depth); } @@ -2535,19 +2691,22 @@ namespace tinyxml2 bool XMLPrinter::VisitEnter(const XMLDocument& doc) { _processEntities = doc.ProcessEntities(); - if (doc.HasBOM()) { PushHeader(true, false); } + if (doc.HasBOM()) { + PushHeader(true, false); + } return true; } bool XMLPrinter::VisitEnter(const XMLElement& element, const XMLAttribute* attribute) { - const XMLElement* parentElem = nullptr; - if (element.Parent()) { parentElem = element.Parent()->ToElement(); } + const XMLElement* parentElem = 0; + if (element.Parent()) { + parentElem = element.Parent()->ToElement(); + } const bool compactMode = parentElem ? CompactMode(*parentElem) : _compactMode; OpenElement(element.Name(), compactMode); - while (attribute) - { + while (attribute) { PushAttribute(attribute->Name(), attribute->Value()); attribute = attribute->Next(); } @@ -2587,4 +2746,5 @@ namespace tinyxml2 PushUnknown(unknown.Value()); return true; } + } // namespace tinyxml2 diff --git a/plugins/processing/riemannian/src/3rd-party/tinyxml2.h b/plugins/processing/riemannian/src/3rd-party/tinyxml2.h index 775bbc3fded6926eb80e34b177ca34275d27fa34..2274be9dcf7804ea35b8f96e20e53b8b413026d5 100644 --- a/plugins/processing/riemannian/src/3rd-party/tinyxml2.h +++ b/plugins/processing/riemannian/src/3rd-party/tinyxml2.h @@ -24,17 +24,40 @@ distribution. #ifndef TINYXML2_INCLUDED #define TINYXML2_INCLUDED -#include <cctype> -#include <climits> -#include <cstdio> -#include <cstdlib> -#include <cstring> -#include <cstdint> +#if defined(ANDROID_NDK) || defined(__BORLANDC__) || defined(__QNXNTO__) +# include <ctype.h> +# include <limits.h> +# include <stdio.h> +# include <stdlib.h> +# include <string.h> +# if defined(__PS3__) +# include <stddef.h> +# endif +#else +# include <cctype> +# include <climits> +# include <cstdio> +# include <cstdlib> +# include <cstring> +#endif +#include <stdint.h> /* TODO: intern strings instead of allocation. */ +/* + gcc: + g++ -Wall -DTINYXML2_DEBUG tinyxml2.cpp xmltest.cpp -o gccxmltest.exe + + Formatting, Artistic Style: + AStyle.exe --style=1tbs --indent-switches --break-closing-brackets --indent-preprocessor tinyxml2.cpp tinyxml2.h +*/ +#if defined( _DEBUG ) || defined (__DEBUG__) +# ifndef TINYXML2_DEBUG +# define TINYXML2_DEBUG +# endif +#endif #ifdef _MSC_VER # pragma warning(push) @@ -56,7 +79,20 @@ distribution. #endif +#if defined(TINYXML2_DEBUG) +# if defined(_MSC_VER) +# // "(void)0," is for suppressing C4127 warning in "assert(false)", "assert(true)" and the like +# define TIXMLASSERT( x ) if ( !((void)0,(x))) { __debugbreak(); } +# elif defined (ANDROID_NDK) +# include <android/log.h> +# define TIXMLASSERT( x ) if ( !(x)) { __android_log_assert( "assert", "grinliz", "ASSERT in '%s' at %d.", __FILE__, __LINE__ ); } +# else +# include <assert.h> +# define TIXMLASSERT assert +# endif +#else # define TIXMLASSERT( x ) {} +#endif /* Versioning, past 1.0.14: @@ -99,8 +135,7 @@ namespace tinyxml2 class TINYXML2_LIB StrPair { public: - enum - { + enum { NEEDS_ENTITY_PROCESSING = 0x01, NEEDS_NEWLINE_NORMALIZATION = 0x02, NEEDS_WHITESPACE_COLLAPSING = 0x04, @@ -113,11 +148,10 @@ namespace tinyxml2 COMMENT = NEEDS_NEWLINE_NORMALIZATION }; - StrPair() = default; - ~StrPair() { Reset(); } + StrPair() : _flags(0), _start(0), _end(0) {} + ~StrPair(); - void Set(char* start, char* end, const int flags) - { + void Set(char* start, char* end, int flags) { TIXMLASSERT(start); TIXMLASSERT(end); Reset(); @@ -130,8 +164,7 @@ namespace tinyxml2 bool Empty() const { return _start == _end; } - void SetInternedStr(const char* str) - { + void SetInternedStr(const char* str) { Reset(); _start = const_cast<char*>(str); } @@ -144,21 +177,20 @@ namespace tinyxml2 void TransferTo(StrPair* other); void Reset(); - StrPair(const StrPair& other) = delete; // not supported - void operator=(const StrPair& other) = delete; // not supported, use TransferTo() - private: void CollapseWhitespace(); - enum - { + enum { NEEDS_FLUSH = 0x100, NEEDS_DELETE = 0x200 }; - int _flags = 0; - char* _start = nullptr; - char* _end = nullptr; + int _flags; + char* _start; + char* _end; + + StrPair(const StrPair& other); // not supported + void operator=(const StrPair& other); // not supported, use TransferTo() }; @@ -171,21 +203,20 @@ namespace tinyxml2 class DynArray { public: - DynArray() : _mem(_pool) { } + DynArray() : _mem(_pool), _allocated(INITIAL_SIZE), _size(0) { } + ~DynArray() { if (_mem != _pool) { delete[] _mem; } } void Clear() { _size = 0; } - void Push(T t) - { + void Push(T t) { TIXMLASSERT(_size < INT_MAX); EnsureCapacity(_size + 1); _mem[_size] = t; ++_size; } - T* PushArr(const int count) - { + T* PushArr(int count) { TIXMLASSERT(count >= 0); TIXMLASSERT(_size <= INT_MAX - count); EnsureCapacity(_size + count); @@ -194,95 +225,83 @@ namespace tinyxml2 return ret; } - T Pop() - { + T Pop() { TIXMLASSERT(_size > 0); --_size; return _mem[_size]; } - void PopArr(const int count) - { + void PopArr(int count) { TIXMLASSERT(_size >= count); _size -= count; } bool Empty() const { return _size == 0; } - T& operator[](int i) - { + T& operator[](int i) { TIXMLASSERT(i >= 0 && i < _size); return _mem[i]; } - const T& operator[](int i) const - { + const T& operator[](int i) const { TIXMLASSERT(i >= 0 && i < _size); return _mem[i]; } - const T& PeekTop() const - { + const T& PeekTop() const { TIXMLASSERT(_size > 0); return _mem[_size - 1]; } - int Size() const - { + int Size() const { TIXMLASSERT(_size >= 0); return _size; } - int Capacity() const - { + int Capacity() const { TIXMLASSERT(_allocated >= INITIAL_SIZE); return _allocated; } - void SwapRemove(int i) - { + void SwapRemove(int i) { TIXMLASSERT(i >= 0 && i < _size); TIXMLASSERT(_size > 0); _mem[i] = _mem[_size - 1]; --_size; } - const T* Mem() const - { + const T* Mem() const { TIXMLASSERT(_mem); return _mem; } - T* Mem() - { + T* Mem() { TIXMLASSERT(_mem); return _mem; } - DynArray(const DynArray&) = delete; // not supported - void operator=(const DynArray&) = delete; // not supported - private: - void EnsureCapacity(const int cap) - { + DynArray(const DynArray&); // not supported + void operator=(const DynArray&); // not supported + + void EnsureCapacity(int cap) { TIXMLASSERT(cap > 0); - if (cap > _allocated) - { + if (cap > _allocated) { TIXMLASSERT(cap <= INT_MAX / 2); - const int newAllocated = cap * 2; + int newAllocated = cap * 2; T* newMem = new T[newAllocated]; TIXMLASSERT(newAllocated >= _size); - memcpy(newMem, _mem, sizeof(T) * _size); // warning: not using constructors, only works for PODs + memcpy(newMem, _mem, sizeof(T)*_size); // warning: not using constructors, only works for PODs if (_mem != _pool) { delete[] _mem; } _mem = newMem; _allocated = newAllocated; } } - T* _mem; - T _pool[INITIAL_SIZE]; - int _allocated = INITIAL_SIZE; // objects allocated - int _size = 0; // number objects in use + T* _mem; + T _pool[INITIAL_SIZE]; + int _allocated; // objects allocated + int _size; // number objects in use }; @@ -293,8 +312,8 @@ namespace tinyxml2 class MemPool { public: - MemPool() = default; - virtual ~MemPool() = default; + MemPool() {} + virtual ~MemPool() {} virtual int ItemSize() const = 0; virtual void* Alloc() = 0; @@ -306,18 +325,16 @@ namespace tinyxml2 /* Template child class to create pools of the correct type. */ - template <int ITEM_SIZE> + template< int ITEM_SIZE > class MemPoolT : public MemPool { public: - MemPoolT() : _blockPtrs(), _root(nullptr) {} - ~MemPoolT() { Clear(); } + MemPoolT() : _blockPtrs(), _root(0), _currentAllocs(0), _nAllocs(0), _maxAllocs(0), _nUntracked(0) {} + ~MemPoolT() { MemPoolT< ITEM_SIZE >::Clear(); } - void Clear() - { + void Clear() { // Delete the blocks. - while (!_blockPtrs.Empty()) - { + while (!_blockPtrs.Empty()) { Block* lastBlock = _blockPtrs.Pop(); delete lastBlock; } @@ -328,13 +345,11 @@ namespace tinyxml2 _nUntracked = 0; } - int ItemSize() const override { return ITEM_SIZE; } + virtual int ItemSize() const { return ITEM_SIZE; } int CurrentAllocs() const { return _currentAllocs; } - void* Alloc() override - { - if (!_root) - { + virtual void* Alloc() { + if (!_root) { // Need a new block. Block* block = new Block(); _blockPtrs.Push(block); @@ -355,23 +370,23 @@ namespace tinyxml2 return result; } - void Free(void* mem) override - { + virtual void Free(void* mem) { if (!mem) { return; } --_currentAllocs; Item* item = static_cast<Item*>(mem); +#ifdef TINYXML2_DEBUG + memset(item, 0xfe, sizeof(*item)); +#endif item->next = _root; _root = item; } - - void Trace(const char* name) - { + void Trace(const char* name) { printf("Mempool %s watermark=%d [%dk] current=%d size=%d nAlloc=%d blocks=%d\n", - name, _maxAllocs, _maxAllocs * ITEM_SIZE / 1024, _currentAllocs, - ITEM_SIZE, _nAllocs, _blockPtrs.Size()); + name, _maxAllocs, _maxAllocs * ITEM_SIZE / 1024, _currentAllocs, + ITEM_SIZE, _nAllocs, _blockPtrs.Size()); } - void SetTracked() override { --_nUntracked; } + void SetTracked() { --_nUntracked; } int Untracked() const { return _nUntracked; } @@ -388,28 +403,24 @@ namespace tinyxml2 // in private part if ITEMS_PER_BLOCK is private enum { ITEMS_PER_BLOCK = (4 * 1024) / ITEM_SIZE }; - MemPoolT(const MemPoolT&) = delete; // not supported - void operator=(const MemPoolT&) = delete; // not supported - private: - union Item - { - Item* next; - char itemData[ITEM_SIZE]; - }; + MemPoolT(const MemPoolT&); // not supported + void operator=(const MemPoolT&); // not supported - struct Block - { - Item items[ITEMS_PER_BLOCK]; + union Item { + Item* next; + char itemData[ITEM_SIZE]; }; - DynArray<Block*, 10> _blockPtrs; - Item* _root = nullptr; + struct Block { Item items[ITEMS_PER_BLOCK]; }; - int _currentAllocs = 0; - int _nAllocs = 0; - int _maxAllocs = 0; - int _nUntracked = 0; + DynArray< Block*, 10 > _blockPtrs; + Item* _root; + + int _currentAllocs; + int _nAllocs; + int _maxAllocs; + int _nUntracked; }; @@ -436,7 +447,7 @@ namespace tinyxml2 class TINYXML2_LIB XMLVisitor { public: - virtual ~XMLVisitor() = default; + virtual ~XMLVisitor() {} /// Visit a document. virtual bool VisitEnter(const XMLDocument& /*doc*/) { return true; } @@ -459,8 +470,7 @@ namespace tinyxml2 }; // WARNING: must match XMLDocument::_errorNames[] - enum XMLError - { + enum XMLError { XML_SUCCESS = 0, XML_NO_ATTRIBUTE, XML_WRONG_ATTRIBUTE_TYPE, @@ -491,12 +501,10 @@ namespace tinyxml2 class TINYXML2_LIB XMLUtil { public: - static const char* SkipWhiteSpace(const char* p, int* curLineNumPtr) - { + static const char* SkipWhiteSpace(const char* p, int* curLineNumPtr) { TIXMLASSERT(p); - while (IsWhiteSpace(*p)) - { + while (IsWhiteSpace(*p)) { if (curLineNumPtr && *p == '\n') { ++(*curLineNumPtr); } ++p; } @@ -508,21 +516,25 @@ namespace tinyxml2 // Anything in the high order range of UTF-8 is assumed to not be whitespace. This isn't // correct, but simple, and usually works. - static bool IsWhiteSpace(const char p) { return !IsUTF8Continuation(p) && isspace(static_cast<unsigned char>(p)); } - - static bool IsNameStartChar(const unsigned char ch) - { - if (ch >= 128) { return true; } - // This is a heuristic guess in attempt to not implement Unicode-aware isalpha() + static bool IsWhiteSpace(char p) { return !IsUTF8Continuation(p) && isspace(static_cast<unsigned char>(p)); } + inline static bool IsNameStartChar(unsigned char ch) { + if (ch >= 128) { + // This is a heuristic guess in attempt to not implement Unicode-aware isalpha() + return true; + } if (isalpha(ch)) { return true; } return ch == ':' || ch == '_'; } - static bool IsNameChar(const unsigned char ch) { return IsNameStartChar(ch) || isdigit(ch) || ch == '.' || ch == '-'; } + inline static bool IsNameChar(unsigned char ch) { + return IsNameStartChar(ch) + || isdigit(ch) + || ch == '.' + || ch == '-'; + } - static bool StringEqual(const char* p, const char* q, const int nChar = INT_MAX) - { + inline static bool StringEqual(const char* p, const char* q, int nChar = INT_MAX) { if (p == q) { return true; } TIXMLASSERT(p); TIXMLASSERT(q); @@ -530,7 +542,7 @@ namespace tinyxml2 return strncmp(p, q, nChar) == 0; } - static bool IsUTF8Continuation(const char p) { return (p & 0x80) != 0; } + inline static bool IsUTF8Continuation(char p) { return (p & 0x80) != 0; } static const char* ReadBOM(const char* p, bool* hasBOM); // p is the starting location, @@ -547,10 +559,10 @@ namespace tinyxml2 static void ToStr(int64_t v, char* buffer, int bufferSize); // converts strings to primitive types - static bool ToInt(const char* str, int* value); + static bool ToInt(const char* str, int* value); static bool ToUnsigned(const char* str, unsigned* value); - static bool ToBool(const char* str, bool* value); - static bool ToFloat(const char* str, float* value); + static bool ToBool(const char* str, bool* value); + static bool ToFloat(const char* str, float* value); static bool ToDouble(const char* str, double* value); static bool ToInt64(const char* str, int64_t* value); @@ -599,37 +611,35 @@ namespace tinyxml2 public: /// Get the XMLDocument that owns this XMLNode. - const XMLDocument* GetDocument() const - { + const XMLDocument* GetDocument() const { TIXMLASSERT(_document); return _document; } /// Get the XMLDocument that owns this XMLNode. - XMLDocument* GetDocument() - { + XMLDocument* GetDocument() { TIXMLASSERT(_document); return _document; } /// Safely cast to an Element, or null. - virtual XMLElement* ToElement() { return nullptr; } + virtual XMLElement* ToElement() { return 0; } /// Safely cast to Text, or null. - virtual XMLText* ToText() { return nullptr; } + virtual XMLText* ToText() { return 0; } /// Safely cast to a Comment, or null. - virtual XMLComment* ToComment() { return nullptr; } + virtual XMLComment* ToComment() { return 0; } /// Safely cast to a Document, or null. - virtual XMLDocument* ToDocument() { return nullptr; } + virtual XMLDocument* ToDocument() { return 0; } /// Safely cast to a Declaration, or null. - virtual XMLDeclaration* ToDeclaration() { return nullptr; } + virtual XMLDeclaration* ToDeclaration() { return 0; } /// Safely cast to an Unknown, or null. - virtual XMLUnknown* ToUnknown() { return nullptr; } + virtual XMLUnknown* ToUnknown() { return 0; } - virtual const XMLElement* ToElement() const { return nullptr; } - virtual const XMLText* ToText() const { return nullptr; } - virtual const XMLComment* ToComment() const { return nullptr; } - virtual const XMLDocument* ToDocument() const { return nullptr; } - virtual const XMLDeclaration* ToDeclaration() const { return nullptr; } - virtual const XMLUnknown* ToUnknown() const { return nullptr; } + virtual const XMLElement* ToElement() const { return 0; } + virtual const XMLText* ToText() const { return 0; } + virtual const XMLComment* ToComment() const { return 0; } + virtual const XMLDocument* ToDocument() const { return 0; } + virtual const XMLDeclaration* ToDeclaration() const { return 0; } + virtual const XMLUnknown* ToUnknown() const { return 0; } /** The meaning of 'value' changes for the specific type. @verbatim @@ -645,13 +655,13 @@ namespace tinyxml2 /** Set the Value of an XML node. @sa Value() */ - void SetValue(const char* str, bool staticMem = false); + void SetValue(const char* val, bool staticMem = false); /// Gets the line number the node is in, if the document was parsed from a file. int GetLineNum() const { return _parseLineNum; } /// Get the parent of this node on the DOM. - const XMLNode* Parent() const { return _parent; } + const XMLNode* Parent() const { return _parent; } XMLNode* Parent() { return _parent; } @@ -659,48 +669,48 @@ namespace tinyxml2 bool NoChildren() const { return !_firstChild; } /// Get the first child node, or null if none exists. - const XMLNode* FirstChild() const { return _firstChild; } + const XMLNode* FirstChild() const { return _firstChild; } - XMLNode* FirstChild() { return _firstChild; } + XMLNode* FirstChild() { return _firstChild; } /** Get the first child element, or optionally the first child element with the specified name. */ - const XMLElement* FirstChildElement(const char* name = nullptr) const; + const XMLElement* FirstChildElement(const char* name = 0) const; - XMLElement* FirstChildElement(const char* name = nullptr) { return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->FirstChildElement(name)); } + XMLElement* FirstChildElement(const char* name = 0) { return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->FirstChildElement(name)); } /// Get the last child node, or null if none exists. - const XMLNode* LastChild() const { return _lastChild; } + const XMLNode* LastChild() const { return _lastChild; } - XMLNode* LastChild() { return _lastChild; } + XMLNode* LastChild() { return _lastChild; } /** Get the last child element or optionally the last child element with the specified name. */ - const XMLElement* LastChildElement(const char* name = nullptr) const; + const XMLElement* LastChildElement(const char* name = 0) const; - XMLElement* LastChildElement(const char* name = nullptr) { return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->LastChildElement(name)); } + XMLElement* LastChildElement(const char* name = 0) { return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->LastChildElement(name)); } /// Get the previous (left) sibling node of this node. - const XMLNode* PreviousSibling() const { return _prev; } + const XMLNode* PreviousSibling() const { return _prev; } - XMLNode* PreviousSibling() { return _prev; } + XMLNode* PreviousSibling() { return _prev; } /// Get the previous (left) sibling element of this node, with an optionally supplied name. - const XMLElement* PreviousSiblingElement(const char* name = nullptr) const; + const XMLElement* PreviousSiblingElement(const char* name = 0) const; - XMLElement* PreviousSiblingElement(const char* name = nullptr) { return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->PreviousSiblingElement(name)); } + XMLElement* PreviousSiblingElement(const char* name = 0) { return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->PreviousSiblingElement(name)); } /// Get the next (right) sibling node of this node. - const XMLNode* NextSibling() const { return _next; } + const XMLNode* NextSibling() const { return _next; } - XMLNode* NextSibling() { return _next; } + XMLNode* NextSibling() { return _next; } /// Get the next (right) sibling element of this node, with an optionally supplied name. - const XMLElement* NextSiblingElement(const char* name = nullptr) const; + const XMLElement* NextSiblingElement(const char* name = 0) const; - XMLElement* NextSiblingElement(const char* name = nullptr) { return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->NextSiblingElement(name)); } + XMLElement* NextSiblingElement(const char* name = 0) { return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->NextSiblingElement(name)); } /** Add a child node as the last (right) child. @@ -812,34 +822,34 @@ namespace tinyxml2 */ void* GetUserData() const { return _userData; } - XMLNode(const XMLNode&) = delete; // not supported - XMLNode& operator=(const XMLNode&) = delete; // not supported - protected: explicit XMLNode(XMLDocument*); virtual ~XMLNode(); virtual char* ParseDeep(char* p, StrPair* parentEndTag, int* curLineNumPtr); - XMLDocument* _document; - XMLNode* _parent; - mutable StrPair _value; - int _parseLineNum; + XMLDocument* _document; + XMLNode* _parent; + mutable StrPair _value; + int _parseLineNum; - XMLNode* _firstChild; - XMLNode* _lastChild; + XMLNode* _firstChild; + XMLNode* _lastChild; - XMLNode* _prev; - XMLNode* _next; + XMLNode* _prev; + XMLNode* _next; - void* _userData; + void* _userData; private: - MemPool* _memPool; + MemPool* _memPool; void Unlink(XMLNode* child); static void DeleteNode(XMLNode* node); - static void InsertChildPreamble(XMLNode* insertThis); + void InsertChildPreamble(XMLNode* insertThis) const; const XMLElement* ToElementWithName(const char* name) const; + + XMLNode(const XMLNode&); // not supported + XMLNode& operator=(const XMLNode&); // not supported }; @@ -859,30 +869,30 @@ namespace tinyxml2 { friend class XMLDocument; public: - bool Accept(XMLVisitor* visitor) const override; + virtual bool Accept(XMLVisitor* visitor) const; - XMLText* ToText() override { return this; } - const XMLText* ToText() const override { return this; } + virtual XMLText* ToText() { return this; } + virtual const XMLText* ToText() const { return this; } /// Declare whether this should be CDATA or standard text. - void SetCData(const bool isCData) { _isCData = isCData; } + void SetCData(bool isCData) { _isCData = isCData; } /// Returns true if this is a CDATA text element. bool CData() const { return _isCData; } - XMLNode* ShallowClone(XMLDocument* doc) const override; - bool ShallowEqual(const XMLNode* compare) const override; - - XMLText(const XMLText&) = delete; // not supported - XMLText& operator=(const XMLText&) = delete; // not supported + virtual XMLNode* ShallowClone(XMLDocument* document) const; + virtual bool ShallowEqual(const XMLNode* compare) const; protected: explicit XMLText(XMLDocument* doc) : XMLNode(doc), _isCData(false) {} - virtual ~XMLText() = default; + virtual ~XMLText() {} - char* ParseDeep(char* p, StrPair* parentEndTag, int* curLineNumPtr) override; + char* ParseDeep(char* p, StrPair* parentEndTag, int* curLineNumPtr); private: bool _isCData; + + XMLText(const XMLText&); // not supported + XMLText& operator=(const XMLText&); // not supported }; @@ -891,23 +901,24 @@ namespace tinyxml2 { friend class XMLDocument; public: - XMLComment* ToComment() override { return this; } + virtual XMLComment* ToComment() { return this; } - const XMLComment* ToComment() const override { return this; } + virtual const XMLComment* ToComment() const { return this; } - bool Accept(XMLVisitor* visitor) const override; + virtual bool Accept(XMLVisitor* visitor) const; - XMLNode* ShallowClone(XMLDocument* doc) const override; - bool ShallowEqual(const XMLNode* compare) const override; - - XMLComment(const XMLComment&) = delete; // not supported - XMLComment& operator=(const XMLComment&) = delete; // not supported + virtual XMLNode* ShallowClone(XMLDocument* document) const; + virtual bool ShallowEqual(const XMLNode* compare) const; protected: explicit XMLComment(XMLDocument* doc); virtual ~XMLComment(); - char* ParseDeep(char* p, StrPair* parentEndTag, int* curLineNumPtr) override; + char* ParseDeep(char* p, StrPair* parentEndTag, int* curLineNumPtr); + + private: + XMLComment(const XMLComment&); // not supported + XMLComment& operator=(const XMLComment&); // not supported }; @@ -926,22 +937,23 @@ namespace tinyxml2 { friend class XMLDocument; public: - XMLDeclaration* ToDeclaration() override { return this; } - const XMLDeclaration* ToDeclaration() const override { return this; } - - bool Accept(XMLVisitor* visitor) const override; + virtual XMLDeclaration* ToDeclaration() { return this; } + virtual const XMLDeclaration* ToDeclaration() const { return this; } - XMLNode* ShallowClone(XMLDocument* doc) const override; - bool ShallowEqual(const XMLNode* compare) const override; + virtual bool Accept(XMLVisitor* visitor) const; - XMLDeclaration(const XMLDeclaration&) = delete; // not supported - XMLDeclaration& operator=(const XMLDeclaration&) = delete; // not supported + virtual XMLNode* ShallowClone(XMLDocument* document) const; + virtual bool ShallowEqual(const XMLNode* compare) const; protected: explicit XMLDeclaration(XMLDocument* doc); virtual ~XMLDeclaration(); - char* ParseDeep(char* p, StrPair* parentEndTag, int* curLineNumPtr) override; + char* ParseDeep(char* p, StrPair* parentEndTag, int* curLineNumPtr); + + private: + XMLDeclaration(const XMLDeclaration&); // not supported + XMLDeclaration& operator=(const XMLDeclaration&); // not supported }; @@ -956,22 +968,23 @@ namespace tinyxml2 { friend class XMLDocument; public: - XMLUnknown* ToUnknown() override { return this; } - const XMLUnknown* ToUnknown() const override { return this; } + virtual XMLUnknown* ToUnknown() { return this; } + virtual const XMLUnknown* ToUnknown() const { return this; } - bool Accept(XMLVisitor* visitor) const override; + virtual bool Accept(XMLVisitor* visitor) const; - XMLNode* ShallowClone(XMLDocument* doc) const override; - bool ShallowEqual(const XMLNode* compare) const override; - - XMLUnknown(const XMLUnknown&) = delete; // not supported - XMLUnknown& operator=(const XMLUnknown&) = delete; // not supported + virtual XMLNode* ShallowClone(XMLDocument* document) const; + virtual bool ShallowEqual(const XMLNode* compare) const; protected: explicit XMLUnknown(XMLDocument* doc); virtual ~XMLUnknown(); - char* ParseDeep(char* p, StrPair* parentEndTag, int* curLineNumPtr) override; + char* ParseDeep(char* p, StrPair* parentEndTag, int* curLineNumPtr); + + private: + XMLUnknown(const XMLUnknown&); // not supported + XMLUnknown& operator=(const XMLUnknown&); // not supported }; @@ -1002,44 +1015,38 @@ namespace tinyxml2 If the value isn't an integer, 0 will be returned. There is no error checking; use QueryIntValue() if you need error checking. */ - int IntValue() const - { + int IntValue() const { int i = 0; QueryIntValue(&i); return i; } - int64_t Int64Value() const - { + int64_t Int64Value() const { int64_t i = 0; QueryInt64Value(&i); return i; } /// Query as an unsigned integer. See IntValue() - unsigned UnsignedValue() const - { + unsigned UnsignedValue() const { unsigned i = 0; QueryUnsignedValue(&i); return i; } /// Query as a boolean. See IntValue() - bool BoolValue() const - { + bool BoolValue() const { bool b = false; QueryBoolValue(&b); return b; } /// Query as a double. See IntValue() - double DoubleValue() const - { + double DoubleValue() const { double d = 0; QueryDoubleValue(&d); return d; } /// Query as a float. See IntValue() - float FloatValue() const - { + float FloatValue() const { float f = 0; QueryFloatValue(&f); return f; @@ -1076,24 +1083,23 @@ namespace tinyxml2 /// Set the attribute to value. void SetAttribute(float value); - XMLAttribute(const XMLAttribute&) = delete; // not supported - void operator=(const XMLAttribute&) = delete; // not supported - private: enum { BUF_SIZE = 200 }; - XMLAttribute() = default; - virtual ~XMLAttribute() = default; + XMLAttribute() : _name(), _value(), _parseLineNum(0), _next(0), _memPool(0) {} + virtual ~XMLAttribute() {} + XMLAttribute(const XMLAttribute&); // not supported + void operator=(const XMLAttribute&); // not supported void SetName(const char* name); - char* ParseDeep(char* p, bool processEntities, int* curLineNumPtr) const; + char* ParseDeep(char* p, bool processEntities, int* curLineNumPtr); mutable StrPair _name; mutable StrPair _value; - int _parseLineNum = 0; - XMLAttribute* _next = nullptr; - MemPool* _memPool = nullptr; + int _parseLineNum; + XMLAttribute* _next; + MemPool* _memPool; }; @@ -1108,11 +1114,11 @@ namespace tinyxml2 /// Get the name of an element (which is the Value() of the node.) const char* Name() const { return Value(); } /// Set the name of the element. - void SetName(const char* str, const bool staticMem = false) { SetValue(str, staticMem); } + void SetName(const char* str, bool staticMem = false) { SetValue(str, staticMem); } - XMLElement* ToElement() override { return this; } - const XMLElement* ToElement() const override { return this; } - bool Accept(XMLVisitor* visitor) const override; + virtual XMLElement* ToElement() { return this; } + virtual const XMLElement* ToElement() const { return this; } + virtual bool Accept(XMLVisitor* visitor) const; /** Given an attribute name, Attribute() returns the value for the attribute of that name, or null if none @@ -1135,7 +1141,7 @@ namespace tinyxml2 if ( ele->Attribute( "foo" ) ) { if ( strcmp( ele->Attribute( "foo" ), "bar" ) == 0 ) callFooIsBar(); } @endverbatim */ - const char* Attribute(const char* name, const char* value = nullptr) const; + const char* Attribute(const char* name, const char* value = 0) const; /** Given an attribute name, IntAttribute() returns the value of the attribute interpreted as an integer. The default @@ -1168,54 +1174,47 @@ namespace tinyxml2 QueryIntAttribute( "foo", &value ); // if "foo" isn't found, value will still be 10 @endverbatim */ - XMLError QueryIntAttribute(const char* name, int* value) const - { + XMLError QueryIntAttribute(const char* name, int* value) const { const XMLAttribute* a = FindAttribute(name); if (!a) { return XML_NO_ATTRIBUTE; } return a->QueryIntValue(value); } /// See QueryIntAttribute() - XMLError QueryUnsignedAttribute(const char* name, unsigned int* value) const - { + XMLError QueryUnsignedAttribute(const char* name, unsigned int* value) const { const XMLAttribute* a = FindAttribute(name); if (!a) { return XML_NO_ATTRIBUTE; } return a->QueryUnsignedValue(value); } /// See QueryIntAttribute() - XMLError QueryInt64Attribute(const char* name, int64_t* value) const - { + XMLError QueryInt64Attribute(const char* name, int64_t* value) const { const XMLAttribute* a = FindAttribute(name); if (!a) { return XML_NO_ATTRIBUTE; } return a->QueryInt64Value(value); } /// See QueryIntAttribute() - XMLError QueryBoolAttribute(const char* name, bool* value) const - { + XMLError QueryBoolAttribute(const char* name, bool* value) const { const XMLAttribute* a = FindAttribute(name); if (!a) { return XML_NO_ATTRIBUTE; } return a->QueryBoolValue(value); } /// See QueryIntAttribute() - XMLError QueryDoubleAttribute(const char* name, double* value) const - { + XMLError QueryDoubleAttribute(const char* name, double* value) const { const XMLAttribute* a = FindAttribute(name); if (!a) { return XML_NO_ATTRIBUTE; } return a->QueryDoubleValue(value); } /// See QueryIntAttribute() - XMLError QueryFloatAttribute(const char* name, float* value) const - { + XMLError QueryFloatAttribute(const char* name, float* value) const { const XMLAttribute* a = FindAttribute(name); if (!a) { return XML_NO_ATTRIBUTE; } return a->QueryFloatValue(value); } /// See QueryIntAttribute() - XMLError QueryStringAttribute(const char* name, const char** value) const - { + XMLError QueryStringAttribute(const char* name, const char** value) const { const XMLAttribute* a = FindAttribute(name); if (!a) { return XML_NO_ATTRIBUTE; } *value = a->Value(); @@ -1249,46 +1248,39 @@ namespace tinyxml2 XMLError QueryAttribute(const char* name, float* value) const { return QueryFloatAttribute(name, value); } /// Sets the named attribute to value. - void SetAttribute(const char* name, const char* value) - { + void SetAttribute(const char* name, const char* value) { XMLAttribute* a = FindOrCreateAttribute(name); a->SetAttribute(value); } /// Sets the named attribute to value. - void SetAttribute(const char* name, const int value) - { + void SetAttribute(const char* name, int value) { XMLAttribute* a = FindOrCreateAttribute(name); a->SetAttribute(value); } /// Sets the named attribute to value. - void SetAttribute(const char* name, const unsigned value) - { + void SetAttribute(const char* name, unsigned value) { XMLAttribute* a = FindOrCreateAttribute(name); a->SetAttribute(value); } /// Sets the named attribute to value. - void SetAttribute(const char* name, const int64_t value) - { + void SetAttribute(const char* name, int64_t value) { XMLAttribute* a = FindOrCreateAttribute(name); a->SetAttribute(value); } /// Sets the named attribute to value. - void SetAttribute(const char* name, const bool value) - { + void SetAttribute(const char* name, bool value) { XMLAttribute* a = FindOrCreateAttribute(name); a->SetAttribute(value); } /// Sets the named attribute to value. - void SetAttribute(const char* name, const double value) - { + void SetAttribute(const char* name, double value) { XMLAttribute* a = FindOrCreateAttribute(name); a->SetAttribute(value); } /// Sets the named attribute to value. - void SetAttribute(const char* name, const float value) - { + void SetAttribute(const char* name, float value) { XMLAttribute* a = FindOrCreateAttribute(name); a->SetAttribute(value); } @@ -1411,7 +1403,7 @@ namespace tinyxml2 /// See QueryIntText() XMLError QueryUnsignedText(unsigned* uval) const; /// See QueryIntText() - XMLError QueryInt64Text(int64_t* ival) const; + XMLError QueryInt64Text(int64_t* uval) const; /// See QueryIntText() XMLError QueryBoolText(bool* bval) const; /// See QueryIntText() @@ -1433,26 +1425,23 @@ namespace tinyxml2 float FloatText(float defaultValue = 0) const; // internal: - enum ElementClosingType - { + enum ElementClosingType { OPEN, // <foo> CLOSED, // <foo/> CLOSING // </foo> }; - ElementClosingType ClosingType() const { return _closingType; } - XMLNode* ShallowClone(XMLDocument* doc) const override; - bool ShallowEqual(const XMLNode* compare) const override; - - XMLElement(const XMLElement&) = delete; // not supported - void operator=(const XMLElement&) = delete; // not supported + virtual XMLNode* ShallowClone(XMLDocument* document) const; + virtual bool ShallowEqual(const XMLNode* compare) const; protected: - char* ParseDeep(char* p, StrPair* parentEndTag, int* curLineNumPtr) override; + char* ParseDeep(char* p, StrPair* parentEndTag, int* curLineNumPtr); private: - explicit XMLElement(XMLDocument* doc); + XMLElement(XMLDocument* doc); virtual ~XMLElement(); + XMLElement(const XMLElement&); // not supported + void operator=(const XMLElement&); // not supported XMLAttribute* FindOrCreateAttribute(const char* name); char* ParseAttributes(char* p, int* curLineNumPtr); @@ -1460,17 +1449,15 @@ namespace tinyxml2 XMLAttribute* CreateAttribute(); enum { BUF_SIZE = 200 }; - - ElementClosingType _closingType = OPEN; + ElementClosingType _closingType; // The attribute list is ordered; there is no 'lastAttribute' // because the list needs to be scanned for dupes before adding // a new attribute. - XMLAttribute* _rootAttribute = nullptr; + XMLAttribute* _rootAttribute; }; - enum Whitespace - { + enum Whitespace { PRESERVE_WHITESPACE, COLLAPSE_WHITESPACE }; @@ -1493,17 +1480,15 @@ namespace tinyxml2 friend class XMLUnknown; public: /// constructor - explicit XMLDocument(bool processEntities = true, Whitespace whitespaceMode = PRESERVE_WHITESPACE); + XMLDocument(bool processEntities = true, Whitespace whitespaceMode = PRESERVE_WHITESPACE); ~XMLDocument(); - XMLDocument* ToDocument() override - { + virtual XMLDocument* ToDocument() { TIXMLASSERT(this == _document); return this; } - const XMLDocument* ToDocument() const override - { + virtual const XMLDocument* ToDocument() const { TIXMLASSERT(this == _document); return this; } @@ -1518,7 +1503,7 @@ namespace tinyxml2 specified, TinyXML-2 will assume 'xml' points to a null terminated string. */ - XMLError Parse(const char* xml, size_t len = size_t(-1)); + XMLError Parse(const char* xml, size_t nBytes = (size_t)(-1)); /** Load an XML file from disk. @@ -1565,7 +1550,7 @@ namespace tinyxml2 bool HasBOM() const { return _writeBOM; } /** Sets whether to write the BOM when writing the file. */ - void SetBOM(const bool useBOM) { _writeBOM = useBOM; } + void SetBOM(bool useBOM) { _writeBOM = useBOM; } /** Return the root element of DOM. Equivalent to FirstChildElement(). To get the first node, use FirstChild(). @@ -1587,8 +1572,8 @@ namespace tinyxml2 // printer.CStr() has a const char* to the XML @endverbatim */ - void Print(XMLPrinter* streamer = nullptr) const; - bool Accept(XMLVisitor* visitor) const override; + void Print(XMLPrinter* streamer = 0) const; + virtual bool Accept(XMLVisitor* visitor) const; /** Create a new Element associated with @@ -1601,13 +1586,13 @@ namespace tinyxml2 this Document. The memory for the Comment is managed by the Document. */ - XMLComment* NewComment(const char* str); + XMLComment* NewComment(const char* comment); /** Create a new Text associated with this Document. The memory for the Text is managed by the Document. */ - XMLText* NewText(const char* str); + XMLText* NewText(const char* text); /** Create a new Declaration associated with this Document. The memory for the object @@ -1619,26 +1604,26 @@ namespace tinyxml2 <?xml version="1.0" encoding="UTF-8"?> @endverbatim */ - XMLDeclaration* NewDeclaration(const char* str = nullptr); + XMLDeclaration* NewDeclaration(const char* text = 0); /** Create a new Unknown associated with this Document. The memory for the object is managed by the Document. */ - XMLUnknown* NewUnknown(const char* str); + XMLUnknown* NewUnknown(const char* text); /** Delete a node associated with this document. It will be unlinked from the DOM. */ - static void DeleteNode(XMLNode* node); + void DeleteNode(XMLNode* node); - void ClearError() { SetError(XML_SUCCESS, 0, nullptr); } + void ClearError() { SetError(XML_SUCCESS, 0, 0); } /// Return true if there was an error parsing the document. bool Error() const { return _errorID != XML_SUCCESS; } /// Return the errorID. - XMLError ErrorID() const { return _errorID; } + XMLError ErrorID() const { return _errorID; } const char* ErrorName() const; static const char* ErrorIDToName(XMLError errorID); @@ -1671,22 +1656,22 @@ namespace tinyxml2 // internal void MarkInUse(XMLNode*); - XMLNode* ShallowClone(XMLDocument* /*document*/) const override { return nullptr; } - bool ShallowEqual(const XMLNode* /*compare*/) const override { return false; } - - XMLDocument(const XMLDocument&) = delete; // not supported - void operator=(const XMLDocument&) = delete; // not supported + virtual XMLNode* ShallowClone(XMLDocument* /*document*/) const { return 0; } + virtual bool ShallowEqual(const XMLNode* /*compare*/) const { return false; } private: - bool _writeBOM = false; - bool _processEntities = true; - XMLError _errorID = XML_SUCCESS; - Whitespace _whitespaceMode = PRESERVE_WHITESPACE; - mutable StrPair _errorStr; - int _errorLineNum = 0; - char* _charBuffer = nullptr; - int _parseCurLineNum = 0; - int _parsingDepth = 0; + XMLDocument(const XMLDocument&); // not supported + void operator=(const XMLDocument&); // not supported + + bool _writeBOM; + bool _processEntities; + XMLError _errorID; + Whitespace _whitespaceMode; + mutable StrPair _errorStr; + int _errorLineNum; + char* _charBuffer; + int _parseCurLineNum; + int _parsingDepth; // Memory tracking does add some overhead. // However, the code assumes that you don't // have a bunch of unlinked nodes around. @@ -1695,10 +1680,10 @@ namespace tinyxml2 // and the performance is the same. DynArray<XMLNode*, 10> _unlinked; - MemPoolT<sizeof(XMLElement)> _elementPool; - MemPoolT<sizeof(XMLAttribute)> _attributePool; - MemPoolT<sizeof(XMLText)> _textPool; - MemPoolT<sizeof(XMLComment)> _commentPool; + MemPoolT< sizeof(XMLElement) > _elementPool; + MemPoolT< sizeof(XMLAttribute) > _attributePool; + MemPoolT< sizeof(XMLText) > _textPool; + MemPoolT< sizeof(XMLComment) > _commentPool; static const char* _errorNames[XML_ERROR_COUNT]; @@ -1709,33 +1694,29 @@ namespace tinyxml2 // Something of an obvious security hole, once it was discovered. // Either an ill-formed XML or an excessively deep one can overflow // the stack. Track stack depth, and error out if needed. - class DepthTracker - { + class DepthTracker { public: - explicit DepthTracker(XMLDocument* document) - { + explicit DepthTracker(XMLDocument * document) { this->_document = document; document->PushDepth(); } - ~DepthTracker() { _document->PopDepth(); } private: - XMLDocument* _document; + XMLDocument * _document; }; - void PushDepth(); void PopDepth(); - template <class NodeType, int PoolElementSize> + template<class NodeType, int PoolElementSize> NodeType* CreateUnlinkedNode(MemPoolT<PoolElementSize>& pool); }; - template <class NodeType, int PoolElementSize> - NodeType* XMLDocument::CreateUnlinkedNode(MemPoolT<PoolElementSize>& pool) + template<class NodeType, int PoolElementSize> + inline NodeType* XMLDocument::CreateUnlinkedNode(MemPoolT<PoolElementSize>& pool) { TIXMLASSERT(sizeof(NodeType) == PoolElementSize); TIXMLASSERT(sizeof(NodeType) == pool.ItemSize()); - NodeType* returnNode = new(pool.Alloc()) NodeType(this); + NodeType* returnNode = new (pool.Alloc()) NodeType(this); TIXMLASSERT(returnNode); returnNode->_memPool = &pool; @@ -1806,37 +1787,40 @@ namespace tinyxml2 /// Create a handle from a node. explicit XMLHandle(XMLNode& node) : _node(&node) { } /// Copy constructor - XMLHandle(const XMLHandle& ref) = default; + XMLHandle(const XMLHandle& ref) : _node(ref._node) { } /// Assignment - XMLHandle& operator=(const XMLHandle& ref) = default; + XMLHandle& operator=(const XMLHandle& ref) { + _node = ref._node; + return *this; + } /// Get the first child of this handle. - XMLHandle FirstChild() const { return XMLHandle(_node ? _node->FirstChild() : nullptr); } + XMLHandle FirstChild() { return XMLHandle(_node ? _node->FirstChild() : 0); } /// Get the first child element of this handle. - XMLHandle FirstChildElement(const char* name = nullptr) const { return XMLHandle(_node ? _node->FirstChildElement(name) : nullptr); } + XMLHandle FirstChildElement(const char* name = 0) { return XMLHandle(_node ? _node->FirstChildElement(name) : 0); } /// Get the last child of this handle. - XMLHandle LastChild() const { return XMLHandle(_node ? _node->LastChild() : nullptr); } + XMLHandle LastChild() { return XMLHandle(_node ? _node->LastChild() : 0); } /// Get the last child element of this handle. - XMLHandle LastChildElement(const char* name = nullptr) const { return XMLHandle(_node ? _node->LastChildElement(name) : nullptr); } + XMLHandle LastChildElement(const char* name = 0) { return XMLHandle(_node ? _node->LastChildElement(name) : 0); } /// Get the previous sibling of this handle. - XMLHandle PreviousSibling() const { return XMLHandle(_node ? _node->PreviousSibling() : nullptr); } + XMLHandle PreviousSibling() { return XMLHandle(_node ? _node->PreviousSibling() : 0); } /// Get the previous sibling element of this handle. - XMLHandle PreviousSiblingElement(const char* name = nullptr) const { return XMLHandle(_node ? _node->PreviousSiblingElement(name) : nullptr); } + XMLHandle PreviousSiblingElement(const char* name = 0) { return XMLHandle(_node ? _node->PreviousSiblingElement(name) : 0); } /// Get the next sibling of this handle. - XMLHandle NextSibling() const { return XMLHandle(_node ? _node->NextSibling() : nullptr); } + XMLHandle NextSibling() { return XMLHandle(_node ? _node->NextSibling() : 0); } /// Get the next sibling element of this handle. - XMLHandle NextSiblingElement(const char* name = nullptr) const { return XMLHandle(_node ? _node->NextSiblingElement(name) : nullptr); } + XMLHandle NextSiblingElement(const char* name = 0) { return XMLHandle(_node ? _node->NextSiblingElement(name) : 0); } /// Safe cast to XMLNode. This can return null. - XMLNode* ToNode() const { return _node; } + XMLNode* ToNode() { return _node; } /// Safe cast to XMLElement. This can return null. - XMLElement* ToElement() const { return (_node ? _node->ToElement() : nullptr); } + XMLElement* ToElement() { return (_node ? _node->ToElement() : 0); } /// Safe cast to XMLText. This can return null. - XMLText* ToText() const { return (_node ? _node->ToText() : nullptr); } + XMLText* ToText() { return (_node ? _node->ToText() : 0); } /// Safe cast to XMLUnknown. This can return null. - XMLUnknown* ToUnknown() const { return (_node ? _node->ToUnknown() : nullptr); } + XMLUnknown* ToUnknown() { return (_node ? _node->ToUnknown() : 0); } /// Safe cast to XMLDeclaration. This can return null. - XMLDeclaration* ToDeclaration() const { return (_node ? _node->ToDeclaration() : nullptr); } + XMLDeclaration* ToDeclaration() { return (_node ? _node->ToDeclaration() : 0); } private: XMLNode* _node; @@ -1852,24 +1836,27 @@ namespace tinyxml2 public: explicit XMLConstHandle(const XMLNode* node) : _node(node) { } explicit XMLConstHandle(const XMLNode& node) : _node(&node) { } - XMLConstHandle(const XMLConstHandle& ref) = default; + XMLConstHandle(const XMLConstHandle& ref) : _node(ref._node) { } - XMLConstHandle& operator=(const XMLConstHandle& ref) = default; + XMLConstHandle& operator=(const XMLConstHandle& ref) { + _node = ref._node; + return *this; + } - XMLConstHandle FirstChild() const { return XMLConstHandle(_node ? _node->FirstChild() : nullptr); } - XMLConstHandle FirstChildElement(const char* name = nullptr) const { return XMLConstHandle(_node ? _node->FirstChildElement(name) : nullptr); } - XMLConstHandle LastChild() const { return XMLConstHandle(_node ? _node->LastChild() : nullptr); } - XMLConstHandle LastChildElement(const char* name = nullptr) const { return XMLConstHandle(_node ? _node->LastChildElement(name) : nullptr); } - XMLConstHandle PreviousSibling() const { return XMLConstHandle(_node ? _node->PreviousSibling() : nullptr); } - XMLConstHandle PreviousSiblingElement(const char* name = nullptr) const { return XMLConstHandle(_node ? _node->PreviousSiblingElement(name) : nullptr); } - XMLConstHandle NextSibling() const { return XMLConstHandle(_node ? _node->NextSibling() : nullptr); } - XMLConstHandle NextSiblingElement(const char* name = nullptr) const { return XMLConstHandle(_node ? _node->NextSiblingElement(name) : nullptr); } + const XMLConstHandle FirstChild() const { return XMLConstHandle(_node ? _node->FirstChild() : 0); } + const XMLConstHandle FirstChildElement(const char* name = 0) const { return XMLConstHandle(_node ? _node->FirstChildElement(name) : 0); } + const XMLConstHandle LastChild() const { return XMLConstHandle(_node ? _node->LastChild() : 0); } + const XMLConstHandle LastChildElement(const char* name = 0) const { return XMLConstHandle(_node ? _node->LastChildElement(name) : 0); } + const XMLConstHandle PreviousSibling() const { return XMLConstHandle(_node ? _node->PreviousSibling() : 0); } + const XMLConstHandle PreviousSiblingElement(const char* name = 0) const { return XMLConstHandle(_node ? _node->PreviousSiblingElement(name) : 0); } + const XMLConstHandle NextSibling() const { return XMLConstHandle(_node ? _node->NextSibling() : 0); } + const XMLConstHandle NextSiblingElement(const char* name = 0) const { return XMLConstHandle(_node ? _node->NextSiblingElement(name) : 0); } const XMLNode* ToNode() const { return _node; } - const XMLElement* ToElement() const { return (_node ? _node->ToElement() : nullptr); } - const XMLText* ToText() const { return (_node ? _node->ToText() : nullptr); } - const XMLUnknown* ToUnknown() const { return (_node ? _node->ToUnknown() : nullptr); } - const XMLDeclaration* ToDeclaration() const { return (_node ? _node->ToDeclaration() : nullptr); } + const XMLElement* ToElement() const { return (_node ? _node->ToElement() : 0); } + const XMLText* ToText() const { return (_node ? _node->ToText() : 0); } + const XMLUnknown* ToUnknown() const { return (_node ? _node->ToUnknown() : 0); } + const XMLDeclaration* ToDeclaration() const { return (_node ? _node->ToDeclaration() : 0); } private: const XMLNode* _node; @@ -1927,8 +1914,8 @@ namespace tinyxml2 If 'compact' is set to true, then output is created with only required whitespace and newlines. */ - explicit XMLPrinter(FILE* file = nullptr, bool compact = false, int depth = 0); - virtual ~XMLPrinter() = default; + XMLPrinter(FILE* file = 0, bool compact = false, int depth = 0); + virtual ~XMLPrinter() {} /** If streaming, write the BOM and declaration. */ void PushHeader(bool writeBOM, bool writeDeclaration); @@ -1967,17 +1954,17 @@ namespace tinyxml2 void PushDeclaration(const char* value); void PushUnknown(const char* value); - bool VisitEnter(const XMLDocument& /*doc*/) override; + virtual bool VisitEnter(const XMLDocument& /*doc*/); - bool VisitExit(const XMLDocument& /*doc*/) override { return true; } + virtual bool VisitExit(const XMLDocument& /*doc*/) { return true; } - bool VisitEnter(const XMLElement& element, const XMLAttribute* attribute) override; - bool VisitExit(const XMLElement& element) override; + virtual bool VisitEnter(const XMLElement& element, const XMLAttribute* attribute); + virtual bool VisitExit(const XMLElement& element); - bool Visit(const XMLText& text) override; - bool Visit(const XMLComment& comment) override; - bool Visit(const XMLDeclaration& declaration) override; - bool Visit(const XMLUnknown& unknown) override; + virtual bool Visit(const XMLText& text); + virtual bool Visit(const XMLComment& comment); + virtual bool Visit(const XMLDeclaration& declaration); + virtual bool Visit(const XMLUnknown& unknown); /** If in print to memory mode, return a pointer to @@ -1994,17 +1981,12 @@ namespace tinyxml2 If in print to memory mode, reset the buffer to the beginning. */ - void ClearBuffer() - { + void ClearBuffer() { _buffer.Clear(); _buffer.Push(0); _firstElement = true; } - // Prohibit cloning, intentionally not implemented - XMLPrinter(const XMLPrinter&) = delete; - XMLPrinter& operator=(const XMLPrinter&) = delete; - protected: virtual bool CompactMode(const XMLElement&) { return _compactMode; } @@ -2014,34 +1996,38 @@ namespace tinyxml2 virtual void PrintSpace(int depth); void Print(const char* format, ...); void Write(const char* data, size_t size); - void Write(const char* data) { Write(data, strlen(data)); } + inline void Write(const char* data) { Write(data, strlen(data)); } void Putc(char ch); void SealElementIfJustOpened(); - bool _elementJustOpened = false; - DynArray<const char*, 10> _stack; + bool _elementJustOpened; + DynArray< const char*, 10 > _stack; private: - void PrintString(const char*, bool restricted); // prints out, after detecting entities. + void PrintString(const char*, bool restrictedEntitySet); // prints out, after detecting entities. - bool _firstElement = true; + bool _firstElement; FILE* _fp; - int _depth = 0; - int _textDepth = -1; - bool _processEntities = true; - bool _compactMode = false; + int _depth; + int _textDepth; + bool _processEntities; + bool _compactMode; - enum - { + enum { ENTITY_RANGE = 64, BUF_SIZE = 200 }; + bool _entityFlag[ENTITY_RANGE]; + bool _restrictedEntityFlag[ENTITY_RANGE]; - bool _entityFlag[ENTITY_RANGE]{ }; - bool _restrictedEntityFlag[ENTITY_RANGE]{ }; + DynArray< char, 20 > _buffer; - DynArray<char, 20> _buffer; + // Prohibit cloning, intentionally not implemented + XMLPrinter(const XMLPrinter&); + XMLPrinter& operator=(const XMLPrinter&); }; + + } // tinyxml2 #if defined(_MSC_VER)