mirror of
https://github.com/FEX-Emu/FEX.git
synced 2026-10-07 21:00:18 +02:00
Instead of keeping the vlaue as a string array in the MetaLayer, convert the value to its final type once. Improves performance in some hotpaths that were doing config based string conversion in a relatively high frequency.
77 lines
1.8 KiB
C++
77 lines
1.8 KiB
C++
// SPDX-License-Identifier: MIT
|
|
#pragma once
|
|
#include <FEXCore/fextl/string.h>
|
|
|
|
#include <cstdint>
|
|
#include <string_view>
|
|
#include <optional>
|
|
|
|
namespace FEXCore::StrConv {
|
|
[[maybe_unused]]
|
|
static bool Conv(std::string_view Value, bool* Result) {
|
|
*Result = std::strtoull(Value.data(), nullptr, 0);
|
|
return true;
|
|
}
|
|
|
|
[[maybe_unused]]
|
|
static bool Conv(std::string_view Value, uint8_t* Result) {
|
|
*Result = std::strtoul(Value.data(), nullptr, 0);
|
|
return true;
|
|
}
|
|
|
|
[[maybe_unused]]
|
|
static bool Conv(std::string_view Value, int8_t* Result) {
|
|
*Result = std::strtol(Value.data(), nullptr, 0);
|
|
return true;
|
|
}
|
|
|
|
[[maybe_unused]]
|
|
static bool Conv(std::string_view Value, uint16_t* Result) {
|
|
*Result = std::strtoul(Value.data(), nullptr, 0);
|
|
return true;
|
|
}
|
|
|
|
[[maybe_unused]]
|
|
static bool Conv(std::string_view Value, int16_t* Result) {
|
|
*Result = std::strtol(Value.data(), nullptr, 0);
|
|
return true;
|
|
}
|
|
|
|
[[maybe_unused]]
|
|
static bool Conv(std::string_view Value, uint32_t* Result) {
|
|
*Result = std::strtoul(Value.data(), nullptr, 0);
|
|
return true;
|
|
}
|
|
|
|
[[maybe_unused]]
|
|
static bool Conv(std::string_view Value, int32_t* Result) {
|
|
*Result = std::strtol(Value.data(), nullptr, 0);
|
|
return true;
|
|
}
|
|
|
|
[[maybe_unused]]
|
|
static bool Conv(std::string_view Value, uint64_t* Result) {
|
|
*Result = std::strtoull(Value.data(), nullptr, 0);
|
|
return true;
|
|
}
|
|
|
|
[[maybe_unused]]
|
|
static bool Conv(std::string_view Value, int64_t* Result) {
|
|
*Result = std::strtoll(Value.data(), nullptr, 0);
|
|
return true;
|
|
}
|
|
|
|
template<typename T, typename = std::enable_if<std::is_enum<T>::value, T>>
|
|
[[maybe_unused]]
|
|
static bool Conv(std::string_view Value, T* Result) {
|
|
*Result = static_cast<T>(std::stoull(Value.data(), nullptr, 0));
|
|
return true;
|
|
}
|
|
|
|
[[maybe_unused]]
|
|
static bool Conv(std::string_view Value, fextl::string* Result) {
|
|
*Result = Value;
|
|
return true;
|
|
}
|
|
} // namespace FEXCore::StrConv
|