move MergeIniUnder to XmlFileUtil

This commit is contained in:
Glenn Maynard
2007-02-04 04:09:53 +00:00
parent 2a912202ad
commit 2d5cbe6535
3 changed files with 38 additions and 35 deletions
+3 -35
View File
@@ -23,6 +23,7 @@
#include "SpecialFiles.h" #include "SpecialFiles.h"
#include "EnumHelper.h" #include "EnumHelper.h"
#include "PrefsManager.h" #include "PrefsManager.h"
#include "XmlFileUtil.h"
ThemeManager* THEME = NULL; // global object accessable from anywhere in the program ThemeManager* THEME = NULL; // global object accessable from anywhere in the program
@@ -258,39 +259,6 @@ bool ThemeManager::DoesLanguageExist( const RString &sLanguage )
return false; return false;
} }
/* Move nodes from pFrom into pTo which don't already exist in pTo. For
* efficiency, nodes will be moved, not copied, so pFrom will be modified.
* On return, the contents of pFrom will be undefined and should be deleted. */
static void MergeIniUnder( XNode *pFrom, XNode *pTo )
{
/* Iterate over each section in pFrom. */
XNodes::iterator it = pFrom->m_childs.begin();
while( it != pFrom->m_childs.end() )
{
XNodes::iterator next = it;
++next;
/* If this node doesn't exist in pTo, just move the whole node. */
XNode *pChildNode = pTo->GetChild( it->first );
XNode *pSectionNode = it->second;
if( pChildNode == NULL )
{
pFrom->RemoveChild( pSectionNode, false ); // don't delete
pTo->AppendChild( pSectionNode );
}
else
{
FOREACHM( RString, XNodeValue *, pSectionNode->m_attrs, it2 )
{
/* Don't overwrite existing nodes. */
pChildNode->AppendAttrFrom( it2->first, it2->second->Copy(), false );
}
}
it = next;
}
}
void ThemeManager::LoadThemeMetrics( deque<Theme> &theme, const RString &sThemeName_, const RString &sLanguage_ ) void ThemeManager::LoadThemeMetrics( deque<Theme> &theme, const RString &sThemeName_, const RString &sLanguage_ )
{ {
if( g_pLoadedThemeData == NULL ) if( g_pLoadedThemeData == NULL )
@@ -343,8 +311,8 @@ void ThemeManager::LoadThemeMetrics( deque<Theme> &theme, const RString &sThemeN
* need to load the derived theme first, to find out the name of the fallback * need to load the derived theme first, to find out the name of the fallback
* theme. Avoid having to load IniFile twice, merging the fallback theme * theme. Avoid having to load IniFile twice, merging the fallback theme
* into the derived theme that we've already loaded. */ * into the derived theme that we've already loaded. */
MergeIniUnder( &iniMetrics, &g_pLoadedThemeData->iniMetrics ); XmlFileUtil::MergeIniUnder( &iniMetrics, &g_pLoadedThemeData->iniMetrics );
MergeIniUnder( &iniStrings, &g_pLoadedThemeData->iniStrings ); XmlFileUtil::MergeIniUnder( &iniStrings, &g_pLoadedThemeData->iniStrings );
if( sFallback.empty() ) if( sFallback.empty() )
break; break;
+33
View File
@@ -733,6 +733,39 @@ XNode *XmlFileUtil::XNodeFromTable( lua_State *L )
return XNodeFromTableRecursive( L, "Layer", ProcessedTables ); return XNodeFromTableRecursive( L, "Layer", ProcessedTables );
} }
/* Move nodes from pFrom into pTo which don't already exist in pTo. For
* efficiency, nodes will be moved, not copied, so pFrom will be modified.
* On return, the contents of pFrom will be undefined and should be deleted. */
void XmlFileUtil::MergeIniUnder( XNode *pFrom, XNode *pTo )
{
/* Iterate over each section in pFrom. */
XNodes::iterator it = pFrom->m_childs.begin();
while( it != pFrom->m_childs.end() )
{
XNodes::iterator next = it;
++next;
/* If this node doesn't exist in pTo, just move the whole node. */
XNode *pChildNode = pTo->GetChild( it->first );
XNode *pSectionNode = it->second;
if( pChildNode == NULL )
{
pFrom->RemoveChild( pSectionNode, false ); // don't delete
pTo->AppendChild( pSectionNode );
}
else
{
FOREACHM( RString, XNodeValue *, pSectionNode->m_attrs, it2 )
{
/* Don't overwrite existing nodes. */
pChildNode->AppendAttrFrom( it2->first, it2->second->Copy(), false );
}
}
it = next;
}
}
/* /*
* (c) 2001-2006 Chris Danford, Glenn Maynard * (c) 2001-2006 Chris Danford, Glenn Maynard
* All rights reserved. * All rights reserved.
+2
View File
@@ -21,6 +21,8 @@ namespace XmlFileUtil
void CompileXNodeTree( XNode *pNode, const RString &sFile ); void CompileXNodeTree( XNode *pNode, const RString &sFile );
XNode *XNodeFromTable( lua_State *L ); XNode *XNodeFromTable( lua_State *L );
void MergeIniUnder( XNode *pFrom, XNode *pTo );
} }
#endif #endif