pointer to attributes

This commit is contained in:
Glenn Maynard
2006-10-03 00:07:01 +00:00
parent fb6bafb208
commit 1a89ddfccd
11 changed files with 66 additions and 37 deletions
+9 -9
View File
@@ -262,17 +262,17 @@ void Actor::LoadFromNode( const RString& sDir, const XNode* pNode )
{ {
// Load Name, if any. // Load Name, if any.
const RString &sKeyName = pAttr->first; const RString &sKeyName = pAttr->first;
const XNodeValue &sValue = pAttr->second; const XNodeValue *pValue = pAttr->second;
if( sKeyName == "Name" ) SetName( sValue.GetValue<RString>() ); if( sKeyName == "Name" ) SetName( pValue->GetValue<RString>() );
else if( sKeyName == "BaseRotationX" ) SetBaseRotationX( sValue.GetValue<float>() ); else if( sKeyName == "BaseRotationX" ) SetBaseRotationX( pValue->GetValue<float>() );
else if( sKeyName == "BaseRotationY" ) SetBaseRotationY( sValue.GetValue<float>() ); else if( sKeyName == "BaseRotationY" ) SetBaseRotationY( pValue->GetValue<float>() );
else if( sKeyName == "BaseRotationZ" ) SetBaseRotationZ( sValue.GetValue<float>() ); else if( sKeyName == "BaseRotationZ" ) SetBaseRotationZ( pValue->GetValue<float>() );
else if( sKeyName == "BaseZoomX" ) SetBaseZoomX( sValue.GetValue<float>() ); else if( sKeyName == "BaseZoomX" ) SetBaseZoomX( pValue->GetValue<float>() );
else if( sKeyName == "BaseZoomY" ) SetBaseZoomY( sValue.GetValue<float>() ); else if( sKeyName == "BaseZoomY" ) SetBaseZoomY( pValue->GetValue<float>() );
else if( sKeyName == "BaseZoomZ" ) SetBaseZoomZ( sValue.GetValue<float>() ); else if( sKeyName == "BaseZoomZ" ) SetBaseZoomZ( pValue->GetValue<float>() );
else if( EndsWith(sKeyName,"Command") ) else if( EndsWith(sKeyName,"Command") )
{ {
apActorCommands apac = ActorUtil::ParseActorCommands( sValue.GetValue<RString>(), ssprintf("%s: %s", sDir.c_str(), sKeyName.c_str()) ); apActorCommands apac = ActorUtil::ParseActorCommands( pValue->GetValue<RString>(), ssprintf("%s: %s", sDir.c_str(), sKeyName.c_str()) );
RString sCmdName = sKeyName.Left( sKeyName.size()-7 ); RString sCmdName = sKeyName.Left( sKeyName.size()-7 );
AddCommand( sCmdName, apac ); AddCommand( sCmdName, apac );
+1 -1
View File
@@ -315,7 +315,7 @@ static void MergeActorXML( XNode *pChild, const XNode *pParent )
RString sWarning = RString sWarning =
ssprintf( "Overriding \"%s\" (\"%s\") in XML node \"%s\" with \"%s\" in XML node \"%s\"", ssprintf( "Overriding \"%s\" (\"%s\") in XML node \"%s\" with \"%s\" in XML node \"%s\"",
p->first.c_str(), p->first.c_str(),
p->second.GetValue<RString>().c_str(), p->second->GetValue<RString>().c_str(),
pChild->GetName().c_str(), pChild->GetName().c_str(),
sOld.c_str(), sOld.c_str(),
pParent->GetName().c_str() ); pParent->GetName().c_str() );
+1 -1
View File
@@ -36,7 +36,7 @@ void ExportStrings::Nsis()
FOREACH_CONST_Attr( child, attr ) FOREACH_CONST_Attr( child, attr )
{ {
RString sName = attr->first; RString sName = attr->first;
RString sValue = attr->second.GetValue<RString>(); RString sValue = attr->second->GetValue<RString>();
sValue.Replace( "\\n", "$\\n" ); sValue.Replace( "\\n", "$\\n" );
RString sLine = ssprintf( "LangString %s ${LANG_%s} \"%s\"", sName.c_str(), sLangNameUpper.c_str(), sValue.c_str() ); RString sLine = ssprintf( "LangString %s ${LANG_%s} \"%s\"", sName.c_str(), sLangNameUpper.c_str(), sValue.c_str() );
out.PutLine( sLine ); out.PutLine( sLine );
+5 -5
View File
@@ -396,14 +396,14 @@ void Font::LoadFontPageSettings( FontPageSettings &cfg, IniFile &ini, const RStr
FOREACH_CONST_Attr( pNode, pAttr ) FOREACH_CONST_Attr( pNode, pAttr )
{ {
RString sName = pAttr->first; RString sName = pAttr->first;
const XNodeValue &sValue = pAttr->second; const XNodeValue *pValue = pAttr->second;
sName.MakeUpper(); sName.MakeUpper();
/* If val is an integer, it's a width, eg. "10=27". */ /* If val is an integer, it's a width, eg. "10=27". */
if( IsAnInt(sName) ) if( IsAnInt(sName) )
{ {
cfg.m_mapGlyphWidths[atoi(sName)] = sValue.GetValue<int>(); cfg.m_mapGlyphWidths[atoi(sName)] = pValue->GetValue<int>();
continue; continue;
} }
@@ -439,7 +439,7 @@ void Font::LoadFontPageSettings( FontPageSettings &cfg, IniFile &ini, const RStr
continue; continue;
} }
cfg.CharToGlyphNo[c] = sValue.GetValue<int>(); cfg.CharToGlyphNo[c] = pValue->GetValue<int>();
continue; continue;
} }
@@ -488,7 +488,7 @@ void Font::LoadFontPageSettings( FontPageSettings &cfg, IniFile &ini, const RStr
iCount = iLast - iFirst + 1; iCount = iLast - iFirst + 1;
} }
RString sRet = cfg.MapRange( asMatches[0], iFirst, sValue.GetValue<int>(), iCount ); RString sRet = cfg.MapRange( asMatches[0], iFirst, pValue->GetValue<int>(), iCount );
if( !sRet.empty() ) if( !sRet.empty() )
RageException::Throw( "Font definition \"%s\" has an invalid range \"%s\": %s.", RageException::Throw( "Font definition \"%s\" has an invalid range \"%s\": %s.",
ini.GetPath().c_str(), sName.c_str(), sRet.c_str() ); ini.GetPath().c_str(), sName.c_str(), sRet.c_str() );
@@ -514,7 +514,7 @@ void Font::LoadFontPageSettings( FontPageSettings &cfg, IniFile &ini, const RStr
ini.GetPath().c_str(), iFirstFrame, iNumFramesHigh ); ini.GetPath().c_str(), iFirstFrame, iNumFramesHigh );
/* Decode the string. */ /* Decode the string. */
const wstring wdata( RStringToWstring(sValue.GetValue<RString>()) ); const wstring wdata( RStringToWstring(pValue->GetValue<RString>()) );
if( int(wdata.size()) > iNumFramesWide ) if( int(wdata.size()) > iNumFramesWide )
RageException::Throw( "The font definition \"%s\" assigns %i characters to row %i (\"%ls\"), but the font is only %i characters wide.", RageException::Throw( "The font definition \"%s\" assigns %i characters to row %i (\"%ls\"), but the font is only %i characters wide.",
+1 -1
View File
@@ -98,7 +98,7 @@ bool IniFile::WriteFile( RageFileBasic &f ) const
FOREACH_CONST_Attr( pKey, pAttr ) FOREACH_CONST_Attr( pKey, pAttr )
{ {
const RString &sName = pAttr->first; const RString &sName = pAttr->first;
const RString &sValue = pAttr->second.GetValue<RString>(); const RString &sValue = pAttr->second->GetValue<RString>();
// TODO: Are there esacpe rules for these? // TODO: Are there esacpe rules for these?
DEBUG_ASSERT( sName.find('\n') == sName.npos ); DEBUG_ASSERT( sName.find('\n') == sName.npos );
+1 -1
View File
@@ -562,7 +562,7 @@ void InputMapper::ReadMappingsFromDisk()
{ {
const RString &name = i->first; const RString &name = i->first;
RString value; RString value;
i->second.GetValue( value ); i->second->GetValue( value );
GameInput GameI; GameInput GameI;
GameI.FromString( m_pInputScheme, name ); GameI.FromString( m_pInputScheme, name );
+6 -6
View File
@@ -275,17 +275,17 @@ static void MergeIniUnder( XNode *pFrom, XNode *pTo )
XNode *pChildNode = pTo->GetChild( it->first ); XNode *pChildNode = pTo->GetChild( it->first );
if( pChildNode == NULL ) if( pChildNode == NULL )
{ {
/* We're moving the XNode without copying it, so don't use RemoveChild--it'll pFrom->RemoveChild( it->second, false ); // don't delete
* delete it. */
pTo->AppendChild( it->second ); pTo->AppendChild( it->second );
pFrom->m_childs.erase( it );
} }
else else
{ {
/* map::insert will not overwrite existing nodes. */
XNode *pFrom = it->second; XNode *pFrom = it->second;
FOREACHM( RString, RString, pFrom->m_attrs, it ) FOREACHM( RString, XNodeValue *, pFrom->m_attrs, it )
pChildNode->m_attrs.insert( *it ); {
/* Don't overwrite existing nodes. */
pChildNode->AppendAttr( it->first, it->second, false );
}
} }
it = next; it = next;
+1 -1
View File
@@ -50,7 +50,7 @@ void TitleTrans::LoadFromNode( const XNode* pNode )
/* Surround each regex with ^(...)$, to force all comparisons to default /* Surround each regex with ^(...)$, to force all comparisons to default
* to being a full-line match. (Add ".*" manually if this isn't wanted.) */ * to being a full-line match. (Add ".*" manually if this isn't wanted.) */
const RString &sKeyName = attr->first; const RString &sKeyName = attr->first;
const RString &sValue = attr->second.GetValue<RString>(); const RString sValue = attr->second->GetValue<RString>();
if( sKeyName == "DontTransliterate" ) translit = false; if( sKeyName == "DontTransliterate" ) translit = false;
else if( sKeyName == "TitleFrom" ) TitleFrom = "^(" + sValue + ")$"; else if( sKeyName == "TitleFrom" ) TitleFrom = "^(" + sValue + ")$";
else if( sKeyName == "ArtistFrom" ) ArtistFrom = "^(" + sValue + ")$"; else if( sKeyName == "ArtistFrom" ) ArtistFrom = "^(" + sValue + ")$";
+34 -6
View File
@@ -30,6 +30,8 @@ void XNode::Clear()
{ {
FOREACH_Child( this, p ) FOREACH_Child( this, p )
SAFE_DELETE( p ); SAFE_DELETE( p );
FOREACH_Attr( this, pAttr )
SAFE_DELETE( pAttr->second );
m_childs.clear(); m_childs.clear();
m_attrs.clear(); m_attrs.clear();
} }
@@ -51,7 +53,7 @@ const XNodeValue *XNode::GetAttr( const RString &attrname ) const
{ {
XAttrs::const_iterator it = m_attrs.find( attrname ); XAttrs::const_iterator it = m_attrs.find( attrname );
if( it != m_attrs.end() ) if( it != m_attrs.end() )
return &it->second; return it->second;
return NULL; return NULL;
} }
@@ -59,7 +61,7 @@ XNodeValue *XNode::GetAttr( const RString &attrname )
{ {
XAttrs::iterator it = m_attrs.find( attrname ); XAttrs::iterator it = m_attrs.find( attrname );
if( it != m_attrs.end() ) if( it != m_attrs.end() )
return &it->second; return it->second;
return NULL; return NULL;
} }
@@ -122,10 +124,36 @@ bool XNode::RemoveAttr( const RString &sName )
return true; return true;
} }
void XNode::AppendAttr( const RString &sName, const XNodeValue &val ) /* If bOverwrite is true and a node already exists with that name, the old value will be deleted.
* If bOverwrite is false and a node already exists with that name, the new value will be deleted. */
XNodeValue *XNode::AppendAttr( const RString &sName, XNodeValue *pValue, bool bOverwrite )
{ {
DEBUG_ASSERT( sName.size() ); DEBUG_ASSERT( sName.size() );
pair<XAttrs::iterator,bool> ret = m_attrs.insert( make_pair(sName,val) ); pair<XAttrs::iterator,bool> ret = m_attrs.insert( make_pair(sName, (XNodeValue *) NULL) );
if( !ret.second ) if( !ret.second ) // already existed
ret.first->second = val; // already existed {
if( bOverwrite )
{
delete ret.first->second;
} }
else
{
delete pValue;
pValue = ret.first->second;
}
}
ret.first->second = pValue;
return ret.first->second;
};
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();
return ret.first->second; // already existed
}
+4 -3
View File
@@ -29,7 +29,7 @@ public:
void SetValue( const DateTime &v ); void SetValue( const DateTime &v );
}; };
typedef map<RString,XNodeValue> XAttrs; typedef map<RString,XNodeValue*> XAttrs;
class XNode; class XNode;
typedef multimap<RString,XNode*> XNodes; typedef multimap<RString,XNode*> XNodes;
@@ -94,9 +94,10 @@ public:
XNode *AppendChild( XNode *node ); XNode *AppendChild( XNode *node );
bool RemoveChild( XNode *node, bool bDelete = true ); bool RemoveChild( XNode *node, bool bDelete = true );
void AppendAttr( const RString &sName, const XNodeValue &val ); XNodeValue *AppendAttr( const RString &sName, XNodeValue *pValue, bool bOverwrite = true );
XNodeValue *AppendAttr( const RString &sName );
template <typename T> template <typename T>
void AppendAttr( const RString &sName, T value ) { XNodeValue val; val.SetValue( value ); AppendAttr( sName, val ); } 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() { }
+3 -3
View File
@@ -150,8 +150,8 @@ unsigned LoadAttributes( XNode *pNode, const RString &xml, RString &sErrorOut, u
// add new attribute // add new attribute
DEBUG_ASSERT( sName.size() ); DEBUG_ASSERT( sName.size() );
pair<XAttrs::iterator,bool> it = pNode->m_attrs.insert( make_pair(sName, XNodeValue()) ); pair<XAttrs::iterator,bool> it = pNode->m_attrs.insert( make_pair(sName, new XNodeValue()) );
RString &sValue = it.first->second.m_sValue; RString &sValue = it.first->second->m_sValue;
iOffset = iEnd; iOffset = iEnd;
// XML Attr Value // XML Attr Value
@@ -423,7 +423,7 @@ bool GetXMLInternal( const XNode *pNode, RageFileBasic &f, bool bWriteTabs, int
if( f.Write(" ") == -1 ) if( f.Write(" ") == -1 )
return false; return false;
FOREACH_CONST_Attr( pNode, p ) FOREACH_CONST_Attr( pNode, p )
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_Value.m_sValue.empty() )