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