tinystr.h | tinystr.h | |||
---|---|---|---|---|
skipping to change at line 33 | skipping to change at line 33 | |||
*/ | */ | |||
#include "tinyxml.h" | #include "tinyxml.h" | |||
#ifndef TIXML_USE_STL | #ifndef TIXML_USE_STL | |||
#ifndef TIXML_STRING_INCLUDED | #ifndef TIXML_STRING_INCLUDED | |||
#define TIXML_STRING_INCLUDED | #define TIXML_STRING_INCLUDED | |||
#ifdef _MSC_VER | #ifdef _MSC_VER | |||
#pragma warning( disable : 4786 ) // Debugger truncating names. | #pragma warning( disable : 4530 ) | |||
#pragma warning( disable : 4786 ) | ||||
#endif | #endif | |||
#include <assert.h> | #include <assert.h> | |||
/* | /* | |||
TiXmlString is an emulation of the std::string template. | TiXmlString is an emulation of the std::string template. | |||
Its purpose is to allow compiling TinyXML on compilers with no or poor S TL support. | Its purpose is to allow compiling TinyXML on compilers with no or poor S TL support. | |||
Only the member functions relevant to the TinyXML project have been impl emented. | Only the member functions relevant to the TinyXML project have been impl emented. | |||
The buffer allocation is made by a simplistic power of 2 like mechanism : if we increase | The buffer allocation is made by a simplistic power of 2 like mechanism : if we increase | |||
a string and there's no more room, we allocate a buffer twice as big as we need. | a string and there's no more room, we allocate a buffer twice as big as we need. | |||
*/ | */ | |||
class TiXmlString | class TiXmlString | |||
{ | { | |||
public : | public : | |||
// TiXmlString constructor, based on a string | // TiXmlString constructor, based on a string, mark explicit to force | |||
TiXmlString (const char * instring); | // us to find unnecessary casting. | |||
explicit TiXmlString (const char * instring); | ||||
// TiXmlString empty constructor | // TiXmlString empty constructor | |||
TiXmlString () | TiXmlString () | |||
{ | { | |||
allocated = 0; | allocated = 0; | |||
cstring = NULL; | cstring = NULL; | |||
current_length = 0; | current_length = 0; | |||
} | } | |||
// TiXmlString copy constructor | // TiXmlString copy constructor | |||
TiXmlString (const TiXmlString& copy); | explicit TiXmlString (const TiXmlString& copy); | |||
// TiXmlString destructor | // TiXmlString destructor | |||
~ TiXmlString () | ~ TiXmlString () | |||
{ | { | |||
empty_it (); | empty_it (); | |||
} | } | |||
// Convert a TiXmlString into a classical char * | // Convert a TiXmlString into a classical char * | |||
const char * c_str () const | const char * c_str () const | |||
{ | { | |||
if (allocated) | if (allocated) | |||
return cstring; | return cstring; | |||
return ""; | return ""; | |||
} | } | |||
// Return the length of a TiXmlString | // Return the length of a TiXmlString | |||
unsigned length () const | size_t length () const | |||
{ | { | |||
return ( allocated ) ? current_length : 0; | return ( allocated ) ? current_length : 0; | |||
} | } | |||
// TiXmlString = operator | // TiXmlString = operator | |||
void operator = (const char * content); | void operator = (const char * content); | |||
// = operator | // = operator | |||
void operator = (const TiXmlString & copy); | void operator = (const TiXmlString & copy); | |||
skipping to change at line 109 | skipping to change at line 111 | |||
return *this; | return *this; | |||
} | } | |||
// += operator. Maps to append | // += operator. Maps to append | |||
TiXmlString& operator += (TiXmlString & suffix) | TiXmlString& operator += (TiXmlString & suffix) | |||
{ | { | |||
append (suffix); | append (suffix); | |||
return *this; | return *this; | |||
} | } | |||
bool operator == (const TiXmlString & compare) const; | bool operator == (const TiXmlString & compare) const; | |||
bool operator == (const char* compare) const; | ||||
bool operator < (const TiXmlString & compare) const; | bool operator < (const TiXmlString & compare) const; | |||
bool operator > (const TiXmlString & compare) const; | bool operator > (const TiXmlString & compare) const; | |||
// Checks if a TiXmlString is empty | // Checks if a TiXmlString is empty | |||
bool empty () const | bool empty () const | |||
{ | { | |||
return length () ? false : true; | return length () ? false : true; | |||
} | } | |||
// single char extraction | // single char extraction | |||
skipping to change at line 160 | skipping to change at line 163 | |||
char& operator [] (unsigned index) const | char& operator [] (unsigned index) const | |||
{ | { | |||
assert( index < length ()); | assert( index < length ()); | |||
return cstring [index]; | return cstring [index]; | |||
} | } | |||
// Error value for find primitive | // Error value for find primitive | |||
enum { notfound = 0xffffffff, | enum { notfound = 0xffffffff, | |||
npos = notfound }; | npos = notfound }; | |||
void append (const char *str, int len ); | void append (const char *str, size_t len ); | |||
protected : | protected : | |||
// The base string | // The base string | |||
char * cstring; | char * cstring; | |||
// Number of chars allocated | // Number of chars allocated | |||
unsigned allocated; | size_t allocated; | |||
// Current string size | // Current string size | |||
unsigned current_length; | size_t current_length; | |||
// New size computation. It is simplistic right now : it returns twice the amount | // New size computation. It is simplistic right now : it returns twice the amount | |||
// we need | // we need | |||
unsigned assign_new_size (unsigned minimum_to_allocate) | size_t assign_new_size (size_t minimum_to_allocate) | |||
{ | { | |||
return minimum_to_allocate * 2; | return minimum_to_allocate * 2; | |||
} | } | |||
// Internal function that clears the content of a TiXmlString | // Internal function that clears the content of a TiXmlString | |||
void empty_it () | void empty_it () | |||
{ | { | |||
if (cstring) | if (cstring) | |||
delete [] cstring; | delete [] cstring; | |||
cstring = NULL; | cstring = NULL; | |||
skipping to change at line 240 | skipping to change at line 243 | |||
} | } | |||
// TiXmlOutStream << operator. Maps to TiXmlString::append | // TiXmlOutStream << operator. Maps to TiXmlString::append | |||
TiXmlOutStream & operator << (const TiXmlString & in) | TiXmlOutStream & operator << (const TiXmlString & in) | |||
{ | { | |||
append (in . c_str ()); | append (in . c_str ()); | |||
return (* this); | return (* this); | |||
} | } | |||
} ; | } ; | |||
#ifdef _MSC_VER | ||||
#pragma warning( default : 4530 ) | ||||
#pragma warning( default : 4786 ) | ||||
#endif | ||||
#endif // TIXML_STRING_INCLUDED | #endif // TIXML_STRING_INCLUDED | |||
#endif // TIXML_USE_STL | #endif // TIXML_USE_STL | |||
End of changes. 10 change blocks. | ||||
9 lines changed or deleted | 17 lines changed or added | |||
tinyxml.h | tinyxml.h | |||
---|---|---|---|---|
skipping to change at line 74 | skipping to change at line 74 | |||
class TiXmlElement; | class TiXmlElement; | |||
class TiXmlComment; | class TiXmlComment; | |||
class TiXmlUnknown; | class TiXmlUnknown; | |||
class TiXmlAttribute; | class TiXmlAttribute; | |||
class TiXmlText; | class TiXmlText; | |||
class TiXmlDeclaration; | class TiXmlDeclaration; | |||
class TiXmlParsingData; | class TiXmlParsingData; | |||
const int TIXML_MAJOR_VERSION = 2; | const int TIXML_MAJOR_VERSION = 2; | |||
const int TIXML_MINOR_VERSION = 3; | const int TIXML_MINOR_VERSION = 3; | |||
const int TIXML_PATCH_VERSION = 3; | const int TIXML_PATCH_VERSION = 4; | |||
/* Internal structure for tracking location of items | /* Internal structure for tracking location of items | |||
in the XML file. | in the XML file. | |||
*/ | */ | |||
struct TiXmlCursor | struct TiXmlCursor | |||
{ | { | |||
TiXmlCursor() { Clear(); } | TiXmlCursor() { Clear(); } | |||
void Clear() { row = col = -1; } | void Clear() { row = col = -1; } | |||
int row; // 0 based. | int row; // 0 based. | |||
skipping to change at line 481 | skipping to change at line 481 | |||
IterateChildren does the same thing with the syntax: | IterateChildren does the same thing with the syntax: | |||
@verbatim | @verbatim | |||
child = 0; | child = 0; | |||
while( child = parent->IterateChildren( child ) ) | while( child = parent->IterateChildren( child ) ) | |||
@endverbatim | @endverbatim | |||
IterateChildren takes the previous child as input and finds | IterateChildren takes the previous child as input and finds | |||
the next one. If the previous child is null, it returns the | the next one. If the previous child is null, it returns the | |||
first. IterateChildren will return null when done. | first. IterateChildren will return null when done. | |||
*/ | */ | |||
const TiXmlNode* IterateChildren( TiXmlNode* previous ) const; | const TiXmlNode* IterateChildren( const TiXmlNode* previous ) const; | |||
TiXmlNode* IterateChildren( TiXmlNode* previous ); | TiXmlNode* IterateChildren( TiXmlNode* previous ); | |||
/// This flavor of IterateChildren searches for children with a part icular 'value' | /// This flavor of IterateChildren searches for children with a part icular 'value' | |||
const TiXmlNode* IterateChildren( const char * value, TiXmlNode* pre vious ) const; | const TiXmlNode* IterateChildren( const char * value, const TiXmlNod e* previous ) const; | |||
TiXmlNode* IterateChildren( const char * value, TiXmlNode* previous ); | TiXmlNode* IterateChildren( const char * value, TiXmlNode* previous ); | |||
#ifdef TIXML_USE_STL | #ifdef TIXML_USE_STL | |||
const TiXmlNode* IterateChildren( const std::string& _value, TiXmlNo de* previous ) const { return IterateChildren (_value.c_str () , previous); } ///< STL std::string form. | const TiXmlNode* IterateChildren( const std::string& _value, const T iXmlNode* previous ) const { return IterateChildren (_value.c_str () , previous); } ///< STL std::string form. | |||
TiXmlNode* IterateChildren( const std::string& _value, TiXmlNode* pr evious ) { return IterateChildren (_value.c_str (), previous); } ///< STL std::string form. | TiXmlNode* IterateChildren( const std::string& _value, TiXmlNode* pr evious ) { return IterateChildren (_value.c_str (), previous); } ///< STL std::string form. | |||
#endif | #endif | |||
/** Add a new node related to this. Adds a child past the LastChild. | /** Add a new node related to this. Adds a child past the LastChild. | |||
Returns a pointer to the new object or NULL if an error occu red. | Returns a pointer to the new object or NULL if an error occu red. | |||
*/ | */ | |||
TiXmlNode* InsertEndChild( const TiXmlNode& addThis ); | TiXmlNode* InsertEndChild( const TiXmlNode& addThis ); | |||
/** Add a new node related to this. Adds a child past the LastChild. | /** Add a new node related to this. Adds a child past the LastChild. | |||
skipping to change at line 1406 | skipping to change at line 1406 | |||
TiXmlElement* Element() const { return ( ( node && node->ToElement () ) ? node->ToElement() : 0 ); } | TiXmlElement* Element() const { return ( ( node && node->ToElement () ) ? node->ToElement() : 0 ); } | |||
/// Return the handle as a TiXmlText. This may return null. | /// Return the handle as a TiXmlText. This may return null. | |||
TiXmlText* Text() const { return ( ( node && node->T oText() ) ? node->ToText() : 0 ); } | TiXmlText* Text() const { return ( ( node && node->T oText() ) ? node->ToText() : 0 ); } | |||
/// Return the handle as a TiXmlUnknown. This may return null; | /// Return the handle as a TiXmlUnknown. This may return null; | |||
TiXmlUnknown* Unknown() const { return ( ( node && node->ToUnknown() ) ? node->ToUnknown() : 0 ); } | TiXmlUnknown* Unknown() const { return ( ( node && node->ToUnknown() ) ? node->ToUnknown() : 0 ); } | |||
private: | private: | |||
TiXmlNode* node; | TiXmlNode* node; | |||
}; | }; | |||
#ifdef _MSC_VER | ||||
#pragma warning( default : 4530 ) | ||||
#pragma warning( default : 4786 ) | ||||
#endif | ||||
#endif | #endif | |||
End of changes. 5 change blocks. | ||||
4 lines changed or deleted | 9 lines changed or added | |||