Skip to content

Commit

Permalink
Revert Settings.cpp, Settings.h
Browse files Browse the repository at this point in the history
original code is fine to use as-is
  • Loading branch information
bluestang2006 committed Mar 26, 2022
1 parent e52a7d8 commit 264fbbf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 48 deletions.
50 changes: 7 additions & 43 deletions es-core/src/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include <vector>

Settings* Settings::sInstance = NULL;
static std::string mEmptyString = "";

// these values are NOT saved to es_settings.xml
// since they're set through command-line arguments, and not the in-program settings menu
Expand Down Expand Up @@ -279,55 +278,20 @@ void Settings::processBackwardCompatibility()


//Print a warning message if the setting we're trying to get doesn't already exist in the map, then return the value in the map.
#define SETTINGS_GETSET(type, mapName, getMethodName, setMethodName, defaultValue) type Settings::getMethodName(const std::string& name) \
#define SETTINGS_GETSET(type, mapName, getMethodName, setMethodName) type Settings::getMethodName(const std::string& name) \
{ \
if(mapName.find(name) == mapName.cend()) \
{ \
/* LOG(LogError) << "Tried to use unset setting " << name << "!"; */ \
return defaultValue; \
LOG(LogError) << "Tried to use unset setting " << name << "!"; \
} \
return mapName[name]; \
} \
bool Settings::setMethodName(const std::string& name, type value) \
void Settings::setMethodName(const std::string& name, type value) \
{ \
if(mapName.count(name) == 0 || mapName[name] != value) { \
mapName[name] = value; \
\
if(std::find(settings_dont_save.cbegin(), settings_dont_save.cend(), name) == settings_dont_save.cend()) \
mWasChanged = true; \
\
return true; \
} \
return false; \
}

SETTINGS_GETSET(bool, mBoolMap, getBool, setBool, false);
SETTINGS_GETSET(int, mIntMap, getInt, setInt, 0);
SETTINGS_GETSET(float, mFloatMap, getFloat, setFloat, 0.0f);


std::string Settings::getString(const std::string& name)
{
if(mStringMap.find(name) == mStringMap.cend())
return mEmptyString;

return mStringMap[name];
}

bool Settings::setString(const std::string& name, const std::string& value)
{
if(mStringMap.count(name) == 0 || mStringMap[name] != value)
{
if(value == "" && mStringMap.count(name) == 0)
return false;

mStringMap[name] = value;

if(std::find(settings_dont_save.cbegin(), settings_dont_save.cend(), name) == settings_dont_save.cend())
mWasChanged = true;

return true;
}

return false;
}
SETTINGS_GETSET(bool, mBoolMap, getBool, setBool);
SETTINGS_GETSET(int, mIntMap, getInt, setInt);
SETTINGS_GETSET(float, mFloatMap, getFloat, setFloat);
SETTINGS_GETSET(const std::string&, mStringMap, getString, setString);
10 changes: 5 additions & 5 deletions es-core/src/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ class Settings
bool getBool(const std::string& name);
int getInt(const std::string& name);
float getFloat(const std::string& name);
std::string getString(const std::string& name);
const std::string& getString(const std::string& name);

bool setBool(const std::string& name, bool value);
bool setInt(const std::string& name, int value);
bool setFloat(const std::string& name, float value);
bool setString(const std::string& name, const std::string& value);
void setBool(const std::string& name, bool value);
void setInt(const std::string& name, int value);
void setFloat(const std::string& name, float value);
void setString(const std::string& name, const std::string& value);

std::map<std::string, std::string>& getStringMap() { return mStringMap; }

Expand Down

0 comments on commit 264fbbf

Please sign in to comment.