IniFile: Handle s64/u64 values

This commit is contained in:
Lioncash
2017-02-24 22:56:33 -05:00
parent 51136681df
commit beec40f178
19 changed files with 133 additions and 40 deletions

View File

@ -2,9 +2,10 @@
// Licensed under GPLv2+
// Refer to the license.txt file included.
// see IniFile.h
#include "Common/IniFile.h"
#include <algorithm>
#include <cinttypes>
#include <cstddef>
#include <cstring>
#include <fstream>
@ -15,7 +16,6 @@
#include "Common/CommonTypes.h"
#include "Common/FileUtil.h"
#include "Common/IniFile.h"
#include "Common/StringUtil.h"
void IniFile::ParseLine(const std::string& line, std::string* keyOut, std::string* valueOut)
@ -73,6 +73,41 @@ void IniFile::Section::Set(const std::string& key, const std::vector<std::string
Set(key, temp);
}
void IniFile::Section::Set(const std::string& key, u32 newValue)
{
Set(key, StringFromFormat("0x%08x", newValue));
}
void IniFile::Section::Set(const std::string& key, u64 new_value)
{
Set(key, StringFromFormat("0x%016" PRIx64, new_value));
}
void IniFile::Section::Set(const std::string& key, float newValue)
{
Set(key, StringFromFormat("%#.9g", newValue));
}
void IniFile::Section::Set(const std::string& key, double newValue)
{
Set(key, StringFromFormat("%#.17g", newValue));
}
void IniFile::Section::Set(const std::string& key, int newValue)
{
Set(key, StringFromInt(newValue));
}
void IniFile::Section::Set(const std::string& key, s64 newValue)
{
Set(key, StringFromFormat("%" PRId64, newValue));
}
void IniFile::Section::Set(const std::string& key, bool newValue)
{
Set(key, StringFromBool(newValue));
}
bool IniFile::Section::Get(const std::string& key, std::string* value,
const std::string& defaultValue) const
{
@ -133,6 +168,18 @@ bool IniFile::Section::Get(const std::string& key, int* value, int defaultValue)
return false;
}
bool IniFile::Section::Get(const std::string& key, s64* value, s64 default_value) const
{
std::string temp;
bool retval = Get(key, &temp);
if (retval && TryParse(temp, value))
return true;
*value = default_value;
return false;
}
bool IniFile::Section::Get(const std::string& key, u32* value, u32 defaultValue) const
{
std::string temp;
@ -145,6 +192,18 @@ bool IniFile::Section::Get(const std::string& key, u32* value, u32 defaultValue)
return false;
}
bool IniFile::Section::Get(const std::string& key, u64* value, u64 default_value) const
{
std::string temp;
bool retval = Get(key, &temp);
if (retval && TryParse(temp, value))
return true;
*value = default_value;
return false;
}
bool IniFile::Section::Get(const std::string& key, bool* value, bool defaultValue) const
{
std::string temp;