From b22b7972aa4a2ec13285809e61c6f10dc7033b9c Mon Sep 17 00:00:00 2001 From: Steve Checkoway Date: Sun, 1 Oct 2006 14:24:19 +0000 Subject: [PATCH] Simplify. --- stepmania/src/XmlFile.cpp | 2 +- stepmania/src/XmlFile.h | 24 +++++++++--------------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/stepmania/src/XmlFile.cpp b/stepmania/src/XmlFile.cpp index 74c610167c..8062eb4082 100644 --- a/stepmania/src/XmlFile.cpp +++ b/stepmania/src/XmlFile.cpp @@ -498,7 +498,7 @@ void XNode::GetValue( RString &out ) const { out = m_sValue; } void XNode::GetValue( int &out ) const { out = atoi(m_sValue); } void XNode::GetValue( float &out ) const { out = StringToFloat(m_sValue); } void XNode::GetValue( bool &out ) const { out = atoi(m_sValue) != 0; } -void XNode::GetValue( unsigned &out ) const { out = 0; sscanf(m_sValue,"%u",&out); } +void XNode::GetValue( unsigned &out ) const { out = strtoul(m_sValue,NULL,0); } void XNode::GetValue( DateTime &out ) const { out.FromString( m_sValue ); } bool XNode::GetAttrValue( const RString &sName, RString &out ) const { const RString* pAttr=GetAttr(sName); if(pAttr==NULL) return false; out = *pAttr; return true; } diff --git a/stepmania/src/XmlFile.h b/stepmania/src/XmlFile.h index 5e59a5fc7a..b822c77922 100644 --- a/stepmania/src/XmlFile.h +++ b/stepmania/src/XmlFile.h @@ -77,25 +77,19 @@ public: bool GetAttrValue( const RString &sName, DateTime &out ) const; // in one level child nodes - const XNode *GetChild( const RString &sName ) const; - XNode *GetChild( const RString &sName ); - bool GetChildValue( const RString &sName, RString &out ) const { const XNode* pChild=GetChild(sName); if(pChild==NULL) return false; pChild->GetValue(out); return true; } - bool GetChildValue( const RString &sName, int &out ) const { const XNode* pChild=GetChild(sName); if(pChild==NULL) return false; pChild->GetValue(out); return true; } - bool GetChildValue( const RString &sName, float &out ) const { const XNode* pChild=GetChild(sName); if(pChild==NULL) return false; pChild->GetValue(out); return true; } - bool GetChildValue( const RString &sName, bool &out ) const { const XNode* pChild=GetChild(sName); if(pChild==NULL) return false; pChild->GetValue(out); return true; } - bool GetChildValue( const RString &sName, unsigned &out ) const { const XNode* pChild=GetChild(sName); if(pChild==NULL) return false; pChild->GetValue(out); return true; } - bool GetChildValue( const RString &sName, DateTime &out ) const { const XNode* pChild=GetChild(sName); if(pChild==NULL) return false; pChild->GetValue(out); return true; } + const XNode *GetChild( const RString &sName ) const; + XNode *GetChild( const RString &sName ); + template + bool GetChildValue( const RString &sName, T &out ) const { const XNode *pChild=GetChild(sName); if(pChild==NULL) return false; pChild->GetValue(out); return true; } - // modify DOM - XNode *AppendChild( const RString &sName = RString(), const RString &value = RString() ); - XNode *AppendChild( const RString &sName, float value ); - XNode *AppendChild( const RString &sName, int value ); - XNode *AppendChild( const RString &sName, unsigned value ); - XNode *AppendChild( const RString &sName, const DateTime &value ); + // modify DOM + template + XNode *AppendChild( const RString &sName, T value ) { XNode *p=new XNode; p->m_sName=sName; p->SetValue(value); return AppendChild(p); } + XNode *AppendChild( const RString &sName ) { XNode *p=new XNode; p->m_sName=sName; return AppendChild(p); } XNode *AppendChild( XNode *node ); bool RemoveChild( XNode *node ); - void AppendAttr( const RString &sName = RString(), const RString &sValue = RString() ); + void AppendAttr( const RString &sName, const RString &sValue = RString() ); void AppendAttr( const RString &sName, float value ); void AppendAttr( const RString &sName, int value ); void AppendAttr( const RString &sName, unsigned value );