...
This commit is contained in:
@@ -168,8 +168,8 @@ endif()
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
add_executable(exe EXCLUDE_FROM_ALL main.cpp)
|
# add_executable(exe EXCLUDE_FROM_ALL main.cpp)
|
||||||
target_link_libraries(exe PUBLIC ${PROJECT_NAME})
|
# target_link_libraries(exe PUBLIC ${PROJECT_NAME})
|
||||||
|
|
||||||
# get_target_property(ZZ exe INCLUDE_DIRECTORIES)
|
# get_target_property(ZZ exe INCLUDE_DIRECTORIES)
|
||||||
|
|
||||||
|
|||||||
77
mcc_serializer.h
Normal file
77
mcc_serializer.h
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <concepts>
|
||||||
|
|
||||||
|
#include "mcc_concepts.h"
|
||||||
|
#include "mcc_traits.h"
|
||||||
|
|
||||||
|
namespace mcc
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
struct mcc_serializer_interface_t {
|
||||||
|
virtual ~mcc_serializer_interface_t() = default;
|
||||||
|
|
||||||
|
template <std::derived_from<mcc_serializer_interface_t> SelfT, traits::mcc_output_char_range R, typename ValueT>
|
||||||
|
mcc_error_c auto operator()(this SelfT&& self, R& output, ValueT&& value)
|
||||||
|
{
|
||||||
|
return std::forward<SelfT>(self).operator=(output, std::forward<ValueT>(value));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
concept mcc_serializer_c = std::derived_from<T, mcc_serializer_interface_t>;
|
||||||
|
|
||||||
|
|
||||||
|
template <typename VT>
|
||||||
|
class MccSerializer : public mcc_serializer_interface_t
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static constexpr std::string_view defaultDelimiter{","};
|
||||||
|
|
||||||
|
typedef std::error_code error_t;
|
||||||
|
|
||||||
|
MccSerializer() = default;
|
||||||
|
|
||||||
|
~MccSerializer() = default;
|
||||||
|
|
||||||
|
error_t operator()(traits::mcc_output_char_range auto& output, VT&& value)
|
||||||
|
requires std::formattable<VT, char>
|
||||||
|
{
|
||||||
|
std::format_to(std::back_inserter(output), "{}", value);
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
std::string _delimiter{defaultDelimiter};
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
template <mcc_angle_c T>
|
||||||
|
class MccSerializer<T> : public mcc_serializer_interface_t
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
error_t operator()(traits::mcc_output_char_range auto& output, T&& value)
|
||||||
|
{
|
||||||
|
std::format_to(std::back_inserter(output), "{}", value.degrees());
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
static_assert(mcc_serializer_c<MccSerializer<float>>, "!!!");
|
||||||
|
|
||||||
|
static_assert(mcc_serializer_c<MccSerializer<impl::MccAngle>>, "!!!");
|
||||||
|
|
||||||
|
void f()
|
||||||
|
{
|
||||||
|
MccSerializer<impl::MccAngle> s;
|
||||||
|
|
||||||
|
std::string str;
|
||||||
|
s(str, impl::MccAngleALT{1.1});
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace mcc
|
||||||
Reference in New Issue
Block a user