Updating tinyxml to 2.6.1 (fixes small xml issues).

This commit is contained in:
lotodore
2010-10-11 16:09:14 +00:00
parent 972f678730
commit 845bf979dc
7 changed files with 410 additions and 359 deletions
+78 -51
View File
@@ -20,6 +20,10 @@ must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
THIS IS A MODIFIED SOURCE VERSION, IT INCLUDES THE DEFAULT
DEFINE FOR TIXML_USE_STL!
*/
#define TIXML_USE_STL
@@ -63,17 +67,20 @@ distribution.
#if defined(_MSC_VER) && (_MSC_VER >= 1400 )
// Microsoft visual studio, version 2005 and higher.
#define TIXML_SNPRINTF _snprintf_s
#define TIXML_SNSCANF _snscanf_s
#define TIXML_SSCANF sscanf_s
#elif 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
#define TIXML_SSCANF sscanf
#elif defined(__GNUC__) && (__GNUC__ >= 3 )
// GCC version 3 and higher.s
//#warning( "Using sn* functions." )
#define TIXML_SNPRINTF snprintf
#define TIXML_SNSCANF snscanf
#define TIXML_SSCANF sscanf
#else
#define TIXML_SNPRINTF snprintf
#define TIXML_SSCANF sscanf
#endif
#endif
@@ -87,8 +94,8 @@ class TiXmlDeclaration;
class TiXmlParsingData;
const int TIXML_MAJOR_VERSION = 2;
const int TIXML_MINOR_VERSION = 5;
const int TIXML_PATCH_VERSION = 2;
const int TIXML_MINOR_VERSION = 6;
const int TIXML_PATCH_VERSION = 1;
/* Internal structure for tracking location of items
in the XML file.
@@ -104,10 +111,11 @@ struct TiXmlCursor
/**
Implements the interface to the "Visitor pattern" (see the Accept() method.)
If you call the Accept() method, it requires being passed a TiXmlVisitor
class to handle callbacks. For nodes that contain other nodes (Document, Element)
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 continue. If you return
false, <b>no children of this node or its sibilings</b> will be Visited.
@@ -127,23 +135,23 @@ public:
virtual ~TiXmlVisitor() {}
/// Visit a document.
virtual bool VisitEnter( const TiXmlDocument& ) { return true; }
virtual bool VisitEnter( const TiXmlDocument& /*doc*/ ) { return true; }
/// Visit a document.
virtual bool VisitExit( const TiXmlDocument& ) { return true; }
virtual bool VisitExit( const TiXmlDocument& /*doc*/ ) { return true; }
/// Visit an element.
virtual bool VisitEnter( const TiXmlElement&, const TiXmlAttribute* ) { return true; }
virtual bool VisitEnter( const TiXmlElement& /*element*/, const TiXmlAttribute* /*firstAttribute*/ ) { return true; }
/// Visit an element.
virtual bool VisitExit( const TiXmlElement& ) { return true; }
virtual bool VisitExit( const TiXmlElement& /*element*/ ) { return true; }
/// Visit a declaration
virtual bool Visit( const TiXmlDeclaration& ) { return true; }
virtual bool Visit( const TiXmlDeclaration& /*declaration*/ ) { return true; }
/// Visit a text node
virtual bool Visit( const TiXmlText& ) { return true; }
virtual bool Visit( const TiXmlText& /*text*/ ) { return true; }
/// Visit a comment node
virtual bool Visit( const TiXmlComment& ) { return true; }
virtual bool Visit( const TiXmlComment& /*comment*/ ) { return true; }
/// Visit an unknow node
virtual bool Visit( const TiXmlUnknown& ) { return true; }
virtual bool Visit( const TiXmlUnknown& /*unknown*/ ) { return true; }
};
// Only used by Attribute::Query functions
@@ -252,12 +260,16 @@ public:
TiXmlParsingData* data,
TiXmlEncoding encoding /*= TIXML_ENCODING_UNKNOWN */ ) = 0;
/** Expands entities in a string. Note this should not contian the tag's '<', '>', etc,
or they will be transformed into entities!
*/
static void EncodeString( const TIXML_STRING& str, TIXML_STRING* out );
enum
{
TIXML_NO_ERROR = 0,
TIXML_ERROR,
TIXML_ERROR_OPENING_FILE,
TIXML_ERROR_OUT_OF_MEMORY,
TIXML_ERROR_PARSING_ELEMENT,
TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME,
TIXML_ERROR_READING_ELEMENT_VALUE,
@@ -278,6 +290,7 @@ public:
protected:
static const char* SkipWhiteSpace( const char*, TiXmlEncoding encoding );
inline static bool IsWhiteSpace( char c )
{
return ( isspace( (unsigned char) c ) || c == '\n' || c == '\r' );
@@ -351,10 +364,6 @@ protected:
}
}
// Puts a string to a stream, expanding entities as it goes.
// Note this should not contian the '<', '>', etc, or they will be transformed into entities!
static void PutString( const TIXML_STRING& str, TIXML_STRING* out );
// Return true if the next characters in the stream are any of the endTag sequences.
// Ignore case only works for english, and should only be relied on when comparing
// to English words: StringEqual( p, "version", true ) is fine.
@@ -456,13 +465,13 @@ public:
*/
enum NodeType
{
DOCUMENT,
ELEMENT,
COMMENT,
UNKNOWN,
TEXT,
DECLARATION,
TYPECOUNT
TINYXML_DOCUMENT,
TINYXML_ELEMENT,
TINYXML_COMMENT,
TINYXML_UNKNOWN,
TINYXML_TEXT,
TINYXML_DECLARATION,
TINYXML_TYPECOUNT
};
virtual ~TiXmlNode();
@@ -489,6 +498,8 @@ public:
const std::string& ValueStr() const { return value; }
#endif
const TIXML_STRING& ValueTStr() const { return value; }
/** Changes the value of the node. Defined as:
@verbatim
Document: filename of the xml file
@@ -512,8 +523,8 @@ public:
TiXmlNode* Parent() { return parent; }
const TiXmlNode* Parent() const { return parent; }
const TiXmlNode* FirstChild() const { return firstChild; } ///< The first child of this node. Will be null if there are no children.
TiXmlNode* FirstChild() { return firstChild; }
const TiXmlNode* FirstChild() const { return firstChild; } ///< The first child of this node. Will be null if there are no children.
TiXmlNode* FirstChild() { return firstChild; }
const TiXmlNode* FirstChild( const char * value ) const; ///< The first child of this node with the matching 'value'. Will be null if none found.
/// The first child of this node with the matching 'value'. Will be null if none found.
TiXmlNode* FirstChild( const char * _value ) {
@@ -907,17 +918,14 @@ public:
const TiXmlAttribute* Last() const { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }
TiXmlAttribute* Last() { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }
const TiXmlAttribute* Find( const char* _name ) const;
TiXmlAttribute* Find( const char* _name ) {
return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttributeSet* >(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 TiXmlAttributeSet* >(this))->Find( _name ) );
}
TiXmlAttribute* Find( const char* _name ) const;
TiXmlAttribute* FindOrCreate( const char* _name );
# ifdef TIXML_USE_STL
TiXmlAttribute* Find( const std::string& _name ) const;
TiXmlAttribute* FindOrCreate( const std::string& _name );
# endif
#endif
private:
//*ME: Because of hidden/disabled copy-construktor in TiXmlAttribute (sentinel-element),
@@ -990,10 +998,23 @@ public:
}
return result;
}
#ifdef TIXML_USE_STL
/// QueryStringAttribute examines the attribute - see QueryIntAttribute().
int QueryStringAttribute( const char* name, std::string* _value ) const {
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
attribute into the specified type. Very easy, very powerful, but
be careful to make sure to call this with the correct type.
NOTE: This method doesn't work correctly for 'string' types that contain spaces.
@return TIXML_SUCCESS, TIXML_WRONG_TYPE, or TIXML_NO_ATTRIBUTE
*/
@@ -1009,6 +1030,15 @@ public:
return TIXML_SUCCESS;
return TIXML_WRONG_TYPE;
}
int QueryValueAttribute( const std::string& name, std::string* outValue ) const
{
const TiXmlAttribute* node = attributeSet.Find( name );
if ( !node )
return TIXML_NO_ATTRIBUTE;
*outValue = node->ValueStr();
return TIXML_SUCCESS;
}
#endif
/** Sets an attribute of name to a given value. The attribute
@@ -1027,6 +1057,8 @@ public:
void SetAttribute( const std::string& name, const std::string& _value );
///< STL std::string form.
void SetAttribute( const std::string& name, int _value );
///< STL std::string form.
void SetDoubleAttribute( const std::string& name, double value );
#endif
/** Sets an attribute of name to a given value. The attribute
@@ -1118,7 +1150,6 @@ protected:
const char* ReadValue( const char* in, TiXmlParsingData* prevData, TiXmlEncoding encoding );
private:
TiXmlAttributeSet attributeSet;
};
@@ -1129,9 +1160,9 @@ class TiXmlComment : public TiXmlNode
{
public:
/// Constructs an empty comment.
TiXmlComment() : TiXmlNode( TiXmlNode::COMMENT ) {}
TiXmlComment() : TiXmlNode( TiXmlNode::TINYXML_COMMENT ) {}
/// Construct a comment from text.
TiXmlComment( const char* _value ) : TiXmlNode( TiXmlNode::COMMENT ) {
TiXmlComment( const char* _value ) : TiXmlNode( TiXmlNode::TINYXML_COMMENT ) {
SetValue( _value );
}
TiXmlComment( const TiXmlComment& );
@@ -1183,7 +1214,7 @@ public:
normal, encoded text. If you want it be output as a CDATA text
element, set the parameter _cdata to 'true'
*/
TiXmlText (const char * initValue ) : TiXmlNode (TiXmlNode::TEXT)
TiXmlText (const char * initValue ) : TiXmlNode (TiXmlNode::TINYXML_TEXT)
{
SetValue( initValue );
cdata = false;
@@ -1192,14 +1223,14 @@ public:
#ifdef TIXML_USE_STL
/// Constructor.
TiXmlText( const std::string& initValue ) : TiXmlNode (TiXmlNode::TEXT)
TiXmlText( const std::string& initValue ) : TiXmlNode (TiXmlNode::TINYXML_TEXT)
{
SetValue( initValue );
cdata = false;
}
#endif
TiXmlText( const TiXmlText& copy ) : TiXmlNode( TiXmlNode::TEXT ) { copy.CopyTo( this ); }
TiXmlText( const TiXmlText& copy ) : TiXmlNode( TiXmlNode::TINYXML_TEXT ) { copy.CopyTo( this ); }
void operator=( const TiXmlText& base ) { base.CopyTo( this ); }
// Write this text object to a FILE stream.
@@ -1252,7 +1283,7 @@ class TiXmlDeclaration : public TiXmlNode
{
public:
/// Construct an empty declaration.
TiXmlDeclaration() : TiXmlNode( TiXmlNode::DECLARATION ) {}
TiXmlDeclaration() : TiXmlNode( TiXmlNode::TINYXML_DECLARATION ) {}
#ifdef TIXML_USE_STL
/// Constructor.
@@ -1320,10 +1351,10 @@ private:
class TiXmlUnknown : public TiXmlNode
{
public:
TiXmlUnknown() : TiXmlNode( TiXmlNode::UNKNOWN ) {}
TiXmlUnknown() : TiXmlNode( TiXmlNode::TINYXML_UNKNOWN ) {}
virtual ~TiXmlUnknown() {}
TiXmlUnknown( const TiXmlUnknown& copy ) : TiXmlNode( TiXmlNode::UNKNOWN ) { copy.CopyTo( this ); }
TiXmlUnknown( const TiXmlUnknown& copy ) : TiXmlNode( TiXmlNode::TINYXML_UNKNOWN ) { copy.CopyTo( this ); }
void operator=( const TiXmlUnknown& copy ) { copy.CopyTo( this ); }
/// Creates a copy of this Unknown and returns it.
@@ -1397,14 +1428,10 @@ public:
#ifdef TIXML_USE_STL
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 );
}
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() );
}
#endif