From 4c864d813b1120ee2dab561bacca4752d286d183 Mon Sep 17 00:00:00 2001 From: Jie Date: Thu, 6 Mar 2025 14:03:16 +0800 Subject: [PATCH] =?UTF-8?q?ini=E9=80=BB=E8=BE=91=20=E5=8D=A0=E4=BD=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/settings.json | 62 ++++++++++++++++++++++++++++++++++++++++++- include/ini.h | 50 ++++++++++++++++++++++++++++++++++ include/stringconv.h | 17 +++++++----- include/toolkit.h | 2 +- include/util.h | 45 +++++++++++++++---------------- 5 files changed, 144 insertions(+), 32 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 0728772..57e6b19 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,6 +1,66 @@ { "files.associations": { "*.cpp": "cpp", - "type_traits": "cpp" + "type_traits": "cpp", + "cctype": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "array": "cpp", + "atomic": "cpp", + "bit": "cpp", + "*.tcc": "cpp", + "charconv": "cpp", + "chrono": "cpp", + "compare": "cpp", + "concepts": "cpp", + "cstdint": "cpp", + "deque": "cpp", + "list": "cpp", + "string": "cpp", + "unordered_map": "cpp", + "vector": "cpp", + "exception": "cpp", + "expected": "cpp", + "algorithm": "cpp", + "functional": "cpp", + "iterator": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "optional": "cpp", + "random": "cpp", + "ratio": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "utility": "cpp", + "fstream": "cpp", + "initializer_list": "cpp", + "iomanip": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "limits": "cpp", + "new": "cpp", + "numbers": "cpp", + "ostream": "cpp", + "ranges": "cpp", + "span": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "cinttypes": "cpp", + "typeinfo": "cpp", + "variant": "cpp", + "format": "cpp", + "codecvt": "cpp" } } \ No newline at end of file diff --git a/include/ini.h b/include/ini.h index e69de29..0101982 100644 --- a/include/ini.h +++ b/include/ini.h @@ -0,0 +1,50 @@ +#ifndef INI_H +#define INI_H + +#include +#include +#include +#include +#include + +namespace fs = std::filesystem; + +namespace ini +{ + + class IniHelper + { + private: + std::fstream handle; + + public: + IniHelper() + { + auto path = (fs::current_path() / "ini.ini").string(); + std::cout << path < + inline T GetValue(const std::string §ion, const std::string &key, T &&default_value) + { + throw std::exception("Not Implemented"); + } + + template + inline bool SaveValue(const std::string §ion, const std::string &key, T &&default_value) + { + throw std::exception("Not Implemented"); + } + }; + +} + +#endif // !INI_H \ No newline at end of file diff --git a/include/stringconv.h b/include/stringconv.h index b24b9ef..165ab29 100644 --- a/include/stringconv.h +++ b/include/stringconv.h @@ -12,7 +12,8 @@ namespace ranges = std::ranges; namespace views = std::ranges::views; constexpr size_t buffer_size = 32; -namespace string{ +namespace string +{ template requires std::is_same_v || std::is_same_v inline std::string replace_string(const std::string &str, T d, T e) @@ -51,15 +52,17 @@ namespace string{ { return T(word.begin(), word.end()); }); return std::vector(v.begin(), v.end()); } - - template + + template requires std::is_same_v || std::is_same_v - double round(T value, int c){ + double round(T value, int c) + { auto temp = 1; - for(int i=0;i #include -namespace util{ - -template -inline std::expected to_string(T value) +namespace util { + + template + inline std::expected to_string(T value) + { if constexpr (std::is_same_v || std::is_same_v || std::is_same_v) { - char buffer[buffer_size]; - auto res = std::to_chars(buffer, buffer + buffer_size, value); - if (res.ec != std::errc()) - { + char buffer[buffer_size]; + auto res = std::to_chars(buffer, buffer + buffer_size, value); + if (res.ec != std::errc()) + { return std::unexpected(std::make_error_code(res.ec).message()); - } - return std::string(buffer, res.ptr - buffer); + } + return std::string(buffer, res.ptr - buffer); } else if constexpr (std::is_same_v::type, - char *>) + char *>) { - return std::to_string(value); + return std::to_string(value); } -} + } -template // requires std::is_same_v -inline std::expected stoi(const std::string &str) -{ + template // requires std::is_same_v + inline std::expected stoi(const std::string &str) + { T value; auto res = std::from_chars(str.c_str(), str.c_str() + str.size(), value); if (res.ec != std::errc()) { - return std::unexpected(std::make_error_code(res.ec).message()); + return std::unexpected(std::make_error_code(res.ec).message()); } return value; -} + } - inline std::string get_time_now(){ + inline std::string get_time_now() + { auto time_now = std::chrono::system_clock::now(); auto now_c = std::chrono::system_clock::to_time_t(time_now); char buffer[32]; @@ -52,9 +54,6 @@ inline std::expected stoi(const std::string &str) result = string::replace_string(result, "\n", ""); return std::move(result); } - } - - -#endif +#endif