mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-10-26 14:00:22 +00:00
switch boost variant for std::variant for settings, for sol2
This commit is contained in:
3 files changed
+11
-10
No files matched your search
+2
-1
@@ -28,6 +28,7 @@ namespace fs = std::filesystem;
|
|||||||
#include <boost/variant.hpp>
|
#include <boost/variant.hpp>
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
#include <variant>
|
||||||
|
|
||||||
using TimeType = std::chrono::system_clock;
|
using TimeType = std::chrono::system_clock;
|
||||||
|
|
||||||
@@ -84,7 +85,7 @@ class Application final {
|
|||||||
public:
|
public:
|
||||||
// types
|
// types
|
||||||
|
|
||||||
using SettingValue = variant<std::string, bool, int>;
|
using SettingValue = std::variant<std::string, bool, int>;
|
||||||
using SettingsMap = flat_map<std::string_view, SettingValue>;
|
using SettingsMap = flat_map<std::string_view, SettingValue>;
|
||||||
|
|
||||||
static SettingsMap mSettings;
|
static SettingsMap mSettings;
|
||||||
|
|||||||
+8
-8
@@ -41,13 +41,13 @@ Application::SettingsMap Application::mSettings = {
|
|||||||
TSentry Sentry {};
|
TSentry Sentry {};
|
||||||
|
|
||||||
std::string Application::SettingToString(const Application::SettingValue& Value) {
|
std::string Application::SettingToString(const Application::SettingValue& Value) {
|
||||||
switch (Value.which()) {
|
switch (Value.index()) {
|
||||||
case 0:
|
case 0:
|
||||||
return fmt::format("{}", boost::get<std::string>(Value));
|
return fmt::format("{}", std::get<std::string>(Value));
|
||||||
case 1:
|
case 1:
|
||||||
return fmt::format("{}", boost::get<bool>(Value));
|
return fmt::format("{}", std::get<bool>(Value));
|
||||||
case 2:
|
case 2:
|
||||||
return fmt::format("{}", boost::get<int>(Value));
|
return fmt::format("{}", std::get<int>(Value));
|
||||||
default:
|
default:
|
||||||
return "<unknown type>";
|
return "<unknown type>";
|
||||||
}
|
}
|
||||||
@@ -55,7 +55,7 @@ std::string Application::SettingToString(const Application::SettingValue& Value)
|
|||||||
|
|
||||||
std::string Application::GetSettingString(std::string_view Name) {
|
std::string Application::GetSettingString(std::string_view Name) {
|
||||||
try {
|
try {
|
||||||
return boost::get<std::string>(Application::mSettings.at(Name));
|
return std::get<std::string>(Application::mSettings.at(Name));
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
beammp_errorf("Failed to get string setting '{}': {}", Name, e.what());
|
beammp_errorf("Failed to get string setting '{}': {}", Name, e.what());
|
||||||
return "";
|
return "";
|
||||||
@@ -64,7 +64,7 @@ std::string Application::GetSettingString(std::string_view Name) {
|
|||||||
|
|
||||||
int Application::GetSettingInt(std::string_view Name) {
|
int Application::GetSettingInt(std::string_view Name) {
|
||||||
try {
|
try {
|
||||||
return boost::get<int>(Application::mSettings.at(Name));
|
return std::get<int>(Application::mSettings.at(Name));
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
beammp_errorf("Failed to get int setting '{}': {}", Name, e.what());
|
beammp_errorf("Failed to get int setting '{}': {}", Name, e.what());
|
||||||
return 0;
|
return 0;
|
||||||
@@ -73,7 +73,7 @@ int Application::GetSettingInt(std::string_view Name) {
|
|||||||
|
|
||||||
bool Application::GetSettingBool(std::string_view Name) {
|
bool Application::GetSettingBool(std::string_view Name) {
|
||||||
try {
|
try {
|
||||||
return boost::get<bool>(Application::mSettings.at(Name));
|
return std::get<bool>(Application::mSettings.at(Name));
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
beammp_errorf("Failed to get bool setting '{}': {}", Name, e.what());
|
beammp_errorf("Failed to get bool setting '{}': {}", Name, e.what());
|
||||||
return false;
|
return false;
|
||||||
@@ -82,7 +82,7 @@ bool Application::GetSettingBool(std::string_view Name) {
|
|||||||
|
|
||||||
void Application::SetSetting(std::string_view Name, const Application::SettingValue& Value) {
|
void Application::SetSetting(std::string_view Name, const Application::SettingValue& Value) {
|
||||||
if (mSettings.contains(Name)) {
|
if (mSettings.contains(Name)) {
|
||||||
if (mSettings[Name].type() == Value.type()) {
|
if (mSettings[Name].index() == Value.index()) {
|
||||||
mSettings[Name] = Value;
|
mSettings[Name] = Value;
|
||||||
} else {
|
} else {
|
||||||
beammp_errorf("Could not change value of setting '{}', because it has a different type.", Name);
|
beammp_errorf("Could not change value of setting '{}', because it has a different type.", Name);
|
||||||
|
|||||||
+1
-1
@@ -191,7 +191,7 @@ void TConfig::ParseFromFile(std::string_view name) {
|
|||||||
void TConfig::PrintDebug() {
|
void TConfig::PrintDebug() {
|
||||||
for (const auto& [k, v] : Application::mSettings) {
|
for (const auto& [k, v] : Application::mSettings) {
|
||||||
if (k == StrAuthKey) {
|
if (k == StrAuthKey) {
|
||||||
beammp_debugf("AuthKey: length {}", boost::get<std::string>(v).size());
|
beammp_debugf("AuthKey: length {}", std::get<std::string>(v).size());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
beammp_debugf("{}: {}", k, Application::SettingToString(v));
|
beammp_debugf("{}: {}", k, Application::SettingToString(v));
|
||||||
|
|||||||
Reference in new issue
Block a user