1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-01-22 23:52:10 +01:00
dxvk/src/util/config/config.cpp

86 lines
1.6 KiB
C++
Raw Normal View History

#include "config.h"
namespace dxvk {
Config::Config() { }
Config::~Config() { }
Config::Config(OptionMap&& options)
: m_options(std::move(options)) { }
void Config::merge(const Config& other) {
for (auto& pair : other.m_options)
m_options.insert(pair);
}
void Config::setOption(const std::string& key, const std::string& value) {
m_options.insert_or_assign(key, value);
}
std::string Config::getOptionValue(const char* option) const {
auto iter = m_options.find(option);
return iter != m_options.end()
? iter->second : std::string();
}
bool Config::parseOptionValue(
const std::string& value,
std::string& result) {
result = value;
return true;
}
bool Config::parseOptionValue(
const std::string& value,
bool& result) {
if (value == "True") {
result = true;
return true;
} else if (value == "False") {
result = false;
return true;
} else {
return false;
}
}
bool Config::parseOptionValue(
const std::string& value,
int32_t& result) {
if (value.size() == 0)
return false;
// Parse sign, don't allow '+'
int32_t sign = 1;
size_t start = 0;
if (value[0] == '-') {
sign = -1;
start = 1;
}
// Parse absolute number
int32_t intval = 0;
for (size_t i = start; i < value.size(); i++) {
if (value[i] < '0' || value[i] > '9')
return false;
intval *= 10;
intval += value[i] - '0';
}
// Apply sign and return
result = sign * intval;
return true;
}
}