new feature: Data::saveBool & Data::getBool

This commit is contained in:
Nomango 2018-02-28 19:46:03 +08:00
parent d0733b01e2
commit bca9f6f792
2 changed files with 32 additions and 6 deletions

View File

@ -11,26 +11,39 @@ void e2d::Data::saveDouble(const String & key, double value)
::WritePrivateProfileString(L"Default", key, String::toString(value), File::getDefaultSavePath());
}
void e2d::Data::saveBool(const String & key, bool value)
{
int nValue = value ? 1 : 0;
::WritePrivateProfileString(L"Default", key, String::toString(nValue), File::getDefaultSavePath());
}
void e2d::Data::saveString(const String & key, const String & value)
{
::WritePrivateProfileString(L"Default", key, value, File::getDefaultSavePath());
}
int e2d::Data::getInt(const String & key, int default)
int e2d::Data::getInt(const String & key, int defaultValue)
{
return ::GetPrivateProfileInt(L"Default", key, default, File::getDefaultSavePath());
return ::GetPrivateProfileInt(L"Default", key, defaultValue, File::getDefaultSavePath());
}
double e2d::Data::getDouble(const String & key, double default)
double e2d::Data::getDouble(const String & key, double defaultValue)
{
wchar_t temp[32] = { 0 };
::GetPrivateProfileString(L"Default", key, String::toString(default), temp, 31, File::getDefaultSavePath());
::GetPrivateProfileString(L"Default", key, String::toString(defaultValue), temp, 31, File::getDefaultSavePath());
return std::stof(temp);
}
e2d::String e2d::Data::getString(const String & key, const String & default)
bool e2d::Data::getBool(const String & key, bool defaultValue)
{
int nDefaultValue = defaultValue ? 1 : 0;
int nValue = ::GetPrivateProfileInt(L"Default", key, nDefaultValue, File::getDefaultSavePath());
return nValue != 0;
}
e2d::String e2d::Data::getString(const String & key, const String & defaultValue)
{
wchar_t temp[256] = { 0 };
::GetPrivateProfileString(L"Default", key, default, temp, 255, File::getDefaultSavePath());
::GetPrivateProfileString(L"Default", key, defaultValue, temp, 255, File::getDefaultSavePath());
return temp;
}

View File

@ -140,6 +140,12 @@ public:
double value
);
// 保存 bool 类型的值
static void saveBool(
const String & key,
bool value
);
// 保存 字符串 类型的值
static void saveString(
const String & key,
@ -160,6 +166,13 @@ public:
double defaultValue
);
// 获取 bool 类型的值
// (若不存在则返回 defaultValue 参数的值)
static bool getBool(
const String & key,
bool defaultValue
);
// 获取 字符串 类型的值
// (若不存在则返回 defaultValue 参数的值)
static String getString(