add method for keeping track of settings that changed

actorid
scrawl 13 years ago
parent 55c984c179
commit 308df7caa8

@ -9,6 +9,7 @@ using namespace Settings;
Ogre::ConfigFile Manager::mFile = Ogre::ConfigFile(); Ogre::ConfigFile Manager::mFile = Ogre::ConfigFile();
Ogre::ConfigFile Manager::mDefaultFile = Ogre::ConfigFile(); Ogre::ConfigFile Manager::mDefaultFile = Ogre::ConfigFile();
SettingCategoryVector Manager::mChangedSettings = SettingCategoryVector();
void Manager::loadUser (const std::string& file) void Manager::loadUser (const std::string& file)
{ {
@ -77,8 +78,11 @@ void Manager::setString (const std::string& setting, const std::string& category
{ {
Ogre::ConfigFile::SettingsMultiMap::iterator i = it.current(); Ogre::ConfigFile::SettingsMultiMap::iterator i = it.current();
if ((*i).first == setting) if ((*i).first == setting && (*i).second != value)
{
mChangedSettings.push_back(std::make_pair(setting, category));
(*i).second = value; (*i).second = value;
}
it.getNext(); it.getNext();
} }
@ -98,3 +102,10 @@ void Manager::setBool (const std::string& setting, const std::string& category,
{ {
setString(setting, category, Ogre::StringConverter::toString(value)); setString(setting, category, Ogre::StringConverter::toString(value));
} }
const SettingCategoryVector Manager::apply()
{
SettingCategoryVector vec = mChangedSettings;
mChangedSettings.clear();
return vec;
}

@ -5,6 +5,7 @@
namespace Settings namespace Settings
{ {
typedef std::vector< std::pair<std::string, std::string> > SettingCategoryVector;
/// ///
/// \brief Settings management (can change during runtime) /// \brief Settings management (can change during runtime)
@ -12,9 +13,13 @@ namespace Settings
class Manager class Manager
{ {
public: public:
static Ogre::ConfigFile mFile; static Ogre::ConfigFile mFile;
static Ogre::ConfigFile mDefaultFile; static Ogre::ConfigFile mDefaultFile;
static SettingCategoryVector mChangedSettings;
///< tracks all the settings that were changed since the last apply() call
void loadDefault (const std::string& file); void loadDefault (const std::string& file);
///< load file as the default settings (can be overridden by user settings) ///< load file as the default settings (can be overridden by user settings)
@ -27,6 +32,9 @@ namespace Settings
void saveUser (const std::string& file); void saveUser (const std::string& file);
///< save user settings to file ///< save user settings to file
const SettingCategoryVector apply();
///< returns the list of changed settings and then clears it
static const int getInt (const std::string& setting, const std::string& category); static const int getInt (const std::string& setting, const std::string& category);
static const float getFloat (const std::string& setting, const std::string& category); static const float getFloat (const std::string& setting, const std::string& category);
static const std::string getString (const std::string& setting, const std::string& category); static const std::string getString (const std::string& setting, const std::string& category);

Loading…
Cancel
Save