m_Value -> base pointer
This commit is contained in:
@@ -13,10 +13,21 @@
|
||||
#include "DateTime.h"
|
||||
#include "Foreach.h"
|
||||
|
||||
XNode::XNode( const XNode &cpy ):
|
||||
m_sName( cpy.m_sName ),
|
||||
m_Value( cpy.m_Value )
|
||||
XNode::XNode()
|
||||
{
|
||||
m_pValue = new XNodeStringValue;
|
||||
}
|
||||
|
||||
XNode::XNode( const RString &sName )
|
||||
{
|
||||
m_sName = sName;
|
||||
m_pValue = new XNodeStringValue;
|
||||
}
|
||||
|
||||
XNode::XNode( const XNode &cpy ):
|
||||
m_sName( cpy.m_sName )
|
||||
{
|
||||
m_pValue = cpy.m_pValue->Copy();
|
||||
FOREACH_CONST_Attr( &cpy, pAttr )
|
||||
this->AppendAttr( pAttr->first, pAttr->second->Copy() );
|
||||
FOREACH_CONST_Child( &cpy, c )
|
||||
@@ -25,10 +36,16 @@ XNode::XNode( const XNode &cpy ):
|
||||
|
||||
XNode::~XNode()
|
||||
{
|
||||
Clear();
|
||||
Free();
|
||||
}
|
||||
|
||||
void XNode::Clear()
|
||||
{
|
||||
Free();
|
||||
m_pValue = new XNodeStringValue;
|
||||
}
|
||||
|
||||
void XNode::Free()
|
||||
{
|
||||
FOREACH_Child( this, p )
|
||||
SAFE_DELETE( p );
|
||||
|
||||
@@ -83,18 +83,18 @@ class XNode
|
||||
{
|
||||
public:
|
||||
RString m_sName; // a duplicate of the m_sName in the parent's map
|
||||
XNodeStringValue m_Value;
|
||||
XNodeValue *m_pValue;
|
||||
XNodes m_childs; // child node
|
||||
XAttrs m_attrs; // attributes
|
||||
|
||||
void SetName( const RString &sName ) { m_sName = sName; }
|
||||
const RString &GetName() const { return m_sName; }
|
||||
const RString &GetValue() const { return m_Value.m_sValue; }
|
||||
RString GetValue() const { return m_pValue->GetValue<RString>(); }
|
||||
|
||||
template <typename T>
|
||||
void GetValue( T &out ) const { m_Value.GetValue(out); }
|
||||
void GetValue( T &out ) const { m_pValue->GetValue(out); }
|
||||
template <typename T>
|
||||
void SetValue( const T val ) { m_Value.SetValue(val); }
|
||||
void SetValue( const T val ) { m_pValue->SetValue(val); }
|
||||
|
||||
// in own attribute list
|
||||
const XNodeValue *GetAttr( const RString &sAttrName ) const;
|
||||
@@ -121,14 +121,15 @@ public:
|
||||
XNodeValue *AppendAttr( const RString &sName, T value ) { XNodeValue *pVal = AppendAttr( sName ); pVal->SetValue( value ); return pVal; }
|
||||
bool RemoveAttr( const RString &sName );
|
||||
|
||||
XNode() { }
|
||||
explicit XNode( const RString &sName ) { m_sName = sName; }
|
||||
XNode();
|
||||
explicit XNode( const RString &sName );
|
||||
XNode( const XNode &cpy );
|
||||
~XNode();
|
||||
|
||||
void Clear();
|
||||
|
||||
private:
|
||||
void Free();
|
||||
XNode &operator=( const XNode &cpy ); // don't use
|
||||
};
|
||||
|
||||
|
||||
@@ -295,7 +295,7 @@ unsigned XmlFileUtil::Load( XNode *pNode, const RString &xml, RString &sErrorOut
|
||||
|
||||
// open/close tag <TAG ..> ... </TAG>
|
||||
// ^- current pointer
|
||||
if( XIsEmptyString(pNode->m_Value.m_sValue) )
|
||||
if( XIsEmptyString(pNode->m_pValue->GetValue<RString>()) )
|
||||
{
|
||||
// Text Value
|
||||
++iOffset;
|
||||
@@ -308,11 +308,13 @@ unsigned XmlFileUtil::Load( XNode *pNode, const RString &xml, RString &sErrorOut
|
||||
return string::npos;
|
||||
}
|
||||
|
||||
SetString( xml, iOffset, iEnd, &pNode->m_Value.m_sValue, true );
|
||||
RString sValue;
|
||||
SetString( xml, iOffset, iEnd, &sValue, true );
|
||||
|
||||
iOffset = iEnd;
|
||||
// TEXTVALUE reference
|
||||
ReplaceEntityText( pNode->m_Value.m_sValue, g_mapEntitiesToChars );
|
||||
ReplaceEntityText( sValue, g_mapEntitiesToChars );
|
||||
|
||||
pNode->m_pValue->SetValue( sValue );
|
||||
}
|
||||
|
||||
// generate child nodes
|
||||
@@ -371,7 +373,7 @@ unsigned XmlFileUtil::Load( XNode *pNode, const RString &xml, RString &sErrorOut
|
||||
}
|
||||
else // Alone child Tag Loaded
|
||||
{
|
||||
if( XIsEmptyString(pNode->m_Value.m_sValue) && iOffset < xml.size() && xml[iOffset] != chXMLTagOpen )
|
||||
if( XIsEmptyString(pNode->m_pValue->GetValue<RString>()) && iOffset < xml.size() && xml[iOffset] != chXMLTagOpen )
|
||||
{
|
||||
// Text Value
|
||||
unsigned iEnd = xml.find( chXMLTagOpen, iOffset );
|
||||
@@ -383,11 +385,12 @@ unsigned XmlFileUtil::Load( XNode *pNode, const RString &xml, RString &sErrorOut
|
||||
return string::npos;
|
||||
}
|
||||
|
||||
SetString( xml, iOffset, iEnd, &pNode->m_Value.m_sValue, true );
|
||||
RString sValue;
|
||||
SetString( xml, iOffset, iEnd, &sValue, true );
|
||||
|
||||
iOffset = iEnd;
|
||||
//TEXTVALUE
|
||||
ReplaceEntityText( pNode->m_Value.m_sValue, g_mapEntitiesToChars );
|
||||
ReplaceEntityText( sValue, g_mapEntitiesToChars );
|
||||
pNode->m_pValue->SetValue( sValue );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -426,7 +429,7 @@ bool GetXMLInternal( const XNode *pNode, RageFileBasic &f, bool bWriteTabs, int
|
||||
if( !GetAttrXML(f, p->first, p->second->GetValue<RString>()) )
|
||||
return false;
|
||||
|
||||
if( pNode->m_childs.empty() && pNode->m_Value.m_sValue.empty() )
|
||||
if( pNode->m_childs.empty() && pNode->m_pValue->GetValue<RString>().empty() )
|
||||
{
|
||||
// <TAG Attr1="Val1"/> alone tag
|
||||
if( f.Write("/>") == -1 )
|
||||
@@ -446,7 +449,7 @@ bool GetXMLInternal( const XNode *pNode, RageFileBasic &f, bool bWriteTabs, int
|
||||
return false;
|
||||
|
||||
// Text Value
|
||||
if( !pNode->m_Value.m_sValue.empty() )
|
||||
if( !pNode->m_pValue->GetValue<RString>().empty() )
|
||||
{
|
||||
if( !pNode->m_childs.empty() )
|
||||
{
|
||||
@@ -457,7 +460,8 @@ bool GetXMLInternal( const XNode *pNode, RageFileBasic &f, bool bWriteTabs, int
|
||||
if( f.Write("\t") == -1 )
|
||||
return false;
|
||||
}
|
||||
RString s( pNode->m_Value.m_sValue );
|
||||
RString s;
|
||||
pNode->m_pValue->GetValue( s );
|
||||
ReplaceEntityText( s, g_mapCharsToEntities );
|
||||
if( f.Write(s) == -1 )
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user