Merge branch 'main' of git.learnjsthehardway.com:learn-code-the-hard-way/roguish

main
Zed A. Shaw 2 weeks ago
commit 809ec9ed0d
  1. 1
      tests/save.cpp
  2. 51
      tser.hpp
  3. 12
      wraps/cereal.wrap

@ -38,7 +38,6 @@ struct Robot {
TEST_CASE("test using tser for serialization", "[config]") {
auto robot = Robot{ Pixel{3,4}, L"BIG NAME", Item::RADAR};
std::cout << robot << '\n';
tser::BinaryArchive archive;
archive.save(robot);

@ -11,6 +11,7 @@
#include <locale>
#include <codecvt>
namespace tser{
//implementation details for C++20 is_detected
namespace detail {
@ -85,52 +86,6 @@ namespace tser{
template<class T> constexpr bool is_pointer_like_v = std::is_pointer_v<T> || is_detected_v<has_element_t, T> || is_detected_v<has_optional_t, T>;
//implementation of the recursive json printing
template<typename T>
constexpr inline decltype(auto) print(std::ostream& os, T&& val) {
using V = std::decay_t<T>;
if constexpr (std::is_constructible_v<std::string, T> || std::is_same_v<V, char>) {
os << "\"" << val << "\"";
} else if constexpr (std::is_constructible_v<std::wstring, T> || std::is_same_v<V, char>) {
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
os << "\"" << converter.to_bytes(val) << "\"";
} else if constexpr (is_container_v<V>) {
size_t i = 0;
os << "\n[";
for (auto& elem : val) {
os << (i++ == 0 ? "" : ",") << tser::print(os, elem);
}
os << "]\n";
} else if constexpr (is_tser_t_v<V> && !is_detected_v<has_outstream_op_t, V>) {
auto pMem = [&](auto& ... memberVal) {
size_t i = 0;
(((os << (i != 0 ? ", " : "") << '\"'), os << V::_memberNames[i++] << "\" : " << tser::print(os, memberVal)), ...);
};
os << "{ \"" << V::_typeName << "\": {"; std::apply(pMem, val.members()); os << "}}\n";
} else if constexpr (std::is_enum_v<V> &&! is_detected_v<has_outstream_op_t, V>) {
os << tser::print(os, static_cast<std::underlying_type_t<V>>(val));
} else if constexpr (is_tuple_v<V> && !is_detected_v<has_outstream_op_t, V>) {
std::apply([&](auto& ... t) {
int i = 0;
os << "{";
(((i++ != 0 ? os << ", " : os),
tser::print(os, t)), ...); // WTF
os << "}";
}, val);
} else if constexpr (is_pointer_like_v<V>) {
os << (val ? (os << (tser::print(os, *val)), "") : "null");
} else {
os << val;
}
return "";
}
class BinaryArchive {
std::string m_bytes = std::string(1024, '\0');
size_t m_bufferSize = 0, m_readOffset = 0;
@ -262,6 +217,4 @@ static constexpr std::array<const char*, tser::detail::n_args(#__VA_ARGS__)> _me
[](){ std::array<const char*, tser::detail::n_args(#__VA_ARGS__)> out{ }; \
for(size_t _i = 0, nArgs = 0; nArgs < tser::detail::n_args(#__VA_ARGS__) ; ++_i) { \
while(Type::_memberNameData[_i] == '\0') _i++; out[nArgs++] = &Type::_memberNameData[_i]; \
while(Type::_memberNameData[++_i] != '\0'); } return out;}();\
template<typename OT, std::enable_if_t<std::is_same_v<OT,Type> && !tser::is_detected_v<tser::has_outstream_op_t, OT>, int> = 0>\
friend std::ostream& operator<<(std::ostream& os, const OT& t) { tser::print(os, t); return os; }
while(Type::_memberNameData[++_i] != '\0'); } return out;}();

@ -1,12 +0,0 @@
[wrap-file]
directory = cereal-1.3.2
source_url = https://github.com/USCiLab/cereal/archive/v1.3.2.tar.gz
source_filename = cereal-1.3.2.tar.gz
source_hash = 16a7ad9b31ba5880dac55d62b5d6f243c3ebc8d46a3514149e56b5e7ea81f85f
patch_filename = cereal_1.3.2-1_patch.zip
patch_url = https://wrapdb.mesonbuild.com/v2/cereal_1.3.2-1/get_patch
patch_hash = fd2f047a40a0d291c643fdafe4ce743f0eadbef667b6afe43a332e1ba0862603
[provide]
cereal = cereal_dep
Loading…
Cancel
Save