From babc19052557a57ac84b9bdec303256698e23ee9 Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Mon, 4 Nov 2024 23:58:56 -0500 Subject: [PATCH] Tser can now output wstring and already saves wstring, so now need to use it. --- tests/config.cpp | 6 ++++-- tser.hpp | 4 ++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/config.cpp b/tests/config.cpp index 5029a26..bbd2f58 100644 --- a/tests/config.cpp +++ b/tests/config.cpp @@ -82,13 +82,14 @@ struct Pixel { struct Robot { Pixel point; + std::wstring name; std::optional item; - DEFINE_SERIALIZABLE(Robot, point, item); + DEFINE_SERIALIZABLE(Robot, point, name, item); }; TEST_CASE("test using tser for serialization", "[config]") { - auto robot = Robot{ Pixel{3,4}, Item::RADAR}; + auto robot = Robot{ Pixel{3,4}, L"BIG NAME", Item::RADAR}; std::cout << robot << '\n'; tser::BinaryArchive archive; @@ -101,5 +102,6 @@ TEST_CASE("test using tser for serialization", "[config]") { REQUIRE(loadedRobot.point.x == robot.point.x); REQUIRE(loadedRobot.point.y == robot.point.y); + REQUIRE(loadedRobot.name == robot.name); REQUIRE(loadedRobot.item == robot.item); } diff --git a/tser.hpp b/tser.hpp index d603dc6..0c56038 100644 --- a/tser.hpp +++ b/tser.hpp @@ -8,6 +8,7 @@ #include #include #include +#include namespace tser{ //implementation details for C++20 is_detected @@ -89,6 +90,9 @@ namespace tser{ using V = std::decay_t; if constexpr (std::is_constructible_v || std::is_same_v) { os << "\"" << val << "\""; + } else if constexpr (std::is_constructible_v || std::is_same_v) { + std::wstring_convert> converter; + os << "\"" << converter.to_bytes(val) << "\""; } else if constexpr (is_container_v) { size_t i = 0; os << "\n[";