Tser can now output wstring and already saves wstring, so now need to use it.
This commit is contained in:
parent
b113b90257
commit
babc190525
2 changed files with 8 additions and 2 deletions
|
@ -82,13 +82,14 @@ struct Pixel {
|
||||||
|
|
||||||
struct Robot {
|
struct Robot {
|
||||||
Pixel point;
|
Pixel point;
|
||||||
|
std::wstring name;
|
||||||
std::optional<Item> item;
|
std::optional<Item> item;
|
||||||
|
|
||||||
DEFINE_SERIALIZABLE(Robot, point, item);
|
DEFINE_SERIALIZABLE(Robot, point, name, item);
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_CASE("test using tser for serialization", "[config]") {
|
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';
|
std::cout << robot << '\n';
|
||||||
|
|
||||||
tser::BinaryArchive archive;
|
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.x == robot.point.x);
|
||||||
REQUIRE(loadedRobot.point.y == robot.point.y);
|
REQUIRE(loadedRobot.point.y == robot.point.y);
|
||||||
|
REQUIRE(loadedRobot.name == robot.name);
|
||||||
REQUIRE(loadedRobot.item == robot.item);
|
REQUIRE(loadedRobot.item == robot.item);
|
||||||
}
|
}
|
||||||
|
|
4
tser.hpp
4
tser.hpp
|
@ -8,6 +8,7 @@
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
|
#include <codecvt>
|
||||||
|
|
||||||
namespace tser{
|
namespace tser{
|
||||||
//implementation details for C++20 is_detected
|
//implementation details for C++20 is_detected
|
||||||
|
@ -89,6 +90,9 @@ namespace tser{
|
||||||
using V = std::decay_t<T>;
|
using V = std::decay_t<T>;
|
||||||
if constexpr (std::is_constructible_v<std::string, T> || std::is_same_v<V, char>) {
|
if constexpr (std::is_constructible_v<std::string, T> || std::is_same_v<V, char>) {
|
||||||
os << "\"" << val << "\"";
|
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>) {
|
} else if constexpr (is_container_v<V>) {
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
os << "\n[";
|
os << "\n[";
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue