Data class adds field functions
This commit is contained in:
parent
0a80483ba6
commit
c8a499ece0
|
|
@ -2,54 +2,54 @@
|
||||||
|
|
||||||
static e2d::String s_sDefaultFileName = L"DefaultData.ini";
|
static e2d::String s_sDefaultFileName = L"DefaultData.ini";
|
||||||
|
|
||||||
void e2d::Data::saveInt(const String & key, int value, const String & fileName)
|
void e2d::Data::saveInt(const String & key, int value, const String & field)
|
||||||
{
|
{
|
||||||
::WritePrivateProfileString(L"Default", key, String::toString(value), Data::getDataFilePath(fileName));
|
::WritePrivateProfileString(field, key, String::toString(value), Data::getDataFilePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
void e2d::Data::saveDouble(const String & key, double value, const String & fileName)
|
void e2d::Data::saveDouble(const String & key, double value, const String & field)
|
||||||
{
|
{
|
||||||
::WritePrivateProfileString(L"Default", key, String::toString(value), Data::getDataFilePath(fileName));
|
::WritePrivateProfileString(field, key, String::toString(value), Data::getDataFilePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
void e2d::Data::saveBool(const String & key, bool value, const String & fileName)
|
void e2d::Data::saveBool(const String & key, bool value, const String & field)
|
||||||
{
|
{
|
||||||
const wchar_t* sValue = value ? L"1" : L"0";
|
const wchar_t* sValue = value ? L"1" : L"0";
|
||||||
::WritePrivateProfileString(L"Default", key, sValue, Data::getDataFilePath(fileName));
|
::WritePrivateProfileString(field, key, sValue, Data::getDataFilePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
void e2d::Data::saveString(const String & key, const String & value, const String & fileName)
|
void e2d::Data::saveString(const String & key, const String & value, const String & field)
|
||||||
{
|
{
|
||||||
::WritePrivateProfileString(L"Default", key, value, Data::getDataFilePath(fileName));
|
::WritePrivateProfileString(field, key, value, Data::getDataFilePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
int e2d::Data::getInt(const String & key, int defaultValue, const String & fileName)
|
int e2d::Data::getInt(const String & key, int defaultValue, const String & field)
|
||||||
{
|
{
|
||||||
return ::GetPrivateProfileInt(L"Default", key, defaultValue, Data::getDataFilePath(fileName));
|
return ::GetPrivateProfileInt(field, key, defaultValue, Data::getDataFilePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
double e2d::Data::getDouble(const String & key, double defaultValue, const String & fileName)
|
double e2d::Data::getDouble(const String & key, double defaultValue, const String & field)
|
||||||
{
|
{
|
||||||
wchar_t temp[32] = { 0 };
|
wchar_t temp[32] = { 0 };
|
||||||
::GetPrivateProfileString(L"Default", key, String::toString(defaultValue), temp, 31, Data::getDataFilePath(fileName));
|
::GetPrivateProfileString(field, key, String::toString(defaultValue), temp, 31, Data::getDataFilePath());
|
||||||
return std::stof(temp);
|
return std::stof(temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool e2d::Data::getBool(const String & key, bool defaultValue, const String & fileName)
|
bool e2d::Data::getBool(const String & key, bool defaultValue, const String & field)
|
||||||
{
|
{
|
||||||
int nDefaultValue = defaultValue ? 1 : 0;
|
int nDefaultValue = defaultValue ? 1 : 0;
|
||||||
int nValue = ::GetPrivateProfileInt(L"Default", key, nDefaultValue, Data::getDataFilePath(fileName));
|
int nValue = ::GetPrivateProfileInt(field, key, nDefaultValue, Data::getDataFilePath());
|
||||||
return nValue != 0;
|
return nValue != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
e2d::String e2d::Data::getString(const String & key, const String & defaultValue, const String & fileName)
|
e2d::String e2d::Data::getString(const String & key, const String & defaultValue, const String & field)
|
||||||
{
|
{
|
||||||
wchar_t temp[256] = { 0 };
|
wchar_t temp[256] = { 0 };
|
||||||
::GetPrivateProfileString(L"Default", key, defaultValue, temp, 255, Data::getDataFilePath(fileName));
|
::GetPrivateProfileString(field, key, defaultValue, temp, 255, Data::getDataFilePath());
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
void e2d::Data::setDataFilePath(const String & fileName)
|
void e2d::Data::setDataFileName(const String & fileName)
|
||||||
{
|
{
|
||||||
if (!fileName.isEmpty())
|
if (!fileName.isEmpty())
|
||||||
{
|
{
|
||||||
|
|
@ -58,11 +58,7 @@ void e2d::Data::setDataFilePath(const String & fileName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
e2d::String e2d::Data::getDataFilePath(const String & fileName)
|
e2d::String e2d::Data::getDataFilePath()
|
||||||
{
|
|
||||||
if (fileName.isEmpty())
|
|
||||||
{
|
{
|
||||||
return Path::getDefaultSavePath() + s_sDefaultFileName;
|
return Path::getDefaultSavePath() + s_sDefaultFileName;
|
||||||
}
|
}
|
||||||
return Path::getDefaultSavePath() + fileName + L".ini";
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -122,73 +122,71 @@ class Data
|
||||||
public:
|
public:
|
||||||
// 保存 int 类型的值
|
// 保存 int 类型的值
|
||||||
static void saveInt(
|
static void saveInt(
|
||||||
const String & key,
|
const String & key, /* 键值 */
|
||||||
int value,
|
int value, /* 数据 */
|
||||||
const String & fileName = L""
|
const String & field = L"Defalut" /* 字段名称 */
|
||||||
);
|
);
|
||||||
|
|
||||||
// 保存 double 类型的值
|
// 保存 double 类型的值
|
||||||
static void saveDouble(
|
static void saveDouble(
|
||||||
const String & key,
|
const String & key, /* 键值 */
|
||||||
double value,
|
double value, /* 数据 */
|
||||||
const String & fileName = L""
|
const String & field = L"Defalut" /* 字段名称 */
|
||||||
);
|
);
|
||||||
|
|
||||||
// 保存 bool 类型的值
|
// 保存 bool 类型的值
|
||||||
static void saveBool(
|
static void saveBool(
|
||||||
const String & key,
|
const String & key, /* 键值 */
|
||||||
bool value,
|
bool value, /* 数据 */
|
||||||
const String & fileName = L""
|
const String & field = L"Defalut" /* 字段名称 */
|
||||||
);
|
);
|
||||||
|
|
||||||
// 保存 字符串 类型的值
|
// 保存 字符串 类型的值
|
||||||
static void saveString(
|
static void saveString(
|
||||||
const String & key,
|
const String & key, /* 键值 */
|
||||||
const String & value,
|
const String & value, /* 数据 */
|
||||||
const String & fileName = L""
|
const String & field = L"Defalut" /* 字段名称 */
|
||||||
);
|
);
|
||||||
|
|
||||||
// 获取 int 类型的值
|
// 获取 int 类型的值
|
||||||
// (若不存在则返回 defaultValue 参数的值)
|
// (若不存在则返回 defaultValue 参数的值)
|
||||||
static int getInt(
|
static int getInt(
|
||||||
const String & key,
|
const String & key, /* 键值 */
|
||||||
int defaultValue,
|
int defaultValue, /* 默认值 */
|
||||||
const String & fileName = L""
|
const String & field = L"Defalut" /* 字段名称 */
|
||||||
);
|
);
|
||||||
|
|
||||||
// 获取 double 类型的值
|
// 获取 double 类型的值
|
||||||
// (若不存在则返回 defaultValue 参数的值)
|
// (若不存在则返回 defaultValue 参数的值)
|
||||||
static double getDouble(
|
static double getDouble(
|
||||||
const String & key,
|
const String & key, /* 键值 */
|
||||||
double defaultValue,
|
double defaultValue, /* 默认值 */
|
||||||
const String & fileName = L""
|
const String & field = L"Defalut" /* 字段名称 */
|
||||||
);
|
);
|
||||||
|
|
||||||
// 获取 bool 类型的值
|
// 获取 bool 类型的值
|
||||||
// (若不存在则返回 defaultValue 参数的值)
|
// (若不存在则返回 defaultValue 参数的值)
|
||||||
static bool getBool(
|
static bool getBool(
|
||||||
const String & key,
|
const String & key, /* 键值 */
|
||||||
bool defaultValue,
|
bool defaultValue, /* 默认值 */
|
||||||
const String & fileName = L""
|
const String & field = L"Defalut" /* 字段名称 */
|
||||||
);
|
);
|
||||||
|
|
||||||
// 获取 字符串 类型的值
|
// 获取 字符串 类型的值
|
||||||
// (若不存在则返回 defaultValue 参数的值)
|
// (若不存在则返回 defaultValue 参数的值)
|
||||||
static String getString(
|
static String getString(
|
||||||
const String & key,
|
const String & key, /* 键值 */
|
||||||
const String & defaultValue,
|
const String & defaultValue, /* 默认值 */
|
||||||
const String & fileName = L""
|
const String & field = L"Defalut" /* 字段名称 */
|
||||||
);
|
);
|
||||||
|
|
||||||
// 修改数据文件的默认名称
|
// 修改数据文件的名称
|
||||||
static void setDataFilePath(
|
static void setDataFileName(
|
||||||
const String & fileName
|
const String & strFileName /* 文件名称 */
|
||||||
);
|
);
|
||||||
|
|
||||||
// 获取数据文件的完整路径
|
// 获取数据文件的完整路径
|
||||||
static String getDataFilePath(
|
static String getDataFilePath();
|
||||||
const String & fileName
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue