tinystr.h   tinystr.h 
skipping to change at line 25 skipping to change at line 25
software in a product, an acknowledgment in the product documentation software in a product, an acknowledgment in the product documentation
would be appreciated but is not required. would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and 2. Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software. must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source 3. This notice may not be removed or altered from any source
distribution. distribution.
*/ */
#include "tinyxml.h" /*
* THIS FILE WAS ALTERED BY Tyge Lovset, 7. April 2005.
*
* - completely rewritten. compact, clean, and fast implementation.
* - sizeof(TiXmlString) = pointer size (4 bytes on 32-bit systems)
* - fixed reserve() to work as per specification.
* - fixed buggy compares operator==(), operator<(), and operator>()
* - fixed operator+=() to take a const ref argument, following spec.
* - added "copy" constructor with length, and most compare operators.
* - added swap(), clear(), size(), capacity(), operator+().
*/
#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
#pragma warning( disable : 4530 )
#pragma warning( disable : 4786 )
#endif
#include <assert.h> #include <assert.h>
#include <string.h>
/* /*
TiXmlString is an emulation of the std::string template. TiXmlString is an emulation of a subset 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, mark explicit to force // The size type used
// us to find unnecessary casting. typedef unsigned int size_type;
explicit TiXmlString (const char * instring);
// TiXmlString empty constructor // Error value for find primitive
TiXmlString () static const size_type npos; // = -1;
{
allocated = 0;
cstring = NULL;
current_length = 0;
}
// TiXmlString copy constructor // TiXmlString empty constructor
explicit TiXmlString (const TiXmlString& copy); TiXmlString () : rep_(&nullrep_)
{
}
// TiXmlString destructor // TiXmlString copy constructor
~ TiXmlString () TiXmlString (const TiXmlString & copy)
{ {
empty_it (); init(copy.length());
} memcpy(start(), copy.data(), length());
}
// Convert a TiXmlString into a classical char * // TiXmlString constructor, based on a string
const char * c_str () const TiXmlString (const char * copy)
{ {
if (allocated) init( static_cast<size_type>( strlen(copy) ));
return cstring; memcpy(start(), copy, length());
return ""; }
}
// Return the length of a TiXmlString // TiXmlString constructor, based on a string
size_t length () const TiXmlString (const char * str, size_type len)
{ {
return ( allocated ) ? current_length : 0; init(len);
memcpy(start(), str, len);
} }
// TiXmlString = operator // TiXmlString destructor
void operator = (const char * content); ~TiXmlString ()
{
quit();
}
// = operator // = operator
void operator = (const TiXmlString & copy); TiXmlString& operator = (const char * copy)
{
return assign( copy, (size_type)strlen(copy));
}
// += operator. Maps to append // = operator
TiXmlString& operator += (const char * suffix) TiXmlString& operator = (const TiXmlString & copy)
{ {
append (suffix); return assign(copy.start(), copy.length());
return *this; }
}
// += operator. Maps to append // += operator. Maps to append
TiXmlString& operator += (char single) TiXmlString& operator += (const char * suffix)
{ {
append (single); return append(suffix, static_cast<size_type>( strlen(suffix)
return *this; ));
} }
// += operator. Maps to append // += operator. Maps to append
TiXmlString& operator += (TiXmlString & suffix) TiXmlString& operator += (char single)
{ {
append (suffix); return append(&single, 1);
return *this; }
}
bool operator == (const TiXmlString & compare) const;
bool operator == (const char* compare) const;
bool operator < (const TiXmlString & compare) const;
bool operator > (const TiXmlString & compare) const;
// Checks if a TiXmlString is empty // += operator. Maps to append
bool empty () const TiXmlString& operator += (const TiXmlString & suffix)
{ {
return length () ? false : true; return append(suffix.data(), suffix.length());
} }
// single char extraction // Convert a TiXmlString into a null-terminated char *
const char& at (unsigned index) const const char * c_str () const { return rep_->str; }
{
assert( index < length ());
return cstring [index];
}
// find a char in a string. Return TiXmlString::notfound if not found // Convert a TiXmlString into a char * (need not be null terminated)
unsigned find (char lookup) const .
{ const char * data () const { return rep_->str; }
return find (lookup, 0);
}
// find a char in a string from an offset. Return TiXmlString::notfound // Return the length of a TiXmlString
if not found size_type length () const { return rep_->size; }
unsigned find (char tofind, unsigned offset) const;
/* Function to reserve a big amount of data when we know we'll need it. // Alias for length()
Be aware that this size_type size () const { return rep_->size; }
function clears the content of the TiXmlString if any exists
.
*/
void reserve (unsigned size)
{
empty_it ();
if (size)
{
allocated = size;
cstring = new char [size];
cstring [0] = 0;
current_length = 0;
}
}
// [] operator // Checks if a TiXmlString is empty
char& operator [] (unsigned index) const bool empty () const { return rep_->size == 0; }
{
assert( index < length ());
return cstring [index];
}
// Error value for find primitive // Return capacity of string
enum { notfound = 0xffffffff, size_type capacity () const { return rep_->capacity; }
npos = notfound };
void append (const char *str, size_t len ); // single char extraction
const char& at (size_type index) const
{
assert( index < length() );
return rep_->str[ index ];
}
protected : // [] operator
char& operator [] (size_type index) const
{
assert( index < length() );
return rep_->str[ index ];
}
// The base string // find a char in a string. Return TiXmlString::npos if not found
char * cstring; size_type find (char lookup) const
// Number of chars allocated {
size_t allocated; return find(lookup, 0);
// Current string size }
size_t current_length;
// New size computation. It is simplistic right now : it returns twice // find a char in a string from an offset. Return TiXmlString::npos
the amount if not found
// we need size_type find (char tofind, size_type offset) const
size_t assign_new_size (size_t minimum_to_allocate) {
{ if (offset >= length()) return npos;
return minimum_to_allocate * 2;
}
// Internal function that clears the content of a TiXmlString for (const char* p = c_str() + offset; *p != '\0'; ++p)
void empty_it () {
{ if (*p == tofind) return static_cast< size_type >( p - c_
if (cstring) str() );
delete [] cstring; }
cstring = NULL; return npos;
allocated = 0; }
current_length = 0;
}
void append (const char *suffix ); void clear ()
{
//Lee:
//The original was just too strange, though correct:
// TiXmlString().swap(*this);
//Instead use the quit & re-init:
quit();
init(0,0);
}
// append function for another TiXmlString /* Function to reserve a big amount of data when we know we'll
void append (const TiXmlString & suffix) need it. Be aware that this
{ function DOES NOT clear the content of the TiXmlString if an
append (suffix . c_str ()); y exists.
} */
void reserve (size_type cap);
// append for a single char. TiXmlString& assign (const char* str, size_type len);
void append (char single)
{ TiXmlString& append (const char* str, size_type len);
if ( cstring && current_length < (allocated-1) )
void swap (TiXmlString& other)
{
Rep* r = rep_;
rep_ = other.rep_;
other.rep_ = r;
}
private:
void init(size_type sz) { init(sz, sz); }
void set_size(size_type sz) { rep_->str[ rep_->size = sz ] = '\0'; }
char* start() const { return rep_->str; }
char* finish() const { return rep_->str + rep_->size; }
struct Rep
{
size_type size, capacity;
char str[1];
};
void init(size_type sz, size_type cap)
{
if (cap)
{ {
cstring[ current_length ] = single; rep_ = static_cast<Rep*>(operator new(sizeof(Rep) +
++current_length; cap));
cstring[ current_length ] = 0; rep_->str[ rep_->size = sz ] = '\0';
rep_->capacity = cap;
} }
else else
{ {
char smallstr [2]; rep_ = &nullrep_;
smallstr [0] = single;
smallstr [1] = 0;
append (smallstr);
} }
} }
void quit()
{
if (rep_ != &nullrep_)
{
operator delete(rep_);
}
}
Rep * rep_;
static Rep nullrep_;
} ; } ;
inline bool operator == (const TiXmlString & a, const TiXmlString & b)
{
return ( a.length() == b.length() ) // o
ptimization on some platforms
&& ( strcmp(a.c_str(), b.c_str()) == 0 ); // actual co
mpare
}
inline bool operator < (const TiXmlString & a, const TiXmlString & b)
{
return strcmp(a.c_str(), b.c_str()) < 0;
}
inline bool operator != (const TiXmlString & a, const TiXmlString & b) { re
turn !(a == b); }
inline bool operator > (const TiXmlString & a, const TiXmlString & b) { re
turn b < a; }
inline bool operator <= (const TiXmlString & a, const TiXmlString & b) { re
turn !(b < a); }
inline bool operator >= (const TiXmlString & a, const TiXmlString & b) { re
turn !(a < b); }
inline bool operator == (const TiXmlString & a, const char* b) { return str
cmp(a.c_str(), b) == 0; }
inline bool operator == (const char* a, const TiXmlString & b) { return b =
= a; }
inline bool operator != (const TiXmlString & a, const char* b) { return !(a
== b); }
inline bool operator != (const char* a, const TiXmlString & b) { return !(b
== a); }
TiXmlString operator + (const TiXmlString & a, const TiXmlString & b);
TiXmlString operator + (const TiXmlString & a, const char* b);
TiXmlString operator + (const char* a, const TiXmlString & b);
/* /*
TiXmlOutStream is an emulation of std::ostream. It is based on TiXmlStri ng. TiXmlOutStream is an emulation of std::ostream. It is based on TiXmlStri ng.
Only the operators that we need for TinyXML have been developped. Only the operators that we need for TinyXML have been developped.
*/ */
class TiXmlOutStream : public TiXmlString class TiXmlOutStream : public TiXmlString
{ {
public : public :
TiXmlOutStream () : TiXmlString () {}
// TiXmlOutStream << operator. Maps to TiXmlString::append // TiXmlOutStream << operator.
TiXmlOutStream & operator << (const char * in) TiXmlOutStream & operator << (const TiXmlString & in)
{ {
append (in); *this += in;
return (* this); return *this;
} }
// TiXmlOutStream << operator. Maps to TiXmlString::append // TiXmlOutStream << operator.
TiXmlOutStream & operator << (const TiXmlString & in) TiXmlOutStream & operator << (const char * in)
{ {
append (in . c_str ()); *this += in;
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. 39 change blocks. 
164 lines changed or deleted 216 lines changed or added


 tinyxml.h   tinyxml.h 
skipping to change at line 29 skipping to change at line 29
must not be misrepresented as being the original software. must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source 3. This notice may not be removed or altered from any source
distribution. distribution.
*/ */
#ifndef TINYXML_INCLUDED #ifndef TINYXML_INCLUDED
#define TINYXML_INCLUDED #define TINYXML_INCLUDED
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning( push )
#pragma warning( disable : 4530 ) #pragma warning( disable : 4530 )
#pragma warning( disable : 4786 ) #pragma warning( disable : 4786 )
#endif #endif
#include <ctype.h> #include <ctype.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <assert.h> #include <assert.h>
skipping to change at line 63 skipping to change at line 64
#include <iostream> #include <iostream>
#define TIXML_STRING std::string #define TIXML_STRING std::string
#define TIXML_ISTREAM std::istream #define TIXML_ISTREAM std::istream
#define TIXML_OSTREAM std::ostream #define TIXML_OSTREAM std::ostream
#else #else
#include "tinystr.h" #include "tinystr.h"
#define TIXML_STRING TiXmlString #define TIXML_STRING TiXmlString
#define TIXML_OSTREAM TiXmlOutStream #define TIXML_OSTREAM TiXmlOutStream
#endif #endif
// Deprecated library function hell. Compilers want to use the
// new safe versions. This probably doesn't fully address the problem,
// but it gets closer. There are too many compilers for me to fully
// test. If you get compilation troubles, undefine TIXML_SAFE
#define TIXML_SAFE // TinyXml isn't fully buffer overrun protec
ted, safe code. This is work in progress.
#ifdef TIXML_SAFE
#if defined(_MSC_VER) && (_MSC_VER >= 1200 )
// Microsoft visual studio, version 6 and higher.
//#pragma message( "Using _sn* functions." )
#define TIXML_SNPRINTF _snprintf
#define TIXML_SNSCANF _snscanf
#elif defined(__GNUC__) && (__GNUC__ >= 3 )
// GCC version 3 and higher.s
//#warning( "Using sn* functions." )
#define TIXML_SNPRINTF snprintf
#define TIXML_SNSCANF snscanf
#endif
#endif
class TiXmlDocument; class TiXmlDocument;
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 = 4;
const int TIXML_PATCH_VERSION = 4; const int TIXML_PATCH_VERSION = 0;
/* 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 205 skipping to change at line 226
TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME, TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME,
TIXML_ERROR_READING_ELEMENT_VALUE, TIXML_ERROR_READING_ELEMENT_VALUE,
TIXML_ERROR_READING_ATTRIBUTES, TIXML_ERROR_READING_ATTRIBUTES,
TIXML_ERROR_PARSING_EMPTY, TIXML_ERROR_PARSING_EMPTY,
TIXML_ERROR_READING_END_TAG, TIXML_ERROR_READING_END_TAG,
TIXML_ERROR_PARSING_UNKNOWN, TIXML_ERROR_PARSING_UNKNOWN,
TIXML_ERROR_PARSING_COMMENT, TIXML_ERROR_PARSING_COMMENT,
TIXML_ERROR_PARSING_DECLARATION, TIXML_ERROR_PARSING_DECLARATION,
TIXML_ERROR_DOCUMENT_EMPTY, TIXML_ERROR_DOCUMENT_EMPTY,
TIXML_ERROR_EMBEDDED_NULL, TIXML_ERROR_EMBEDDED_NULL,
TIXML_ERROR_PARSING_CDATA,
TIXML_ERROR_STRING_COUNT TIXML_ERROR_STRING_COUNT
}; };
protected: protected:
// See STL_STRING_BUG // See STL_STRING_BUG
// Utility class to overcome a bug. // Utility class to overcome a bug.
class StringToBuffer class StringToBuffer
{ {
skipping to change at line 277 skipping to change at line 299
if ( *length == 1 ) if ( *length == 1 )
{ {
if ( *p == '&' ) if ( *p == '&' )
return GetEntity( p, _value, length, encodin g ); return GetEntity( p, _value, length, encodin g );
*_value = *p; *_value = *p;
return p+1; return p+1;
} }
else if ( *length ) else if ( *length )
{ {
strncpy( _value, p, *length ); //strncpy( _value, p, *length ); // lots of c
ompilers don't like this function (unsafe),
// and the null terminator isn't needed
for( int i=0; p[i] && i<*length; ++i ) {
_value[i] = p[i];
}
return p + (*length); return p + (*length);
} }
else else
{ {
// Not valid text. // Not valid text.
return 0; return 0;
} }
} }
// Puts a string to a stream, expanding entities as it goes. // Puts a string to a stream, expanding entities as it goes.
// Note this should not contian the '<', '>', etc, or they will be t ransformed into entities! // Note this should not contian the '<', '>', etc, or they will be t ransformed into entities!
static void PutString( const TIXML_STRING& str, TIXML_OSTREAM* out ) ; static void PutString( const TIXML_STRING& str, TIXML_OSTREAM* out ) ;
static void PutString( const TIXML_STRING& str, TIXML_STRING* out ); static void PutString( const TIXML_STRING& str, TIXML_STRING* out );
// Return true if the next characters in the stream are any of the e ndTag sequences. // Return true if the next characters in the stream are any of the e ndTag sequences.
// Ignore case only works for english, and should only be relied on when comparing // Ignore case only works for english, and should only be relied on when comparing
// to Engilish words: StringEqual( p, "version", true ) is fine. // to English words: StringEqual( p, "version", true ) is fine.
static bool StringEqual( const char* p, static bool StringEqual( const char* p,
const char* endTag, const char* endTag,
bool ignoreC ase, bool ignoreC ase,
TiXmlEncodin g encoding ); TiXmlEncodin g encoding );
static const char* errorString[ TIXML_ERROR_STRING_COUNT ]; static const char* errorString[ TIXML_ERROR_STRING_COUNT ];
TiXmlCursor location; TiXmlCursor location;
/// Field containing a generic user pointer /// Field containing a generic user pointer
skipping to change at line 419 skipping to change at line 445
@verbatim @verbatim
Document: filename of the xml file Document: filename of the xml file
Element: name of the element Element: name of the element
Comment: the comment text Comment: the comment text
Unknown: the tag contents Unknown: the tag contents
Text: the text string Text: the text string
@endverbatim @endverbatim
The subclasses will wrap this function. The subclasses will wrap this function.
*/ */
const char * Value() const { return value.c_str (); } const char *Value() const { return value.c_str (); }
#ifdef TIXML_USE_STL
/** Return Value() as a std::string. If you only use STL,
this is more efficient than calling Value().
Only available in STL mode.
*/
const std::string& ValueStr() const { return value; }
#endif
/** Changes the value of the node. Defined as: /** Changes the value of the node. Defined as:
@verbatim @verbatim
Document: filename of the xml file Document: filename of the xml file
Element: name of the element Element: name of the element
Comment: the comment text Comment: the comment text
Unknown: the tag contents Unknown: the tag contents
Text: the text string Text: the text string
@endverbatim @endverbatim
*/ */
skipping to change at line 631 skipping to change at line 665
void CopyTo( TiXmlNode* target ) const; void CopyTo( TiXmlNode* target ) const;
#ifdef TIXML_USE_STL #ifdef TIXML_USE_STL
// The real work of the input operator. // The real work of the input operator.
virtual void StreamIn( TIXML_ISTREAM* in, TIXML_STRING* tag ) = 0; virtual void StreamIn( TIXML_ISTREAM* in, TIXML_STRING* tag ) = 0;
#endif #endif
// Figure out what is at *p, and parse it. Returns null if it is not an xml node. // Figure out what is at *p, and parse it. Returns null if it is not an xml node.
TiXmlNode* Identify( const char* start, TiXmlEncoding encoding ); TiXmlNode* Identify( const char* start, TiXmlEncoding encoding );
// Internal Value function returning a TIXML_STRING
const TIXML_STRING& SValue() const { return value ; }
TiXmlNode* parent; TiXmlNode* parent;
NodeType type; NodeType type;
TiXmlNode* firstChild; TiXmlNode* firstChild;
TiXmlNode* lastChild; TiXmlNode* lastChild;
TIXML_STRING value; TIXML_STRING value;
TiXmlNode* prev; TiXmlNode* prev;
TiXmlNode* next; TiXmlNode* next;
skipping to change at line 691 skipping to change at line 722
TiXmlAttribute( const char * _name, const char * _value ) TiXmlAttribute( const char * _name, const char * _value )
{ {
name = _name; name = _name;
value = _value; value = _value;
document = 0; document = 0;
prev = next = 0; prev = next = 0;
} }
const char* Name() const { return name.c_str (); } ///< Return the name of this attribute. const char* Name() const { return name.c_str (); } ///< Return the name of this attribute.
const char* Value() const { return value.c_str (); } ///< Return the value of this attribute. const char* Value() const { return value.c_str (); } ///< Return the value of this attribute.
const int IntValue() const; int IntValue() const;
///< Return the value of this attribute ///< Return the value o
, converted to an integer. f this attribute, converted to an integer.
const double DoubleValue() const; double DoubleValue() const;
///< Return the value of this attribute, conver ///< Return the value of this attribute
ted to a double. , converted to a double.
/** QueryIntValue examines the value string. It is an alternative to the /** QueryIntValue examines the value string. It is an alternative to the
IntValue() method with richer error checking. IntValue() method with richer error checking.
If the value is an integer, it is stored in 'value' and If the value is an integer, it is stored in 'value' and
the call returns TIXML_SUCCESS. If it is not the call returns TIXML_SUCCESS. If it is not
an integer, it returns TIXML_WRONG_TYPE. an integer, it returns TIXML_WRONG_TYPE.
A specialized but useful call. Note that for success it retu rns 0, A specialized but useful call. Note that for success it retu rns 0,
which is the opposite of almost all other TinyXml calls. which is the opposite of almost all other TinyXml calls.
*/ */
int QueryIntValue( int* value ) const; int QueryIntValue( int* _value ) const;
/// QueryDoubleValue examines the value string. See QueryIntValue(). /// QueryDoubleValue examines the value string. See QueryIntValue().
int QueryDoubleValue( double* value ) const; int QueryDoubleValue( double* _value ) const;
void SetName( const char* _name ) { name = _name; } ///< Set the name of this attribute. void SetName( const char* _name ) { name = _name; } ///< Set the name of this attribute.
void SetValue( const char* _value ) { value = _value; } ///< Set the value. void SetValue( const char* _value ) { value = _value; } ///< Set the value.
void SetIntValue( int value ); void SetIntValue( int _value );
///< Set the value from an integer. ///< Set the value from an integer.
void SetDoubleValue( double value ); void SetDoubleValue( double _value );
///< Set the value from a double. ///< Set the value from a double.
#ifdef TIXML_USE_STL #ifdef TIXML_USE_STL
/// STL std::string form. /// STL std::string form.
void SetName( const std::string& _name ) void SetName( const std::string& _name )
{ {
StringToBuffer buf( _name ); StringToBuffer buf( _name );
SetName ( buf.buffer ? buf.buffer : "error" ); SetName ( buf.buffer ? buf.buffer : "error" );
} }
/// STL std::string form. /// STL std::string form.
void SetValue( const std::string& _value ) void SetValue( const std::string& _value )
skipping to change at line 850 skipping to change at line 881
*/ */
const char* Attribute( const char* name, double* d ) const; const char* Attribute( const char* name, double* d ) const;
/** QueryIntAttribute examines the attribute - it is an alternative to the /** QueryIntAttribute examines the attribute - it is an alternative to the
Attribute() method with richer error checking. Attribute() method with richer error checking.
If the attribute is an integer, it is stored in 'value' and If the attribute is an integer, it is stored in 'value' and
the call returns TIXML_SUCCESS. If it is not the call returns TIXML_SUCCESS. If it is not
an integer, it returns TIXML_WRONG_TYPE. If the attribute an integer, it returns TIXML_WRONG_TYPE. If the attribute
does not exist, then TIXML_NO_ATTRIBUTE is returned. does not exist, then TIXML_NO_ATTRIBUTE is returned.
*/ */
int QueryIntAttribute( const char* name, int* value ) const; int QueryIntAttribute( const char* name, int* _value ) const;
/// QueryDoubleAttribute examines the attribute - see QueryIntAttrib ute(). /// QueryDoubleAttribute examines the attribute - see QueryIntAttrib ute().
int QueryDoubleAttribute( const char* name, double* value ) const; int QueryDoubleAttribute( const char* name, double* _value ) const;
/// QueryFloatAttribute examines the attribute - see QueryIntAttribu te(). /// QueryFloatAttribute examines the attribute - see QueryIntAttribu te().
int QueryDoubleAttribute( const char* name, float* value ) const { int QueryFloatAttribute( const char* name, float* _value ) const {
double d; double d;
int result = QueryDoubleAttribute( name, &d ); int result = QueryDoubleAttribute( name, &d );
*value = (float)d; if ( result == TIXML_SUCCESS ) {
*_value = (float)d;
}
return result; return result;
} }
/** Sets an attribute of name to a given value. The attribute /** Sets an attribute of name to a given value. The attribute
will be created if it does not exist, or changed if it does. will be created if it does not exist, or changed if it does.
*/ */
void SetAttribute( const char* name, const char * value ); void SetAttribute( const char* name, const char * _value );
#ifdef TIXML_USE_STL #ifdef TIXML_USE_STL
const char* Attribute( const std::string& name ) const { return Attribute( name.c_str() ); } const char* Attribute( const std::string& name ) const { return Attribute( name.c_str() ); }
const char* Attribute( const std::string& name, int* i ) const { return Attribute( name.c_str(), i ); } const char* Attribute( const std::string& name, int* i ) const { return Attribute( name.c_str(), i ); }
const char* Attribute( const std::string& name, double* d ) const { return Attribute( name.c_str(), d ); } const char* Attribute( const std::string& name, double* d ) const { return Attribute( name.c_str(), d ); }
int QueryIntAttribute( const std::string& name, int* value ) const int QueryIntAttribute( const std::string& name, int* _value ) const
{ return QueryIntAttribute( name.c_str(), value ); } { return QueryIntAttribute( name.c_str(), _value ); }
int QueryDoubleAttribute( const std::string& name, double* value ) c int QueryDoubleAttribute( const std::string& name, double* _value )
onst { return QueryDoubleAttribute( name.c_str(), value ); } const { return QueryDoubleAttribute( name.c_str(), _value ); }
/// STL std::string form. /// STL std::string form.
void SetAttribute( const std::string& name, const std::string& _valu e ) void SetAttribute( const std::string& name, const std::string& _valu e )
{ {
StringToBuffer n( name ); StringToBuffer n( name );
StringToBuffer v( _value ); StringToBuffer v( _value );
if ( n.buffer && v.buffer ) if ( n.buffer && v.buffer )
SetAttribute (n.buffer, v.buffer ); SetAttribute (n.buffer, v.buffer );
} }
///< STL std::string form. ///< STL std::string form.
skipping to change at line 912 skipping to change at line 945
void RemoveAttribute( const char * name ); void RemoveAttribute( const char * name );
#ifdef TIXML_USE_STL #ifdef TIXML_USE_STL
void RemoveAttribute( const std::string& name ) { RemoveAttrib ute (name.c_str ()); } ///< STL std::string form. void RemoveAttribute( const std::string& name ) { RemoveAttrib ute (name.c_str ()); } ///< STL std::string form.
#endif #endif
const TiXmlAttribute* FirstAttribute() const { return attributeSe t.First(); } ///< Access the first attribute in this element . const TiXmlAttribute* FirstAttribute() const { return attributeSe t.First(); } ///< Access the first attribute in this element .
TiXmlAttribute* FirstAttribute() { re turn attributeSet.First(); } TiXmlAttribute* FirstAttribute() { re turn attributeSet.First(); }
const TiXmlAttribute* LastAttribute() const { return attributeSe t.Last(); } ///< Access the last attribute in this element. const TiXmlAttribute* LastAttribute() const { return attributeSe t.Last(); } ///< Access the last attribute in this element.
TiXmlAttribute* LastAttribute() { re turn attributeSet.Last(); } TiXmlAttribute* LastAttribute() { re turn attributeSet.Last(); }
/** Convenience function for easy access to the text inside an eleme
nt. Although easy
and concise, GetText() is limited compared to getting the Ti
XmlText child
and accessing it directly.
If the first child of 'this' is a TiXmlText, the GetText()
returs the character string of the Text node, else null is r
eturned.
This is a convenient method for getting the text of simple c
ontained text:
@verbatim
<foo>This is text</foo>
const char* str = fooElement->GetText();
@endverbatim
'str' will be a pointer to "This is text".
Note that this function can be misleading. If the element fo
o was created from
this XML:
@verbatim
<foo><b>This is text</b></foo>
@endverbatim
then the value of str would be null. The first child node is
n't a text node, it is
another element. From this XML:
@verbatim
<foo>This is <b>text</b></foo>
@endverbatim
GetText() will return "This is ".
WARNING: GetText() accesses a child node - don't become conf
used with the
similarly named TiXmlHandle::Text() and TiX
mlNode::ToText() which are
safe type casts on the referenced node.
*/
const char* GetText() const;
/// Creates a new Element and returns it - the returned element is a copy. /// Creates a new Element and returns it - the returned element is a copy.
virtual TiXmlNode* Clone() const; virtual TiXmlNode* Clone() const;
// Print the Element to a FILE stream. // Print the Element to a FILE stream.
virtual void Print( FILE* cfile, int depth ) const; virtual void Print( FILE* cfile, int depth ) const;
/* Attribtue parsing starts: next char past '<' /* Attribtue parsing starts: next char past '<'
returns: next char past '>' returns: next char past '>'
*/ */
virtual const char* Parse( const char* p, TiXmlParsingData* data, Ti XmlEncoding encoding ); virtual const char* Parse( const char* p, TiXmlParsingData* data, Ti XmlEncoding encoding );
skipping to change at line 979 skipping to change at line 1046
// used to be public // used to be public
#ifdef TIXML_USE_STL #ifdef TIXML_USE_STL
virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag ); virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
#endif #endif
virtual void StreamOut( TIXML_OSTREAM * out ) const; virtual void StreamOut( TIXML_OSTREAM * out ) const;
private: private:
}; };
/** XML text. Contained in an element. /** XML text. A text node can have 2 ways to output the next. "normal" outp
ut
and CDATA. It will default to the mode it was parsed from the XML fi
le and
you generally want to leave it alone, but you can change the output
mode with
SetCDATA() and query it with CDATA().
*/ */
class TiXmlText : public TiXmlNode class TiXmlText : public TiXmlNode
{ {
friend class TiXmlElement; friend class TiXmlElement;
public: public:
/// Constructor. /** Constructor for text element. By default, it is treated as
TiXmlText (const char * initValue) : TiXmlNode (TiXmlNode::TEXT) normal, encoded text. If you want it be output as a CDATA te
xt
element, set the parameter _cdata to 'true'
*/
TiXmlText (const char * initValue ) : TiXmlNode (TiXmlNode::TEXT)
{ {
SetValue( initValue ); SetValue( initValue );
cdata = false;
} }
virtual ~TiXmlText() {} virtual ~TiXmlText() {}
#ifdef TIXML_USE_STL #ifdef TIXML_USE_STL
/// Constructor. /// Constructor.
TiXmlText( const std::string& initValue ) : TiXmlNode (TiXmlNode::TE XT) TiXmlText( const std::string& initValue ) : TiXmlNode (TiXmlNode::TE XT)
{ {
SetValue( initValue ); SetValue( initValue );
cdata = false;
} }
#endif #endif
TiXmlText( const TiXmlText& copy ) : TiXmlNode( TiXmlNode::TEXT ) { copy.CopyTo( this ); } TiXmlText( const TiXmlText& copy ) : TiXmlNode( TiXmlNode::TEXT ) { copy.CopyTo( this ); }
void operator=( const TiXmlText& base ) { base.CopyTo( this ); } void operator=( const TiXmlText& base ) { base.CopyTo( this ); }
/// Write this text object to a FILE stream. /// Write this text object to a FILE stream.
virtual void Print( FILE* cfile, int depth ) const; virtual void Print( FILE* cfile, int depth ) const;
/// Queries whether this represents text using a CDATA section.
bool CDATA() { return cdata; }
/// Turns on or off a CDATA representation of text.
void SetCDATA( bool _cdata ) { cdata = _cdata; }
virtual const char* Parse( const char* p, TiXmlParsingData* data, Ti XmlEncoding encoding ); virtual const char* Parse( const char* p, TiXmlParsingData* data, Ti XmlEncoding encoding );
protected : protected :
/// [internal use] Creates a new Element and returns it. /// [internal use] Creates a new Element and returns it.
virtual TiXmlNode* Clone() const; virtual TiXmlNode* Clone() const;
void CopyTo( TiXmlText* target ) const; void CopyTo( TiXmlText* target ) const;
virtual void StreamOut ( TIXML_OSTREAM * out ) const; virtual void StreamOut ( TIXML_OSTREAM * out ) const;
bool Blank() const; // returns true if all white space and new l ines bool Blank() const; // returns true if all white space and new l ines
// [internal use] // [internal use]
#ifdef TIXML_USE_STL #ifdef TIXML_USE_STL
virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag ); virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
#endif #endif
private: private:
bool cdata; // true if this should be input and output as a CDATA style text element
}; };
/** In correct XML the declaration is the first entry in the file. /** In correct XML the declaration is the first entry in the file.
@verbatim @verbatim
<?xml version="1.0" standalone="yes"?> <?xml version="1.0" standalone="yes"?>
@endverbatim @endverbatim
TinyXml will happily read or write files without a declaration, TinyXml will happily read or write files without a declaration,
however. There are 3 possible attributes to the declaration: however. There are 3 possible attributes to the declaration:
version, encoding, and standalone. version, encoding, and standalone.
skipping to change at line 1196 skipping to change at line 1277
- The ErrorRow() and ErrorCol() will return the location of the error (if known) - The ErrorRow() and ErrorCol() will return the location of the error (if known)
*/ */
bool Error() const { re turn error; } bool Error() const { re turn error; }
/// Contains a textual (english) description of the error if one occ urs. /// Contains a textual (english) description of the error if one occ urs.
const char * ErrorDesc() const { return errorDesc.c_str (); } const char * ErrorDesc() const { return errorDesc.c_str (); }
/** Generally, you probably want the error string ( ErrorDesc() ). B ut if you /** Generally, you probably want the error string ( ErrorDesc() ). B ut if you
prefer the ErrorId, this function will fetch it. prefer the ErrorId, this function will fetch it.
*/ */
const int ErrorId() const { return err orId; } int ErrorId() const { return errorId; }
/** Returns the location (if known) of the error. The first column i s column 1, /** Returns the location (if known) of the error. The first column i s column 1,
and the first row is row 1. A value of 0 means the row and c olumn wasn't applicable and the first row is row 1. A value of 0 means the row and c olumn wasn't applicable
(memory errors, for example, have no row/column) or the pars er lost the error. (An (memory errors, for example, have no row/column) or the pars er lost the error. (An
error in the error reporting, in that case.) error in the error reporting, in that case.)
@sa SetTabSize, Row, Column @sa SetTabSize, Row, Column
*/ */
int ErrorRow() { return errorLocation.row+1; } int ErrorRow() { return errorLocation.row+1; }
int ErrorCol() { return errorLocation.col+1; } ///< The column wher e the error occured. See ErrorRow() int ErrorCol() { return errorLocation.col+1; } ///< The column wher e the error occured. See ErrorRow()
/** By calling this method, with a tab size /** SetTabSize() allows the error reporting functions (ErrorRow() an
d ErrorCol())
to report the correct values for row and column. It does not
change the output
or input in any way.
By calling this method, with a tab size
greater than 0, the row and column of each node and attribut e is stored greater than 0, the row and column of each node and attribut e is stored
when the file is loaded. Very useful for tracking the DOM ba ck in to when the file is loaded. Very useful for tracking the DOM ba ck in to
the source file. the source file.
The tab size is required for calculating the location of nod es. If not The tab size is required for calculating the location of nod es. If not
set, the default of 4 is used. The tabsize is set per docume nt. Setting set, the default of 4 is used. The tabsize is set per docume nt. Setting
the tabsize to 0 disables row/column tracking. the tabsize to 0 disables row/column tracking.
Note that row and column tracking is not supported when usin g operator>>. Note that row and column tracking is not supported when usin g operator>>.
skipping to change at line 1266 skipping to change at line 1351
#endif #endif
private: private:
void CopyTo( TiXmlDocument* target ) const; void CopyTo( TiXmlDocument* target ) const;
bool error; bool error;
int errorId; int errorId;
TIXML_STRING errorDesc; TIXML_STRING errorDesc;
int tabsize; int tabsize;
TiXmlCursor errorLocation; TiXmlCursor errorLocation;
bool useMicrosoftBOM; // the UTF-8 BOM were found when rea d. Note this, and try to write.
}; };
/** /**
A TiXmlHandle is a class that wraps a node pointer with null checks; this is A TiXmlHandle is a class that wraps a node pointer with null checks; this is
an incredibly useful thing. Note that TiXmlHandle is not part of the TinyXml an incredibly useful thing. Note that TiXmlHandle is not part of the TinyXml
DOM structure. It is a separate utility class. DOM structure. It is a separate utility class.
Take an example: Take an example:
@verbatim @verbatim
<Document> <Document>
skipping to change at line 1352 skipping to change at line 1438
for( child; child; child=child->NextSiblingElement() ) for( child; child; child=child->NextSiblingElement() )
{ {
// do something // do something
} }
@endverbatim @endverbatim
*/ */
class TiXmlHandle class TiXmlHandle
{ {
public: public:
/// Create a handle from any node (at any depth of the tree.) This c an be a null pointer. /// Create a handle from any node (at any depth of the tree.) This c an be a null pointer.
TiXmlHandle( TiXmlNode* node ) { th is->node = node; } TiXmlHandle( TiXmlNode* _node ) { th is->node = _node; }
/// Copy constructor /// Copy constructor
TiXmlHandle( const TiXmlHandle& ref ) { this->node = ref.node; } TiXmlHandle( const TiXmlHandle& ref ) { this->node = ref.node; }
TiXmlHandle operator=( const TiXmlHandle& ref ) { this->node = ref.n ode; return *this; } TiXmlHandle operator=( const TiXmlHandle& ref ) { this->node = ref.n ode; return *this; }
/// Return a handle to the first child node. /// Return a handle to the first child node.
TiXmlHandle FirstChild() const; TiXmlHandle FirstChild() const;
/// Return a handle to the first child node with the given name. /// Return a handle to the first child node with the given name.
TiXmlHandle FirstChild( const char * value ) const; TiXmlHandle FirstChild( const char * value ) const;
/// Return a handle to the first child element. /// Return a handle to the first child element.
TiXmlHandle FirstChildElement() const; TiXmlHandle FirstChildElement() const;
skipping to change at line 1407 skipping to change at line 1493
/// 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 #ifdef _MSC_VER
#pragma warning( default : 4530 ) #pragma warning( pop )
#pragma warning( default : 4786 )
#endif #endif
#endif #endif
 End of changes. 30 change blocks. 
37 lines changed or deleted 139 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/