I have color attributes specified in hex and felt like the best place to handle them that would be in TinyXML rather than my app, so added TiXmlElement::QueryHexAttribute and TiXmlAttribute::QueryHexValue in the same form as QueryIntAttribute and QueryIntValue.
Looking at what I did, thinking now I should have made template functions along the lines of:
@@ -830,6 +836,7 @@
which is the opposite of almost all other TinyXml calls.
*/
int QueryIntValue( int* _value ) const;
+ int QueryHexValue( int* _value ) const;
/// QueryDoubleValue examines the value string. See QueryIntValue().
int QueryDoubleValue( double* _value ) const;
@@ -987,6 +994,7 @@
does not exist, then TIXML_NO_ATTRIBUTE is returned.
*/
int QueryIntAttribute( const char* name, int* _value ) const;
+ int QueryHexAttribute( const char* name, int* _value ) const;
/// QueryDoubleAttribute examines the attribute - see QueryIntAttribute().
int QueryDoubleAttribute( const char* name, double* _value ) const;
/// QueryFloatAttribute examines the attribute - see QueryIntAttribute().
@@ -1047,6 +1055,7 @@
const std::string* Attribute( const std::string& name, int* i ) const;
const std::string* Attribute( const std::string& name, double* d ) const;
int QueryIntAttribute( const std::string& name, int* _value ) const;
+ int QueryHexAttribute( const std::string& name, int* _value ) const;
int QueryDoubleAttribute( const std::string& name, double* _value ) const;
/// STL std::string form.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have color attributes specified in hex and felt like the best place to handle them that would be in TinyXML rather than my app, so added TiXmlElement::QueryHexAttribute and TiXmlAttribute::QueryHexValue in the same form as QueryIntAttribute and QueryIntValue.
Looking at what I did, thinking now I should have made template functions along the lines of:
template<typename T>
int TiXmlAttribute::QueryValue( T* tval, const char * scanString ) const
{
if ( TIXML_SSCANF( value.c_str(), scanString, tval ) == 1 )
return TIXML_SUCCESS;
return TIXML_WRONG_TYPE;
}
template<typename T>
int TiXmlElement::QueryAttribute( const char* name, T* tval, const char * scanString ) const
{
const TiXmlAttribute* node = attributeSet.Find( name );
if ( !node )
return TIXML_NO_ATTRIBUTE;
return node->QueryValue<T>( tval, scanString );
}
Oh well, here's the original non-template...
==== //appSource/MidiController/tinyxml/tinyxml.cpp#2 (text) ====
@@ -22,6 +22,12 @@
distribution.
*/
+/*
+Altered source version
+ Modified by: Sean Echevarria (www.creepingfog.com/sean) 2007.10.07
+ Added: TiXmlElement::QueryHexAttribute and TiXmlAttribute::QueryHexValue
+*/
+
#include <ctype.h>
#ifdef TIXML_USE_STL
@@ -649,6 +655,15 @@
}
+int TiXmlElement::QueryHexAttribute( const char* name, int* ival ) const
+{
+ const TiXmlAttribute* node = attributeSet.Find( name );
+ if ( !node )
+ return TIXML_NO_ATTRIBUTE;
+ return node->QueryHexValue( ival );
+}
+
+
#ifdef TIXML_USE_STL
int TiXmlElement::QueryIntAttribute( const std::string& name, int* ival ) const
{
@@ -657,6 +672,15 @@
return TIXML_NO_ATTRIBUTE;
return node->QueryIntValue( ival );
}
+
+
+int TiXmlElement::QueryHexAttribute( const std::string& name, int* ival ) const
+{
+ const TiXmlAttribute* node = attributeSet.Find( name );
+ if ( !node )
+ return TIXML_NO_ATTRIBUTE;
+ return node->QueryHexValue( ival );
+}
#endif
@@ -1244,6 +1268,13 @@
return TIXML_WRONG_TYPE;
}
+int TiXmlAttribute::QueryHexValue( int* ival ) const
+{
+ if ( TIXML_SSCANF( value.c_str(), "%x", ival ) == 1 )
+ return TIXML_SUCCESS;
+ return TIXML_WRONG_TYPE;
+}
+
int TiXmlAttribute::QueryDoubleValue( double* dval ) const
{
if ( TIXML_SSCANF( value.c_str(), "%lf", dval ) == 1 )
==== //appSource/MidiController/tinyxml/tinyxml.h#2 (text) ====
@@ -22,7 +22,13 @@
distribution.
*/
+/*
+Altered source version
+ Modified by: Sean Echevarria (www.creepingfog.com/sean) 2007.10.07
+ Added: TiXmlElement::QueryHexAttribute and TiXmlAttribute::QueryHexValue
+*/
+
#ifndef TINYXML_INCLUDED
#define TINYXML_INCLUDED
@@ -830,6 +836,7 @@
which is the opposite of almost all other TinyXml calls.
*/
int QueryIntValue( int* _value ) const;
+ int QueryHexValue( int* _value ) const;
/// QueryDoubleValue examines the value string. See QueryIntValue().
int QueryDoubleValue( double* _value ) const;
@@ -987,6 +994,7 @@
does not exist, then TIXML_NO_ATTRIBUTE is returned.
*/
int QueryIntAttribute( const char* name, int* _value ) const;
+ int QueryHexAttribute( const char* name, int* _value ) const;
/// QueryDoubleAttribute examines the attribute - see QueryIntAttribute().
int QueryDoubleAttribute( const char* name, double* _value ) const;
/// QueryFloatAttribute examines the attribute - see QueryIntAttribute().
@@ -1047,6 +1055,7 @@
const std::string* Attribute( const std::string& name, int* i ) const;
const std::string* Attribute( const std::string& name, double* d ) const;
int QueryIntAttribute( const std::string& name, int* _value ) const;
+ int QueryHexAttribute( const std::string& name, int* _value ) const;
int QueryDoubleAttribute( const std::string& name, double* _value ) const;
/// STL std::string form.