chore: add clang-format and pre-commit configuration

This commit is contained in:
2026-04-28 09:22:55 +08:00
parent dc3be5a4bc
commit 611a795481
62 changed files with 2166 additions and 2134 deletions

View File

@@ -1,6 +1,7 @@
#include <Cubed/config.hpp>
#include <Cubed/tools/cubed_assert.hpp>
#include <Cubed/tools/log.hpp>
#include "Cubed/config.hpp"
#include "Cubed/tools/cubed_assert.hpp"
#include "Cubed/tools/log.hpp"
#include <filesystem>
#include <fstream>
@@ -10,22 +11,16 @@ using namespace std::string_view_literals;
namespace Cubed {
Config::Config() {
load_or_create_config();
}
Config::Config() { load_or_create_config(); }
Config::~Config() {
save_to_file();
}
Config::~Config() { save_to_file(); }
Config& Config::get() {
static Config instance;
return instance;
}
toml::table& Config::table() {
return m_tbl;
}
toml::table& Config::table() { return m_tbl; }
void Config::create_config() {
static constexpr auto SOURCE = R"(
@@ -60,26 +55,25 @@ void Config::create_config() {
std::abort();
}
Logger::info("Create New Config File Success");
}
void Config::load_or_create_config() {
fs::path config_path {CONGIF_PATH};
fs::path config_path{CONGIF_PATH};
if (!fs::is_regular_file(config_path)) {
create_config();
} else try {
m_tbl = toml::parse_file(config_path.string());
} catch (const toml::parse_error& err) {
Logger::error("Load Config Error: \"{}\"", err.what());
create_config();
}
Logger::info("Load Config File Success");
} else
try {
m_tbl = toml::parse_file(config_path.string());
} catch (const toml::parse_error& err) {
Logger::error("Load Config Error: \"{}\"", err.what());
create_config();
}
Logger::info("Load Config File Success");
}
void Config::save_to_file() {
fs::path config_path {CONGIF_PATH};
fs::path config_path{CONGIF_PATH};
std::ofstream file{config_path};
file << m_tbl;
Logger::info("Save File Success");
@@ -121,4 +115,4 @@ toml::node_view<toml::node> Config::val_view(std::string_view key) {
return view;
}
}
} // namespace Cubed