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
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:
parent
59b2bf781f
commit
d93e4802c7
@ -4,9 +4,11 @@ project(
|
|||||||
VERSION 0.1.1
|
VERSION 0.1.1
|
||||||
LANGUAGES C CXX)
|
LANGUAGES C CXX)
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 11)
|
if(NOT CMAKE_CXX_STANDARD)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
set(CMAKE_CXX_STANDARD 11)
|
||||||
set(CMAKE_CXX_STANDARD_EXTENSIONS OFF)
|
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
|
# set(CMAKE_C_FLAGS "-gdwarf-3 -gstrict-dwarf") set(CMAKE_CXX_FLAGS "-gdwarf-3
|
||||||
# -gstrict-dwarf")
|
# -gstrict-dwarf")
|
||||||
|
|
||||||
@ -48,8 +50,8 @@ if(SLED_LOCATION_PATH)
|
|||||||
sled PRIVATE __SLED_LOCATION_PATH="${SLED_LOCATION_PATH}")
|
sled PRIVATE __SLED_LOCATION_PATH="${SLED_LOCATION_PATH}")
|
||||||
endif()
|
endif()
|
||||||
# add_subdirectory(3party/eigen EXCLUDE_FROM_ALL)
|
# add_subdirectory(3party/eigen EXCLUDE_FROM_ALL)
|
||||||
target_include_directories(sled PUBLIC src/ 3party/eigen 3party/inja
|
target_include_directories(sled PUBLIC src/ 3party/eigen 3party/rxcpp
|
||||||
3party/rxcpp 3party/toml11)
|
3party/nlohammn 3party/toml11)
|
||||||
target_sources(
|
target_sources(
|
||||||
sled
|
sled
|
||||||
PRIVATE src/sled/async/async.cc
|
PRIVATE src/sled/async/async.cc
|
||||||
|
@ -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::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
|
void
|
||||||
Config::AddConfigFullPath(sled::string_view path)
|
Config::AddConfigFullPath(sled::string_view path)
|
||||||
{
|
{
|
||||||
config_full_paths_.emplace_back(path.to_string());
|
config_full_paths_.emplace_back(sled::to_string(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Config::SetConfigName(sled::string_view name)
|
Config::SetConfigName(sled::string_view name)
|
||||||
{
|
{
|
||||||
config_name_ = name.to_string();
|
config_name_ = sled::to_string(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Config::AddConfigPath(sled::string_view path)
|
Config::AddConfigPath(sled::string_view path)
|
||||||
{
|
{
|
||||||
config_paths_.emplace_back(path.to_string());
|
config_paths_.emplace_back(sled::to_string(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
@ -36,7 +36,7 @@ Config::ReadInConfig()
|
|||||||
{
|
{
|
||||||
const static std::vector<std::string> extensions = {".toml"};
|
const static std::vector<std::string> extensions = {".toml"};
|
||||||
auto load_config_from = [](sled::string_view full_path, toml::value &value) {
|
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()) {
|
if (file.good()) {
|
||||||
try {
|
try {
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
@ -47,7 +47,7 @@ Config::ReadInConfig()
|
|||||||
return true;
|
return true;
|
||||||
// goto config_read_success;
|
// goto config_read_success;
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
LOGD("Failed to parse config file: {}", full_path.to_string());
|
LOGD("Failed to parse config file: {}", sled::to_string(full_path));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -126,13 +126,13 @@ Config::GetStringOr(sled::string_view key, sled::string_view def) const
|
|||||||
try {
|
try {
|
||||||
if (GetNode(key, value) && value.is_string()) { return value.as_string(); }
|
if (GetNode(key, value) && value.is_string()) { return value.as_string(); }
|
||||||
} catch (...) {}
|
} catch (...) {}
|
||||||
return def.to_string();
|
return sled::to_string(def);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Config::SetDefault(sled::string_view key, const bool &value)
|
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
|
void
|
||||||
@ -144,7 +144,7 @@ Config::SetDefault(sled::string_view key, const char *value)
|
|||||||
void
|
void
|
||||||
Config::SetDefault(sled::string_view key, const std::string &value)
|
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
|
void
|
||||||
@ -156,19 +156,19 @@ Config::SetDefault(sled::string_view key, sled::string_view value)
|
|||||||
void
|
void
|
||||||
Config::SetDefault(sled::string_view key, const int &value)
|
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
|
void
|
||||||
Config::SetDefault(sled::string_view key, const double &value)
|
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
|
void
|
||||||
Config::SetValue(sled::string_view key, const bool &value)
|
Config::SetValue(sled::string_view key, const bool &value)
|
||||||
{
|
{
|
||||||
values_.insert({key.to_string(), value});
|
values_.insert({sled::to_string(key), value});
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -181,7 +181,7 @@ void
|
|||||||
Config::SetValue(sled::string_view key, const std::string &value)
|
Config::SetValue(sled::string_view key, const std::string &value)
|
||||||
{
|
{
|
||||||
|
|
||||||
values_.insert({key.to_string(), value});
|
values_.insert({sled::to_string(key), value});
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -193,13 +193,13 @@ Config::SetValue(sled::string_view key, sled::string_view value)
|
|||||||
void
|
void
|
||||||
Config::SetValue(sled::string_view key, const int &value)
|
Config::SetValue(sled::string_view key, const int &value)
|
||||||
{
|
{
|
||||||
values_.insert({key.to_string(), value});
|
values_.insert({sled::to_string(key), value});
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Config::SetValue(sled::string_view key, const double &value)
|
Config::SetValue(sled::string_view key, const double &value)
|
||||||
{
|
{
|
||||||
values_.insert({key.to_string(), value});
|
values_.insert({sled::to_string(key), value});
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
@ -209,7 +209,7 @@ Config::GetNode(sled::string_view key, toml::value &value) const
|
|||||||
if (GetValueNode(key, value)) { return true; }
|
if (GetValueNode(key, value)) { return true; }
|
||||||
|
|
||||||
// 2. 然后从配置文件获取
|
// 2. 然后从配置文件获取
|
||||||
auto keys = StrSplit(key.to_string(), ".");
|
auto keys = StrSplit(sled::to_string(key), ".");
|
||||||
auto cur = toml_;
|
auto cur = toml_;
|
||||||
for (const auto &k : keys) {
|
for (const auto &k : keys) {
|
||||||
try {
|
try {
|
||||||
@ -228,7 +228,7 @@ Config::GetNode(sled::string_view key, toml::value &value) const
|
|||||||
bool
|
bool
|
||||||
Config::AddDefaultNode(sled::string_view key, ValueType value)
|
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) {
|
if (keys.size() == 1) {
|
||||||
auto first_key = keys[0];
|
auto first_key = keys[0];
|
||||||
switch (value.index()) {
|
switch (value.index()) {
|
||||||
@ -256,7 +256,7 @@ bool
|
|||||||
Config::GetValueNode(sled::string_view key, toml::value &value) const
|
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; }
|
if (iter == values_.end()) { return false; }
|
||||||
auto &default_value = iter->second;
|
auto &default_value = iter->second;
|
||||||
switch (default_value.index()) {
|
switch (default_value.index()) {
|
||||||
@ -281,7 +281,7 @@ Config::GetValueNode(sled::string_view key, toml::value &value) const
|
|||||||
bool
|
bool
|
||||||
Config::GetDefaultNode(sled::string_view key, toml::value &value) const
|
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; }
|
if (iter == default_values_.end()) { return false; }
|
||||||
auto &default_value = iter->second;
|
auto &default_value = iter->second;
|
||||||
switch (default_value.index()) {
|
switch (default_value.index()) {
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#include <sled/strings/utils.h>
|
#include <sled/strings/utils.h>
|
||||||
|
|
||||||
static std::string test_config_name = "config_test";
|
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")
|
TEST_SUITE("Config")
|
||||||
{
|
{
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -3,11 +3,11 @@
|
|||||||
#define SLED_SLED_H
|
#define SLED_SLED_H
|
||||||
|
|
||||||
// thrid_party
|
// thrid_party
|
||||||
#include "inja.hpp"
|
|
||||||
#include "rx.h"
|
#include "rx.h"
|
||||||
#include "sled/async/async.h"
|
#include "sled/async/async.h"
|
||||||
#include "sled/nonstd/cxxopts.h"
|
#include "sled/nonstd/cxxopts.h"
|
||||||
#include "sled/nonstd/expected.h"
|
#include "sled/nonstd/expected.h"
|
||||||
|
#include "sled/nonstd/inja.h"
|
||||||
#include "sled/nonstd/string_view.h"
|
#include "sled/nonstd/string_view.h"
|
||||||
#include "toml.hpp"
|
#include "toml.hpp"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user