diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 0a378a4..39ae825 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -6,7 +6,7 @@ jobs: ubuntu-bionic-gcc: runs-on: ubuntu-18.04 env: - CMAKE_FLAGS: '-DSERDEPP_USE_NLOHMANN_JSON=ON -DSERDEPP_USE_TOML11=ON -DSERDEPP_USE_YAML-CPP=ON -DSERDEPP_BUILD_EXAMPLES=ON -DSERDEPP_USE_RAPIDJSON=ON' + CMAKE_FLAGS: '-DSERDEPP_USE_NLOHMANN_JSON=ON -DSERDEPP_USE_TOML11=ON -DSERDEPP_USE_YAML-CPP=ON -DSERDEPP_BUILD_EXAMPLES=ON -DSERDEPP_USE_RAPIDJSON=ON -DSERDEPP_USE_FMT=ON' strategy: matrix: build-type: ['Release', 'Debug'] @@ -42,7 +42,7 @@ jobs: ubuntu-bionic-llvm: runs-on: ubuntu-18.04 env: - CMAKE_FLAGS: '-DSERDEPP_USE_NLOHMANN_JSON=ON -DSERDEPP_USE_TOML11=ON -DSERDEPP_USE_YAML-CPP=ON -DSERDEPP_BUILD_EXAMPLES=ON -DSERDEPP_USE_RAPIDJSON=ON' + CMAKE_FLAGS: '-DSERDEPP_USE_NLOHMANN_JSON=ON -DSERDEPP_USE_TOML11=ON -DSERDEPP_USE_YAML-CPP=ON -DSERDEPP_BUILD_EXAMPLES=ON -DSERDEPP_USE_RAPIDJSON=ON -DSERDEPP_USE_FMT=ON' strategy: matrix: build-type: ['Release', 'Debug'] diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 962b915..2aa03e4 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -6,7 +6,7 @@ jobs: macos-clang: runs-on: macos-latest env: - CMAKE_FLAGS: '-DSERDEPP_USE_NLOHMANN_JSON=ON -DSERDEPP_USE_TOML11=ON -DSERDEPP_USE_YAML-CPP=ON -DSERDEPP_BUILD_EXAMPLES=ON -DSERDEPP_USE_RAPIDJSON=ON' + CMAKE_FLAGS: '-DSERDEPP_USE_NLOHMANN_JSON=ON -DSERDEPP_USE_TOML11=ON -DSERDEPP_USE_YAML-CPP=ON -DSERDEPP_BUILD_EXAMPLES=ON -DSERDEPP_USE_RAPIDJSON=ON -DSERDEPP_USE_FMT=ON' strategy: matrix: build-type: ['Release', 'Debug'] diff --git a/.github/workflows/window.yml b/.github/workflows/window.yml index 1a1d693..7650d2f 100644 --- a/.github/workflows/window.yml +++ b/.github/workflows/window.yml @@ -6,7 +6,7 @@ jobs: windows-msvc: runs-on: windows-2019 env: - CMAKE_FLAGS: '-DSERDEPP_USE_NLOHMANN_JSON=ON -DSERDEPP_USE_TOML11=ON -DSERDEPP_USE_YAML-CPP=ON -DSERDEPP_BUILD_EXAMPLES=ON -DSERDEPP_USE_RAPIDJSON=ON' + CMAKE_FLAGS: '-DSERDEPP_USE_NLOHMANN_JSON=ON -DSERDEPP_USE_TOML11=ON -DSERDEPP_USE_YAML-CPP=ON -DSERDEPP_BUILD_EXAMPLES=ON -DSERDEPP_USE_RAPIDJSON=ON -DSERDEPP_USE_FMT=ON' strategy: matrix: build-type: ['Release', 'Debug'] diff --git a/CMakeLists.txt b/CMakeLists.txt index 4555ce6..05198b8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ set(CPPM_VERSION 0.0.13) include(cmake/cppm_loader.cmake) cppm_project() -project(serdepp VERSION 0.1.1 LANGUAGES C CXX) +project(serdepp VERSION 0.1.2 LANGUAGES C CXX) cppm_setting() cppm_cxx_standard(17) cppm_compiler_option(DEFAULT) @@ -12,14 +12,18 @@ cppm_compiler_option(DEFAULT) find_cppkg(benchmark 1.5.2 MODULE benchmark::benchmark TYPE lib OPTIONAL OFF) find_cppkg(RapidJSON 1.1.1 MODULE rapidjson TYPE lib OPTIONAL OFF) find_cppkg(nlohmann_json 3.9.1 MODULE nlohmann_json::nlohmann_json TYPE lib OPTIONAL OFF) +find_cppkg(ryml 0.2.0 MODULE ryml::ryml TYPE lib OPTIONAL OFF) find_cppkg(toml11 3.7.0 MODULE toml11::toml11 TYPE lib OPTIONAL OFF) find_cppkg(yaml-cpp 0.6.3 MODULE yaml-cpp TYPE lib OPTIONAL OFF) -find_cppkg(nameof 0.10.0 MODULE nameof::nameof TYPE lib) +find_cppkg(fmt 7.1.3 MODULE fmt::fmt TYPE lib OPTIONAL OFF) find_cppkg(magic_enum 0.7.3 MODULE magic_enum::magic_enum TYPE lib) -find_cppkg(fmt 7.1.3 MODULE fmt::fmt TYPE lib) +find_cppkg(nameof 0.10.0 MODULE nameof::nameof TYPE lib) -cppm_target_define(serdepp INTERFACE) +cppm_target_define(serdepp STATIC +SOURCES + src/to_static.cpp +) cppm_examples_area() if(SERDEPP_BUILD_EXAMPLES) @@ -64,6 +68,11 @@ SOURCES examples/sugar.cpp ) +cppm_target_define(print BINARY +SOURCES + examples/print.cpp +) + endif() if(SERDEPP_BUILD_BENCHMARKS) @@ -86,7 +95,7 @@ SOURCES endif() set(serdepp_global_deps PRIVATE benchmark -PUBLIC RapidJSON nlohmann_json toml11 yaml-cpp nameof magic_enum fmt) +PUBLIC RapidJSON nlohmann_json ryml toml11 yaml-cpp fmt magic_enum nameof) cppm_target_dependencies(serdepp ${serdepp_global_deps}) @@ -122,6 +131,10 @@ cppm_target_dependencies(sugar ${serdepp_global_deps} serdepp) +cppm_target_dependencies(print + ${serdepp_global_deps} + serdepp) + cppm_target_dependencies(benchmark ${serdepp_global_deps} serdepp) @@ -144,4 +157,5 @@ cppm_target_install(variant_example) cppm_target_install(parse_file_example) cppm_target_install(struct_attribute_example) cppm_target_install(sugar) +cppm_target_install(print) diff --git a/README.md b/README.md index 38b4517..99af83e 100644 --- a/README.md +++ b/README.md @@ -87,9 +87,9 @@ fmt:{"vec: {"a", "b", "c"}", "t_enum: B"} ``` ## Dependencies -- [fmt](https://github.com/fmtlib/fmt) (Auto Install) - [nameof](https://github.com/Neargye/nameof) (Auto Install) - [magic_enum](https://github.com/Neargye/magic_enum) (Auto Install) +- [fmt](https://github.com/fmtlib/fmt) (optional) (Install CMAKE FLAG: -DSERDEPP_USE_FMT=ON) - [nlohmann_json](https://github.com/nlohmann/json) (optional) (Install CMAKE FLAG: -DSERDEPP_USE_NLOHMANN_JSON=ON) - [rapidjson](https://github.com/Tencent/rapidjson) (optional) (Install CMAKE FLAG: -DSERDEPP_USE_RAPIDJSON=ON) - [toml11](https://github.com/ToruNiina/toml11) (optional) (Install CMAKE FLAG: -DSERDEPP_USE_TOML11=ON) @@ -212,7 +212,6 @@ template #include #include #include -#include using namespace serde::ostream; diff --git a/cppm.toml b/cppm.toml index 33448a3..7ba3c95 100644 --- a/cppm.toml +++ b/cppm.toml @@ -1,14 +1,14 @@ [package] name = "serdepp" - version = "0.1.1" + version = "0.1.2" description = "c++ universal serialize deserialize library like rust serde" #tool-version = "dev" [lib] name = "serdepp" - #type = "static" - #source= ["src/to_static.cpp"] - type = "header-only" + type = "static" + #type = "header-only" + source= ["src/to_static.cpp"] [[example]] @@ -43,6 +43,10 @@ name = "sugar" source = ["examples/sugar.cpp"] +[[example]] + name = "print" + source = ["examples/print.cpp"] + #[[example]] # name = "simdjson_example" # source = ["examples/simdjson.cpp"] @@ -60,11 +64,12 @@ source = ["benchmark/syntax_benchmark.cpp"] [dependencies] - fmt = {version="7.1.3", link="public"} nameof = { version="0.10.0", link="public"} magic_enum = { version= "0.7.3", link="public"} + fmt = {version="7.1.3", link="public", optional=true} yaml-cpp = { version="0.6.3", link="public", optional=true} toml11 = { version="3.7.0", link="public", optional=true} + ryml = { version= "0.2.0", link="public", optional=true} nlohmann_json = { version="3.9.1", link="public", optional=true} RapidJSON = { version="1.1.1", link="public", optional=true} benchmark = { version="1.5.2", optional=true} diff --git a/examples/example.cpp b/examples/example.cpp index c41640c..f46ae40 100644 --- a/examples/example.cpp +++ b/examples/example.cpp @@ -1,13 +1,9 @@ -#include +#include #include #include #include #include #include "serdepp/adaptor/rapidjson.hpp" -#include - -#include -#include #include using namespace serde::ostream; diff --git a/examples/example1.cpp b/examples/example1.cpp index c1dbdbd..5f351c3 100644 --- a/examples/example1.cpp +++ b/examples/example1.cpp @@ -1,5 +1,6 @@ -#include +#include #include +#include enum class t_enum { A, B }; diff --git a/examples/flatten.cpp b/examples/flatten.cpp index 75785a3..0adf0f8 100644 --- a/examples/flatten.cpp +++ b/examples/flatten.cpp @@ -1,4 +1,5 @@ -#include +#include +#include #include #include diff --git a/examples/parse_file.cpp b/examples/parse_file.cpp index 24f5e75..f54cc94 100644 --- a/examples/parse_file.cpp +++ b/examples/parse_file.cpp @@ -4,6 +4,7 @@ #include "serdepp/adaptor/rapidjson.hpp" #include "serdepp/adaptor/toml11.hpp" #include "serdepp/adaptor/yaml-cpp.hpp" +#include "serdepp/adaptor/fmt.hpp" enum class tenum { INPUT, OUTPUT, INPUT_2 , OUTPUT_2 }; @@ -55,6 +56,5 @@ int main(int argc, char *argv[]) fmt::print("{}\n",from_rpjson); fmt::print("{}\n",from_toml11); fmt::print("{}\n",from_yamlpp); - return 0; } diff --git a/examples/print.cpp b/examples/print.cpp new file mode 100644 index 0000000..0093299 --- /dev/null +++ b/examples/print.cpp @@ -0,0 +1,40 @@ + +#include +#include + +struct Object { + DERIVE_SERDE(Object, + (&Self::radius, "radius") + (&Self::width, "width") + (&Self::height, "height")) + std::optional radius; + std::optional width; + std::optional height; +}; +struct Test { + DERIVE_SERDE(Test, + (&Self::type, "type") + [attributes(flatten)] + (&Self::object, "object")) + std::string type; + Object object; +}; + +int main(int argc, char *argv[]) +{ + nlohmann::json jflat = R"([ + {"type": "circle", "radius": 5}, + {"type": "rectangle", "width": 6, "height": 5} + ])"_json; + + nlohmann::json j = R"([ + {"type": "circle", "object": {"radius" : 5}}, + {"type": "rectangle", "object": {"width": 6, "height": 5}} + ])"_json; + + auto j_flatten = serde::deserialize>(jflat); + + std::cout << serde::serialize(j_flatten).str(); + + return 0; +} diff --git a/examples/simple_example.cpp b/examples/simple_example.cpp index 9140489..f16f4c9 100644 --- a/examples/simple_example.cpp +++ b/examples/simple_example.cpp @@ -1,12 +1,9 @@ -#include +#include #include #include #include #include #include -#include - -#include using namespace serde::ostream; diff --git a/examples/struct_attribute.cpp b/examples/struct_attribute.cpp index 7813816..c5918b4 100644 --- a/examples/struct_attribute.cpp +++ b/examples/struct_attribute.cpp @@ -1,4 +1,5 @@ #include "serdepp/serde.hpp" +#include "serdepp/adaptor/fmt.hpp" namespace serde::attribute { namespace detail { diff --git a/examples/sugar.cpp b/examples/sugar.cpp index 4556465..2c26a41 100644 --- a/examples/sugar.cpp +++ b/examples/sugar.cpp @@ -1,4 +1,5 @@ #include "serdepp/serde.hpp" +#include "serdepp/adaptor/fmt.hpp" namespace serde::attribute { namespace detail { diff --git a/examples/variant.cpp b/examples/variant.cpp index 7ec7f33..d0ad88f 100644 --- a/examples/variant.cpp +++ b/examples/variant.cpp @@ -3,6 +3,7 @@ #include #include #include +#include enum class T { A, B }; diff --git a/include/serdepp/adaptor/fmt.hpp b/include/serdepp/adaptor/fmt.hpp index a7098ce..40566dc 100644 --- a/include/serdepp/adaptor/fmt.hpp +++ b/include/serdepp/adaptor/fmt.hpp @@ -3,83 +3,24 @@ #ifndef __SERDEPP_ADAPTOR_FMT_HPP__ #define __SERDEPP_ADAPTOR_FMT_HPP__ -#include -#include +#include #include - -namespace serde { - using namespace fmt::literals; - struct string_converter { - struct _element { - std::string_view id; - std::string value; - explicit _element(std::string_view id, const std::string& value) noexcept : id(id), value(value) {} - std::string to_str() const { - return id.empty() ? value : "{} : \"{}\""_format(id, value); - } - }; - std::vector<_element> iter; - template - string_converter& add(std::string_view key, const T& data) { - iter.push_back(_element(key, fmt::format("{}", data))); - return *this; - } - std::string to_str() const { return iter.size() == 1 ? fmt::format("{}", iter[0]) : fmt::format("{}", iter); } - }; - - template<> struct serde_adaptor_helper: derive_serde_adaptor_helper { - inline constexpr static bool is_null(string_converter& adaptor, std::string_view key) { return false; } - inline constexpr static size_t size(string_converter& adaptor) { return 1; } - inline constexpr static bool is_struct(string_converter& adaptor) { return true; } - }; - - template struct serde_adaptor { - static void from(string_converter& s, std::string_view key, T& data){ - throw serde::unimplemented_error(fmt::format("serde_adaptor<{}>::from(string_converter, key data)", - nameof::nameof_short_type())); - } - static void into(string_converter& s, std::string_view key, const T& data) { s.add(key, data); } - }; - - template - struct serde_adaptor> { - constexpr static void from(string_converter& s, std::string_view key, std::variant& data) { - throw serde::unimplemented_error(fmt::format("serde_adaptor<{}>::from(string_converter, key data)", - nameof::nameof_short_type())); - } - constexpr static void into(string_converter& s, std::string_view key, const std::variant& data) { - std::visit([&](auto& type){ serialize_to(type, s, key); }, data); - } - }; - - template - inline std::string to_string(const T& type) { return serialize(type).to_str(); } - template - inline std::string to_str(const T& type) { return serialize(type).to_str(); } -} +#include template struct fmt::formatter, char>> : fmt::formatter { template auto format(const T& serde_type, format_ctx& ctx) { - return formatter::format(serde::serialize(serde_type).to_str(), ctx); - } -}; - -template<> -struct fmt::formatter : fmt::formatter { - template - auto format(const serde::string_converter& serde_type, format_ctx& ctx) { - return formatter::format(serde_type.to_str(), ctx); + return formatter::format(serde::to_string(serde_type), ctx); } }; template<> -struct fmt::formatter : fmt::formatter { +struct fmt::formatter : fmt::formatter { template - auto format(const serde::string_converter::_element& serde_type, format_ctx& ctx) { - return formatter::format(serde_type.to_str(), ctx); + auto format(const serde::serde_sstream& serde_type, format_ctx& ctx) { + return formatter::format(serde_type.str(), ctx); } }; diff --git a/include/serdepp/adaptor/sstream.hpp b/include/serdepp/adaptor/sstream.hpp new file mode 100644 index 0000000..ee7d88c --- /dev/null +++ b/include/serdepp/adaptor/sstream.hpp @@ -0,0 +1,104 @@ +#pragma once + +#ifndef __SERDEPP_ADAPTOR_SSTREAM_HPP__ +#define __SERDEPP_ADAPTOR_SSTREAM_HPP__ + +#include +#include + +namespace serde { + struct serde_sstream { + std::vector members; + serde_sstream() : members() {} + + serde_sstream& add(const std::string& data, std::string_view key="") { + members.push_back(key.empty() ? data : "\"" + std::string{key} + "\": " + data); + return *this; + } + + inline std::string str(char begin = '{', char end = '}') const { + std::string str; + if (members.size() == 1) { + str = members.front(); + } else { + str = begin + str; + for (auto &it : members) { str.append(it + ", "); } + str.pop_back(); + str.back() = end; + } + return str; + } + }; + + + template<> struct serde_adaptor_helper: derive_serde_adaptor_helper { + inline constexpr static bool is_null(serde_sstream& adaptor, std::string_view key) { return false; } + inline constexpr static size_t size(serde_sstream& adaptor) { return 1; } + inline constexpr static bool is_struct(serde_sstream& adaptor) { return true; } + }; + + template struct serde_adaptor { + static void from(serde_sstream& s, std::string_view key, T& data){ + throw serde::unimplemented_error("serde_adaptor<{}>::from(serde_sstream, key data)" + + std::string(nameof::nameof_short_type())); + } + static void into(serde_sstream& s, std::string_view key, const T& data) { + std::stringstream ss; ss << data; + s.add(ss.str(), key); + } + }; + + template struct serde_adaptor { + inline static void from(serde_sstream& s, std::string_view key, T& data) { + throw serde::unimplemented_error("serde_adaptor<{}>::from(serde_sstream, key data)" + + std::string(nameof::nameof_short_type())); + } + inline static void into(serde_sstream &s, std::string_view key, const T& data) { + s.add(serialize(data).str(), key); + } + }; + + template + struct serde_adaptor> { + constexpr static void from(serde_sstream& s, std::string_view key, std::variant& data) { + throw serde::unimplemented_error("serde_adaptor<{}>::from(serde_sstream, key data)" + + std::string(nameof::nameof_short_type())); + } + constexpr static void into(serde_sstream& s, std::string_view key, const std::variant& data) { + std::visit([&](auto& type){ serialize_to(type, s, key); }, data); + } + }; + + template struct serde_adaptor { + using E = type::seq_e; + static void from(serde_sstream& s, std::string_view key, T& arr) { + throw serde::unimplemented_error("serde_adaptor<{}>::from(serde_sstream, key data)" + + std::string(nameof::nameof_short_type())); + } + static void into(serde_sstream& s, std::string_view key, const T& data) { + serde_sstream ss; + for(auto& it : data) { ss.add(serialize(it).str()); } + s.add(ss.str('[', ']'), key); + } + }; + + template struct serde_adaptor { + using E = type::map_e; + inline static void from(serde_sstream& s, std::string_view key, Map& map) { + throw serde::unimplemented_error("serde_adaptor<{}>::from(serde_sstream, key data)" + + std::string(nameof::nameof_short_type())); + } + inline static void into(serde_sstream& s, std::string_view key, const Map& data) { + serde_sstream ss; + for(auto& [key_, it] : data) { ss.add(serialize(it).str(), key_); } + s.add(ss.str(), key); + } + }; + + template + inline std::string to_string(const T& type) { return serialize(type).str(); } + template + inline std::string to_str(const T& type) { return serialize(type).str(); } +} + +#endif diff --git a/include/serdepp/attribute/make_optional.hpp b/include/serdepp/attribute/make_optional.hpp index 3b1c19b..9517cb4 100644 --- a/include/serdepp/attribute/make_optional.hpp +++ b/include/serdepp/attribute/make_optional.hpp @@ -19,8 +19,9 @@ namespace serde::attribute { next_attr.from(ctx, data, key, remains...); } } else { - throw serde::attribute_error(fmt::format("this {} is not emptyable type", - nameof::nameof_short_type())); + throw serde::attribute_error("this " + + std::string(nameof::nameof_short_type()) + + " is not emptyable type"); } } diff --git a/include/serdepp/exception.hpp b/include/serdepp/exception.hpp index 5500e24..dfec819 100644 --- a/include/serdepp/exception.hpp +++ b/include/serdepp/exception.hpp @@ -1,7 +1,6 @@ #pragma once #include -#include #ifndef __SERDEPP_EXCEPTION_HPP__ #define __SERDEPP_EXCEPTION_HPP__ @@ -14,7 +13,7 @@ namespace serde { }; struct unimplemented_error :exception { - explicit unimplemented_error(std::string what) : what_(fmt::format("unimplemented function: {}\n", what)) {} + explicit unimplemented_error(std::string what) : what_("unimplemented function: " + what + '\n') {} virtual ~unimplemented_error() noexcept override = default; virtual const char* what() const noexcept override {return what_.c_str();} protected: @@ -22,7 +21,7 @@ namespace serde { }; struct variant_error :exception { - explicit variant_error(std::string what) : what_(fmt::format("varaint error: {}\n", what)) {} + explicit variant_error(std::string what) : what_("varaint error: " + what + '\n') {} virtual ~variant_error() noexcept override = default; virtual const char* what() const noexcept override {return what_.c_str();} protected: @@ -31,7 +30,7 @@ namespace serde { struct enum_error : exception { public: - explicit enum_error(std::string what) : what_(fmt::format("unregisted enum value: {}\n", what)) {} + explicit enum_error(std::string what) : what_("unregisted enum value: " + what + '\n') {} virtual ~enum_error() noexcept override = default; virtual const char* what() const noexcept override {return what_.c_str();} protected: @@ -40,7 +39,7 @@ namespace serde { struct unregisted_data_error : exception { public: - explicit unregisted_data_error(std::string what) : what_(fmt::format("unregisted data: {}\n", what)) {} + explicit unregisted_data_error(std::string what) : what_("unregisted data: " + what + '\n') {} virtual ~unregisted_data_error() noexcept override = default; virtual const char* what() const noexcept override {return what_.c_str();} protected: @@ -49,7 +48,7 @@ namespace serde { struct attribute_error : exception { public: - explicit attribute_error(std::string what) : what_(fmt::format("attribute error: {}\n", what)) {} + explicit attribute_error(std::string what) : what_("attribute error: " + what + '\n') {} virtual ~attribute_error() noexcept override = default; virtual const char* what() const noexcept override {return what_.c_str();} protected: @@ -57,5 +56,4 @@ namespace serde { }; } - #endif diff --git a/include/serdepp/ostream.hpp b/include/serdepp/ostream.hpp index d086147..2541b22 100644 --- a/include/serdepp/ostream.hpp +++ b/include/serdepp/ostream.hpp @@ -3,7 +3,7 @@ #ifndef __SERDEPP_OSTREAM_HPP__ #define __SERDEPP_OSTREAM_HPP__ -#include "serdepp/adaptor/fmt.hpp" +#include "serdepp/adaptor/sstream.hpp" namespace serde::ostream { //template @@ -17,7 +17,7 @@ namespace serde::ostream { template< class CharT, class Traits, typename T> std::basic_ostream& operator<<(std::basic_ostream& os, const T& x) { if constexpr (type::is_struct_v) { - return os << serde::serialize(x).to_str(); + return os << serde::to_string(x); } else { return os << x; } diff --git a/include/serdepp/serde.hpp b/include/serdepp/serde.hpp index 7a8e1e5..f54004a 100644 --- a/include/serdepp/serde.hpp +++ b/include/serdepp/serde.hpp @@ -4,6 +4,7 @@ #define __SERDEPP__SERDE_HPP__ #include - +#include +#include #endif diff --git a/include/serdepp/serializer.hpp b/include/serdepp/serializer.hpp index 4524a4d..ddeba36 100644 --- a/include/serdepp/serializer.hpp +++ b/include/serdepp/serializer.hpp @@ -12,13 +12,15 @@ #include #include #include -#include #include -#include "serdepp/meta.hpp" #include #include +#include +#include +#include "serdepp/meta.hpp" #include "serdepp/exception.hpp" + namespace serde { using namespace serde::meta; @@ -37,26 +39,30 @@ namespace serde template struct derive_serde_adaptor_helper { // default serde adaptor helper inline constexpr static bool is_null(Adaptor& adaptor, std::string_view key) { - throw serde::unimplemented_error(fmt::format("serde_adaptor<{}>::is_null(adaptor, key)", - nameof::nameof_short_type())); + throw serde::unimplemented_error("serde_adaptor<" + + std::string(nameof::nameof_short_type()) + +">::is_null(adaptor, key)"); return adaptor.contains(key); } inline constexpr static size_t size(Adaptor& adaptor) { - throw serde::unimplemented_error(fmt::format("serde_adaptor<{}>::size(adaptor, key)", - nameof::nameof_short_type())); + throw serde::unimplemented_error("serde_adaptor<" + + std::string(nameof::nameof_short_type()) + +">::size(adaptor, key)"); return adaptor.size(); } inline constexpr static bool is_struct(Adaptor& adaptor) { - throw serde::unimplemented_error(fmt::format("serde_adaptor<{}>::is_struct(adaptor, key)", - nameof::nameof_short_type())); + throw serde::unimplemented_error("serde_adaptor<" + + std::string(nameof::nameof_short_type()) + +">::is_struct(adaptor, key)"); return true; } inline constexpr static Adaptor parse_file(Adaptor& adaptor) { - throw serde::unimplemented_error(fmt::format("serde_adaptor<{}>::parse_file(path)", - nameof::nameof_short_type())); + throw serde::unimplemented_error("serde_adaptor<" + + std::string(nameof::nameof_short_type()) + +">::parse_file(adaptor, key)"); return true; } }; @@ -172,7 +178,7 @@ namespace serde inline constexpr static Enum from_str(std::string_view str) { auto value = magic_enum::enum_cast(str); if (!value.has_value()) { - throw enum_error(fmt::format("{}::{}", nameof::nameof_type(), str)); + throw enum_error(std::string{nameof::nameof_type()} + "::" + std::string{str}); } return *value; } @@ -303,18 +309,18 @@ namespace serde } inline constexpr serde_struct& no_remain() { + using namespace std::literals; if constexpr (!Context::is_serialize) { const auto adaptor_size = Context::Helper::is_struct(context_.adaptor) ? Context::Helper::size(context_.adaptor) : 1; const auto serde_size = context_.read_count_; if(adaptor_size > serde_size) { - throw unregisted_data_error(fmt::format( - "serde[{}] read:{} != adaptor[{}] read:{}", - type, - serde_size, - nameof::nameof_short_type(), - adaptor_size)); + throw unregisted_data_error( + "serde["s + std::string{type} + "] read: " + std::to_string(serde_size) + + " != adaptor[" + + std::string(nameof::nameof_short_type()) + + "] read: " + std::to_string(adaptor_size)); } } return *this; diff --git a/include/serdepp/utility.hpp b/include/serdepp/utility.hpp index 14fbf40..cb83010 100644 --- a/include/serdepp/utility.hpp +++ b/include/serdepp/utility.hpp @@ -1,7 +1,6 @@ #pragma once #include "serdepp/serializer.hpp" -#include "serdepp/adaptor/fmt.hpp" #include "serdepp/attributes.hpp" #include