tinyxml.h   tinyxml.h 
skipping to change at line 94 skipping to change at line 94
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 = 5; const int TIXML_MINOR_VERSION = 6;
const int TIXML_PATCH_VERSION = 3; 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.
int col; // 0 based. int col; // 0 based.
}; };
/** /**
Implements the interface to the "Visitor pattern" (see the Accept() method.)
If you call the Accept() method, it requires being passed a TiXmlVis itor If you call the Accept() method, it requires being passed a TiXmlVis itor
class to handle callbacks. For nodes that contain other nodes (Docum ent, Element) class to handle callbacks. For nodes that contain other nodes (Docum ent, Element)
you will get called with a VisitEnter/VisitExit pair. Nodes that are always leaves you will get called with a VisitEnter/VisitExit pair. Nodes that are always leaves
are simple called with Visit(). are simply called with Visit().
If you return 'true' from a Visit method, recursive parsing will con tinue. If you return If you return 'true' from a Visit method, recursive parsing will con tinue. If you return
false, <b>no children of this node or its sibilings</b> will be Visi ted. false, <b>no children of this node or its sibilings</b> will be Visi ted.
All flavors of Visit methods have a default implementation that retu rns 'true' (continue All flavors of Visit methods have a default implementation that retu rns 'true' (continue
visiting). You need to only override methods that are interesting to you. visiting). You need to only override methods that are interesting to you.
Generally Accept() is called on the TiXmlDocument, although all node s suppert Visiting. Generally Accept() is called on the TiXmlDocument, although all node s suppert Visiting.
You should never change the document from a callback. You should never change the document from a callback.
skipping to change at line 267 skipping to change at line 268
/** Expands entities in a string. Note this should not contian the t ag's '<', '>', etc, /** Expands entities in a string. Note this should not contian the t ag's '<', '>', etc,
or they will be transformed into entities! or they will be transformed into entities!
*/ */
static void EncodeString( const TIXML_STRING& str, TIXML_STRING* out ); static void EncodeString( const TIXML_STRING& str, TIXML_STRING* out );
enum enum
{ {
TIXML_NO_ERROR = 0, TIXML_NO_ERROR = 0,
TIXML_ERROR, TIXML_ERROR,
TIXML_ERROR_OPENING_FILE, TIXML_ERROR_OPENING_FILE,
TIXML_ERROR_OUT_OF_MEMORY,
TIXML_ERROR_PARSING_ELEMENT, TIXML_ERROR_PARSING_ELEMENT,
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,
skipping to change at line 461 skipping to change at line 462
/// Appends the XML node or attribute to a std::string. /// Appends the XML node or attribute to a std::string.
friend std::string& operator<< (std::string& out, const TiXm lNode& base ); friend std::string& operator<< (std::string& out, const TiXm lNode& base );
#endif #endif
/** The types of XML nodes supported by TinyXml. (All the /** The types of XML nodes supported by TinyXml. (All the
unsupported types are picked up by UNKNOWN.) unsupported types are picked up by UNKNOWN.)
*/ */
enum NodeType enum NodeType
{ {
DOCUMENT, TINYXML_DOCUMENT,
ELEMENT, TINYXML_ELEMENT,
COMMENT, TINYXML_COMMENT,
UNKNOWN, TINYXML_UNKNOWN,
TEXT, TINYXML_TEXT,
DECLARATION, TINYXML_DECLARATION,
TYPECOUNT TINYXML_TYPECOUNT
}; };
virtual ~TiXmlNode(); virtual ~TiXmlNode();
/** The meaning of 'value' changes for the specific type of /** The meaning of 'value' changes for the specific type of
TiXmlNode. TiXmlNode.
@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
skipping to change at line 911 skipping to change at line 912
~TiXmlAttributeSet(); ~TiXmlAttributeSet();
void Add( TiXmlAttribute* attribute ); void Add( TiXmlAttribute* attribute );
void Remove( TiXmlAttribute* attribute ); void Remove( TiXmlAttribute* attribute );
const TiXmlAttribute* First() const { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; } const TiXmlAttribute* First() const { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; }
TiXmlAttribute* First() { return ( s entinel.next == &sentinel ) ? 0 : sentinel.next; } TiXmlAttribute* First() { return ( s entinel.next == &sentinel ) ? 0 : sentinel.next; }
const TiXmlAttribute* Last() const { return ( sentinel. prev == &sentinel ) ? 0 : sentinel.prev; } const TiXmlAttribute* Last() const { return ( sentinel. prev == &sentinel ) ? 0 : sentinel.prev; }
TiXmlAttribute* Last() { return ( s entinel.prev == &sentinel ) ? 0 : sentinel.prev; } TiXmlAttribute* Last() { return ( s entinel.prev == &sentinel ) ? 0 : sentinel.prev; }
const TiXmlAttribute* Find( const char* _name ) const; TiXmlAttribute* Find( const char* _name ) const;
TiXmlAttribute* Find( const char* _name ) { TiXmlAttribute* FindOrCreate( const char* _name );
return const_cast< TiXmlAttribute* >( (const_cast< const TiX
mlAttributeSet* >(this))->Find( _name ) );
}
#ifdef TIXML_USE_STL
const TiXmlAttribute* Find( const std::string& _name ) const;
TiXmlAttribute* Find( const std::string& _name ) {
return const_cast< TiXmlAttribute* >( (const_cast< const TiX
mlAttributeSet* >(this))->Find( _name ) );
}
#endif # ifdef TIXML_USE_STL
TiXmlAttribute* Find( const std::string& _name ) const;
TiXmlAttribute* FindOrCreate( const std::string& _name );
# endif
private: private:
//*ME: Because of hidden/disabled copy-construktor in TiXmlAttribut e (sentinel-element), //*ME: Because of hidden/disabled copy-construktor in TiXmlAttribut e (sentinel-element),
//*ME: this class must be also use a hidden/disabled copy-construct or !!! //*ME: this class must be also use a hidden/disabled copy-construct or !!!
TiXmlAttributeSet( const TiXmlAttributeSet& ); // not allowed TiXmlAttributeSet( const TiXmlAttributeSet& ); // not allowed
void operator=( const TiXmlAttributeSet& ); // not allowed (as T iXmlAttribute) void operator=( const TiXmlAttributeSet& ); // not allowed (as T iXmlAttribute)
TiXmlAttribute sentinel; TiXmlAttribute sentinel;
}; };
skipping to change at line 995 skipping to change at line 992
int QueryFloatAttribute( 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 );
if ( result == TIXML_SUCCESS ) { if ( result == TIXML_SUCCESS ) {
*_value = (float)d; *_value = (float)d;
} }
return result; return result;
} }
#ifdef TIXML_USE_STL #ifdef TIXML_USE_STL
/// QueryStringAttribute examines the attribute - see QueryIntAttrib
ute().
int QueryStringAttribute( const char* name, std::string* _value ) co
nst {
const char* cstr = Attribute( name );
if ( cstr ) {
*_value = std::string( cstr );
return TIXML_SUCCESS;
}
return TIXML_NO_ATTRIBUTE;
}
/** Template form of the attribute query which will try to read the /** Template form of the attribute query which will try to read the
attribute into the specified type. Very easy, very powerful, but attribute into the specified type. Very easy, very powerful, but
be careful to make sure to call this with the correct type. be careful to make sure to call this with the correct type.
NOTE: This method doesn't work correctly for 'string' types. NOTE: This method doesn't work correctly for 'string' types that contain spaces.
@return TIXML_SUCCESS, TIXML_WRONG_TYPE, or TIXML_NO_ATTRIBU TE @return TIXML_SUCCESS, TIXML_WRONG_TYPE, or TIXML_NO_ATTRIBU TE
*/ */
template< typename T > int QueryValueAttribute( const std::string& n ame, T* outValue ) const template< typename T > int QueryValueAttribute( const std::string& n ame, T* outValue ) const
{ {
const TiXmlAttribute* node = attributeSet.Find( name ); const TiXmlAttribute* node = attributeSet.Find( name );
if ( !node ) if ( !node )
return TIXML_NO_ATTRIBUTE; return TIXML_NO_ATTRIBUTE;
std::stringstream sstream( node->ValueStr() ); std::stringstream sstream( node->ValueStr() );
sstream >> *outValue; sstream >> *outValue;
if ( !sstream.fail() ) if ( !sstream.fail() )
return TIXML_SUCCESS; return TIXML_SUCCESS;
return TIXML_WRONG_TYPE; return TIXML_WRONG_TYPE;
} }
/*
This is - in theory - a bug fix for "QueryValueAtribute returns tru
ncated std::string"
but template specialization is hard to get working cross-compiler.
Leaving the bug for now.
// The above will fail for std::string because the space character i int QueryValueAttribute( const std::string& name, std::string* outVa
s used as a seperator. lue ) const
// Specialize for strings. Bug [ 1695429 ] QueryValueAtribute return
s truncated std::string
template<> int QueryValueAttribute( const std::string& name, std::st
ring* outValue ) const
{ {
const TiXmlAttribute* node = attributeSet.Find( name ); const TiXmlAttribute* node = attributeSet.Find( name );
if ( !node ) if ( !node )
return TIXML_NO_ATTRIBUTE; return TIXML_NO_ATTRIBUTE;
*outValue = node->ValueStr(); *outValue = node->ValueStr();
return TIXML_SUCCESS; return TIXML_SUCCESS;
} }
*/
#endif #endif
/** 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 std::string* Attribute( const std::string& name ) const; const std::string* Attribute( const std::string& name ) const;
const std::string* Attribute( const std::string& name, int* i ) cons t; const std::string* Attribute( const std::string& name, int* i ) cons t;
const std::string* Attribute( const std::string& name, double* d ) c onst; const std::string* Attribute( const std::string& name, double* d ) c onst;
int QueryIntAttribute( const std::string& name, int* _value ) const; int QueryIntAttribute( const std::string& name, int* _value ) const;
int QueryDoubleAttribute( const std::string& name, double* _value ) const; int QueryDoubleAttribute( const std::string& name, double* _value ) const;
/// 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 );
///< STL std::string form. ///< STL std::string form.
void SetAttribute( const std::string& name, int _value ); void SetAttribute( const std::string& name, int _value );
///< STL std::string form.
void SetDoubleAttribute( const std::string& name, double value );
#endif #endif
/** 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, int value ); void SetAttribute( const char * name, int value );
/** 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.
*/ */
skipping to change at line 1139 skipping to change at line 1142
#ifdef TIXML_USE_STL #ifdef TIXML_USE_STL
virtual void StreamIn( std::istream * in, TIXML_STRING * tag ); virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
#endif #endif
/* [internal use] /* [internal use]
Reads the "value" of the element -- another element, or text . Reads the "value" of the element -- another element, or text .
This should terminate with the current end tag. This should terminate with the current end tag.
*/ */
const char* ReadValue( const char* in, TiXmlParsingData* prevData, T iXmlEncoding encoding ); const char* ReadValue( const char* in, TiXmlParsingData* prevData, T iXmlEncoding encoding );
private: private:
TiXmlAttributeSet attributeSet; TiXmlAttributeSet attributeSet;
}; };
/** An XML comment. /** An XML comment.
*/ */
class TiXmlComment : public TiXmlNode class TiXmlComment : public TiXmlNode
{ {
public: public:
/// Constructs an empty comment. /// Constructs an empty comment.
TiXmlComment() : TiXmlNode( TiXmlNode::COMMENT ) {} TiXmlComment() : TiXmlNode( TiXmlNode::TINYXML_COMMENT ) {}
/// Construct a comment from text. /// Construct a comment from text.
TiXmlComment( const char* _value ) : TiXmlNode( TiXmlNode::COMMENT ) { TiXmlComment( const char* _value ) : TiXmlNode( TiXmlNode::TINYXML_C OMMENT ) {
SetValue( _value ); SetValue( _value );
} }
TiXmlComment( const TiXmlComment& ); TiXmlComment( const TiXmlComment& );
void operator=( const TiXmlComment& base ); void operator=( const TiXmlComment& base );
virtual ~TiXmlComment() {} virtual ~TiXmlComment() {}
/// Returns a copy of this Comment. /// Returns a copy of this Comment.
virtual TiXmlNode* Clone() const; virtual TiXmlNode* Clone() const;
// Write this Comment to a FILE stream. // Write this Comment to a FILE stream.
skipping to change at line 1202 skipping to change at line 1204
SetCDATA() and query it with CDATA(). SetCDATA() and query it with CDATA().
*/ */
class TiXmlText : public TiXmlNode class TiXmlText : public TiXmlNode
{ {
friend class TiXmlElement; friend class TiXmlElement;
public: public:
/** Constructor for text element. By default, it is treated as /** Constructor for text element. By default, it is treated as
normal, encoded text. If you want it be output as a CDATA te xt normal, encoded text. If you want it be output as a CDATA te xt
element, set the parameter _cdata to 'true' element, set the parameter _cdata to 'true'
*/ */
TiXmlText (const char * initValue ) : TiXmlNode (TiXmlNode::TEXT) TiXmlText (const char * initValue ) : TiXmlNode (TiXmlNode::TINYXML_ TEXT)
{ {
SetValue( initValue ); SetValue( initValue );
cdata = false; 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::TI NYXML_TEXT)
{ {
SetValue( initValue ); SetValue( initValue );
cdata = false; cdata = false;
} }
#endif #endif
TiXmlText( const TiXmlText& copy ) : TiXmlNode( TiXmlNode::TEXT ) { copy.CopyTo( this ); } TiXmlText( const TiXmlText& copy ) : TiXmlNode( TiXmlNode::TINYXML_T EXT ) { 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. /// Queries whether this represents text using a CDATA section.
bool CDATA() const { return cdata; } bool CDATA() const { return cdata; }
/// Turns on or off a CDATA representation of text. /// Turns on or off a CDATA representation of text.
void SetCDATA( bool _cdata ) { cdata = _cdata; } void SetCDATA( bool _cdata ) { cdata = _cdata; }
skipping to change at line 1270 skipping to change at line 1272
version, encoding, and standalone. version, encoding, and standalone.
Note: In this version of the code, the attributes are Note: In this version of the code, the attributes are
handled as special cases, not generic attributes, simply handled as special cases, not generic attributes, simply
because there can only be at most 3 and they are always the same. because there can only be at most 3 and they are always the same.
*/ */
class TiXmlDeclaration : public TiXmlNode class TiXmlDeclaration : public TiXmlNode
{ {
public: public:
/// Construct an empty declaration. /// Construct an empty declaration.
TiXmlDeclaration() : TiXmlNode( TiXmlNode::DECLARATION ) {} TiXmlDeclaration() : TiXmlNode( TiXmlNode::TINYXML_DECLARATION ) { }
#ifdef TIXML_USE_STL #ifdef TIXML_USE_STL
/// Constructor. /// Constructor.
TiXmlDeclaration( const std::string& _version, TiXmlDeclaration( const std::string& _version,
const std::string& _encoding , const std::string& _encoding ,
const std::string& _standalo ne ); const std::string& _standalo ne );
#endif #endif
/// Construct. /// Construct.
TiXmlDeclaration( const char* _version, TiXmlDeclaration( const char* _version,
skipping to change at line 1337 skipping to change at line 1339
/** Any tag that tinyXml doesn't recognize is saved as an /** Any tag that tinyXml doesn't recognize is saved as an
unknown. It is a tag of text, but should not be modified. unknown. It is a tag of text, but should not be modified.
It will be written back to the XML, unchanged, when the file It will be written back to the XML, unchanged, when the file
is saved. is saved.
DTD tags get thrown into TiXmlUnknowns. DTD tags get thrown into TiXmlUnknowns.
*/ */
class TiXmlUnknown : public TiXmlNode class TiXmlUnknown : public TiXmlNode
{ {
public: public:
TiXmlUnknown() : TiXmlNode( TiXmlNode::UNKNOWN ) {} TiXmlUnknown() : TiXmlNode( TiXmlNode::TINYXML_UNKNOWN ) {}
virtual ~TiXmlUnknown() {} virtual ~TiXmlUnknown() {}
TiXmlUnknown( const TiXmlUnknown& copy ) : TiXmlNode( TiXmlNode::UNK NOWN ) { copy.CopyTo( this ); } TiXmlUnknown( const TiXmlUnknown& copy ) : TiXmlNode( TiXmlNode::TIN YXML_UNKNOWN ) { copy.CopyTo( this ); }
void operator=( const TiXmlUnknown& copy ) { copy.CopyTo( this ); } void operator=( const TiXmlUnknown& copy ) { copy.CopyTo( this ); }
/// Creates a copy of this Unknown and returns it. /// Creates a copy of this Unknown and returns it.
virtual TiXmlNode* Clone() const; virtual TiXmlNode* Clone() const;
// Print this Unknown to a FILE stream. // Print this Unknown to a FILE stream.
virtual void Print( FILE* cfile, int depth ) const; virtual void Print( FILE* cfile, int depth ) const;
virtual const char* Parse( const char* p, TiXmlParsingData* data, Ti XmlEncoding encoding ); virtual const char* Parse( const char* p, TiXmlParsingData* data, Ti XmlEncoding encoding );
virtual const TiXmlUnknown* ToUnknown() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type. virtual const TiXmlUnknown* ToUnknown() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
skipping to change at line 1413 skipping to change at line 1415
will be interpreted as an XML file. TinyXML doesn't stream i n XML from the current will be interpreted as an XML file. TinyXML doesn't stream i n XML from the current
file location. Streaming may be added in the future. file location. Streaming may be added in the future.
*/ */
bool LoadFile( FILE*, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODIN G ); bool LoadFile( FILE*, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODIN G );
/// Save a file using the given FILE*. Returns true if successful. /// Save a file using the given FILE*. Returns true if successful.
bool SaveFile( FILE* ) const; bool SaveFile( FILE* ) const;
#ifdef TIXML_USE_STL #ifdef TIXML_USE_STL
bool LoadFile( const std::string& filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING ) ///< STL std::string version. bool LoadFile( const std::string& filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING ) ///< STL std::string version.
{ {
// StringToBuffer f( filename );
// return ( f.buffer && LoadFile( f.buffer, encoding ));
return LoadFile( filename.c_str(), encoding ); return LoadFile( filename.c_str(), encoding );
} }
bool SaveFile( const std::string& filename ) const ///< STL std::string version. bool SaveFile( const std::string& filename ) const ///< STL std::string version.
{ {
// StringToBuffer f( filename );
// return ( f.buffer && SaveFile( f.buffer ));
return SaveFile( filename.c_str() ); return SaveFile( filename.c_str() );
} }
#endif #endif
/** Parse the given null terminated block of xml data. Passing in an encoding to this /** Parse the given null terminated block of xml data. Passing in an encoding to this
method (either TIXML_ENCODING_LEGACY or TIXML_ENCODING_UTF8 will force TinyXml method (either TIXML_ENCODING_LEGACY or TIXML_ENCODING_UTF8 will force TinyXml
to use that encoding, regardless of what TinyXml might other wise try to detect. to use that encoding, regardless of what TinyXml might other wise try to detect.
*/ */
virtual const char* Parse( const char* p, TiXmlParsingData* data = 0 , TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING ); virtual const char* Parse( const char* p, TiXmlParsingData* data = 0 , TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
 End of changes. 24 change blocks. 
49 lines changed or deleted 42 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/