fix config string_view
All checks were successful
linux-aarch64-cpu-gcc / linux-gcc-aarch64 (push) Successful in 1m23s
linux-mips64-gcc / linux-gcc-mips64el (Debug) (push) Successful in 1m37s
linux-x64-gcc / linux-gcc (Release) (push) Successful in 1m50s
linux-x64-gcc / linux-gcc (Debug) (push) Successful in 2m4s
linux-arm-gcc / linux-gcc-armhf (push) Successful in 2m22s
linux-mips64-gcc / linux-gcc-mips64el (Release) (push) Successful in 3m1s

This commit is contained in:
tqcq 2024-04-10 22:45:16 +08:00
parent 59b2bf781f
commit d93e4802c7
6 changed files with 985 additions and 2604 deletions

View File

@ -4,9 +4,11 @@ project(
VERSION 0.1.1
LANGUAGES C CXX)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD_EXTENSIONS OFF)
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD_EXTENSIONS OFF)
endif()
# set(CMAKE_C_FLAGS "-gdwarf-3 -gstrict-dwarf") set(CMAKE_CXX_FLAGS "-gdwarf-3
# -gstrict-dwarf")
@ -48,8 +50,8 @@ if(SLED_LOCATION_PATH)
sled PRIVATE __SLED_LOCATION_PATH="${SLED_LOCATION_PATH}")
endif()
# add_subdirectory(3party/eigen EXCLUDE_FROM_ALL)
target_include_directories(sled PUBLIC src/ 3party/eigen 3party/inja
3party/rxcpp 3party/toml11)
target_include_directories(sled PUBLIC src/ 3party/eigen 3party/rxcpp
3party/nlohammn 3party/toml11)
target_sources(
sled
PRIVATE src/sled/async/async.cc

View File

@ -10,25 +10,25 @@ Config::Config(sled::string_view name) : Config(name, "") {}
Config::Config(sled::string_view name, sled::string_view path) : config_name_(name)
{
config_paths_.emplace_back(path.to_string());
config_paths_.emplace_back(sled::to_string(path));
}
void
Config::AddConfigFullPath(sled::string_view path)
{
config_full_paths_.emplace_back(path.to_string());
config_full_paths_.emplace_back(sled::to_string(path));
}
void
Config::SetConfigName(sled::string_view name)
{
config_name_ = name.to_string();
config_name_ = sled::to_string(name);
}
void
Config::AddConfigPath(sled::string_view path)
{
config_paths_.emplace_back(path.to_string());
config_paths_.emplace_back(sled::to_string(path));
}
bool
@ -36,7 +36,7 @@ Config::ReadInConfig()
{
const static std::vector<std::string> extensions = {".toml"};
auto load_config_from = [](sled::string_view full_path, toml::value &value) {
const std::ifstream file(full_path.to_string());
const std::ifstream file(to_string(full_path));
if (file.good()) {
try {
std::stringstream ss;
@ -47,7 +47,7 @@ Config::ReadInConfig()
return true;
// goto config_read_success;
} catch (...) {
LOGD("Failed to parse config file: {}", full_path.to_string());
LOGD("Failed to parse config file: {}", sled::to_string(full_path));
}
}
return false;
@ -126,13 +126,13 @@ Config::GetStringOr(sled::string_view key, sled::string_view def) const
try {
if (GetNode(key, value) && value.is_string()) { return value.as_string(); }
} catch (...) {}
return def.to_string();
return sled::to_string(def);
}
void
Config::SetDefault(sled::string_view key, const bool &value)
{
default_values_.insert({key.to_string(), value});
default_values_.insert({sled::to_string(key), value});
}
void
@ -144,7 +144,7 @@ Config::SetDefault(sled::string_view key, const char *value)
void
Config::SetDefault(sled::string_view key, const std::string &value)
{
default_values_.insert({key.to_string(), value});
default_values_.insert({sled::to_string(key), value});
}
void
@ -156,19 +156,19 @@ Config::SetDefault(sled::string_view key, sled::string_view value)
void
Config::SetDefault(sled::string_view key, const int &value)
{
default_values_.insert({key.to_string(), value});
default_values_.insert({sled::to_string(key), value});
}
void
Config::SetDefault(sled::string_view key, const double &value)
{
default_values_.insert({key.to_string(), value});
default_values_.insert({sled::to_string(key), value});
}
void
Config::SetValue(sled::string_view key, const bool &value)
{
values_.insert({key.to_string(), value});
values_.insert({sled::to_string(key), value});
}
void
@ -181,7 +181,7 @@ void
Config::SetValue(sled::string_view key, const std::string &value)
{
values_.insert({key.to_string(), value});
values_.insert({sled::to_string(key), value});
}
void
@ -193,13 +193,13 @@ Config::SetValue(sled::string_view key, sled::string_view value)
void
Config::SetValue(sled::string_view key, const int &value)
{
values_.insert({key.to_string(), value});
values_.insert({sled::to_string(key), value});
}
void
Config::SetValue(sled::string_view key, const double &value)
{
values_.insert({key.to_string(), value});
values_.insert({sled::to_string(key), value});
}
bool
@ -209,7 +209,7 @@ Config::GetNode(sled::string_view key, toml::value &value) const
if (GetValueNode(key, value)) { return true; }
// 2. 然后从配置文件获取
auto keys = StrSplit(key.to_string(), ".");
auto keys = StrSplit(sled::to_string(key), ".");
auto cur = toml_;
for (const auto &k : keys) {
try {
@ -228,7 +228,7 @@ Config::GetNode(sled::string_view key, toml::value &value) const
bool
Config::AddDefaultNode(sled::string_view key, ValueType value)
{
auto keys = StrSplit(key.to_string(), ".");
auto keys = StrSplit(sled::to_string(key), ".");
if (keys.size() == 1) {
auto first_key = keys[0];
switch (value.index()) {
@ -256,7 +256,7 @@ bool
Config::GetValueNode(sled::string_view key, toml::value &value) const
{
auto iter = values_.find(key.to_string());
auto iter = values_.find(sled::to_string(key));
if (iter == values_.end()) { return false; }
auto &default_value = iter->second;
switch (default_value.index()) {
@ -281,7 +281,7 @@ Config::GetValueNode(sled::string_view key, toml::value &value) const
bool
Config::GetDefaultNode(sled::string_view key, toml::value &value) const
{
auto iter = default_values_.find(key.to_string());
auto iter = default_values_.find(sled::to_string(key));
if (iter == default_values_.end()) { return false; }
auto &default_value = iter->second;
switch (default_value.index()) {

View File

@ -2,7 +2,7 @@
#include <sled/strings/utils.h>
static std::string test_config_name = "config_test";
static std::string test_config_path = sled::StripSuffix(__FILE__, "config_test.cc").to_string();
static std::string test_config_path = sled::to_string(sled::StripSuffix(__FILE__, "config_test.cc"));
TEST_SUITE("Config")
{

File diff suppressed because it is too large Load Diff

View File

@ -3,11 +3,11 @@
#define SLED_SLED_H
// thrid_party
#include "inja.hpp"
#include "rx.h"
#include "sled/async/async.h"
#include "sled/nonstd/cxxopts.h"
#include "sled/nonstd/expected.h"
#include "sled/nonstd/inja.h"
#include "sled/nonstd/string_view.h"
#include "toml.hpp"