XNodeValue base class, Copy()
This commit is contained in:
@@ -321,7 +321,7 @@ static void MergeActorXML( XNode *pChild, const XNode *pParent )
|
||||
pParent->GetName().c_str() );
|
||||
Dialog::OK( sWarning, "XML_ATTRIB_OVERRIDE" );
|
||||
}
|
||||
pChild->AppendAttr( p->first, new XNodeValue(*p->second) );
|
||||
pChild->AppendAttr( p->first, p->second->Copy() );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -284,7 +284,7 @@ static void MergeIniUnder( XNode *pFrom, XNode *pTo )
|
||||
FOREACHM( RString, XNodeValue *, pSectionNode->m_attrs, it2 )
|
||||
{
|
||||
/* Don't overwrite existing nodes. */
|
||||
pChildNode->AppendAttr( it2->first, new XNodeValue(*it2->second), false );
|
||||
pChildNode->AppendAttr( it2->first, it2->second->Copy(), false );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+11
-11
@@ -18,7 +18,7 @@ XNode::XNode( const XNode &cpy ):
|
||||
m_Value( cpy.m_Value )
|
||||
{
|
||||
FOREACH_CONST_Attr( &cpy, pAttr )
|
||||
this->AppendAttr( pAttr->first, new XNodeValue(*pAttr->second) );
|
||||
this->AppendAttr( pAttr->first, pAttr->second->Copy() );
|
||||
FOREACH_CONST_Child( &cpy, c )
|
||||
this->AppendChild( new XNode(*c) );
|
||||
}
|
||||
@@ -38,16 +38,16 @@ void XNode::Clear()
|
||||
m_attrs.clear();
|
||||
}
|
||||
|
||||
void XNodeValue::GetValue( RString &out ) const { out = m_sValue; }
|
||||
void XNodeValue::GetValue( int &out ) const { out = atoi(m_sValue); }
|
||||
void XNodeValue::GetValue( float &out ) const { out = StringToFloat(m_sValue); }
|
||||
void XNodeValue::GetValue( bool &out ) const { out = atoi(m_sValue) != 0; }
|
||||
void XNodeValue::GetValue( unsigned &out ) const { out = strtoul(m_sValue,NULL,0); }
|
||||
void XNodeStringValue::GetValue( RString &out ) const { out = m_sValue; }
|
||||
void XNodeStringValue::GetValue( int &out ) const { out = atoi(m_sValue); }
|
||||
void XNodeStringValue::GetValue( float &out ) const { out = StringToFloat(m_sValue); }
|
||||
void XNodeStringValue::GetValue( bool &out ) const { out = atoi(m_sValue) != 0; }
|
||||
void XNodeStringValue::GetValue( unsigned &out ) const { out = strtoul(m_sValue,NULL,0); }
|
||||
|
||||
void XNodeValue::SetValue( const RString &v ) { m_sValue = v; }
|
||||
void XNodeValue::SetValue( int v ) { m_sValue = ssprintf("%d",v); }
|
||||
void XNodeValue::SetValue( float v ) { m_sValue = ssprintf("%f",v); }
|
||||
void XNodeValue::SetValue( unsigned v ) { m_sValue = ssprintf("%u",v); }
|
||||
void XNodeStringValue::SetValue( const RString &v ) { m_sValue = v; }
|
||||
void XNodeStringValue::SetValue( int v ) { m_sValue = ssprintf("%d",v); }
|
||||
void XNodeStringValue::SetValue( float v ) { m_sValue = ssprintf("%f",v); }
|
||||
void XNodeStringValue::SetValue( unsigned v ) { m_sValue = ssprintf("%u",v); }
|
||||
|
||||
const XNodeValue *XNode::GetAttr( const RString &attrname ) const
|
||||
{
|
||||
@@ -153,7 +153,7 @@ XNodeValue *XNode::AppendAttr( const RString &sName )
|
||||
DEBUG_ASSERT( sName.size() );
|
||||
pair<XAttrs::iterator,bool> ret = m_attrs.insert( make_pair(sName, (XNodeValue *) NULL) );
|
||||
if( ret.second )
|
||||
ret.first->second = new XNodeValue();
|
||||
ret.first->second = new XNodeStringValue;
|
||||
return ret.first->second; // already existed
|
||||
}
|
||||
|
||||
|
||||
+24
-1
@@ -9,9 +9,32 @@ class RageFileBasic;
|
||||
|
||||
class XNodeValue
|
||||
{
|
||||
public:
|
||||
virtual ~XNodeValue() { }
|
||||
virtual XNodeValue *Copy() const = 0;
|
||||
|
||||
virtual void GetValue( RString &out ) const = 0;
|
||||
virtual void GetValue( int &out ) const = 0;
|
||||
virtual void GetValue( float &out ) const = 0;
|
||||
virtual void GetValue( bool &out ) const = 0;
|
||||
virtual void GetValue( unsigned &out ) const = 0;
|
||||
|
||||
template<typename T>
|
||||
T GetValue() const { T val; GetValue(val); return val; }
|
||||
|
||||
virtual void SetValue( const RString &v ) = 0;
|
||||
virtual void SetValue( int v ) = 0;
|
||||
virtual void SetValue( float v ) = 0;
|
||||
virtual void SetValue( unsigned v ) = 0;
|
||||
};
|
||||
|
||||
class XNodeStringValue: public XNodeValue
|
||||
{
|
||||
public:
|
||||
RString m_sValue;
|
||||
|
||||
XNodeValue *Copy() const { return new XNodeStringValue( *this ); }
|
||||
|
||||
void GetValue( RString &out ) const;
|
||||
void GetValue( int &out ) const;
|
||||
void GetValue( float &out ) const;
|
||||
@@ -60,7 +83,7 @@ class XNode
|
||||
{
|
||||
public:
|
||||
RString m_sName; // a duplicate of the m_sName in the parent's map
|
||||
XNodeValue m_Value;
|
||||
XNodeStringValue m_Value;
|
||||
XNodes m_childs; // child node
|
||||
XAttrs m_attrs; // attributes
|
||||
|
||||
|
||||
@@ -150,8 +150,7 @@ unsigned LoadAttributes( XNode *pNode, const RString &xml, RString &sErrorOut, u
|
||||
|
||||
// add new attribute
|
||||
DEBUG_ASSERT( sName.size() );
|
||||
pair<XAttrs::iterator,bool> it = pNode->m_attrs.insert( make_pair(sName, new XNodeValue()) );
|
||||
RString &sValue = it.first->second->m_sValue;
|
||||
XNodeValue *pAttr = pNode->AppendAttr( sName );
|
||||
iOffset = iEnd;
|
||||
|
||||
// XML Attr Value
|
||||
@@ -188,9 +187,10 @@ unsigned LoadAttributes( XNode *pNode, const RString &xml, RString &sErrorOut, u
|
||||
return string::npos;
|
||||
}
|
||||
|
||||
RString sValue;
|
||||
SetString( xml, iOffset, iEnd, &sValue, true );
|
||||
pAttr->SetValue( sValue );
|
||||
iOffset = iEnd;
|
||||
// ATTRVALUE
|
||||
ReplaceEntityText( sValue, g_mapEntitiesToChars );
|
||||
|
||||
if( quote == '"' || quote == '\'' )
|
||||
|
||||
Reference in New Issue
Block a user