From 0d32f9b2c73690fa188d0f5920dfa9cbe3005200 Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Sun, 20 Apr 2025 17:12:55 +0200 Subject: Added Unit printing --- modules/codec-unit/c++/unit_print.hpp | 54 +++++++++++++++++++++++++++++++++ modules/codec-unit/tests/codec-unit.cpp | 6 ++++ 2 files changed, 60 insertions(+) create mode 100644 modules/codec-unit/c++/unit_print.hpp diff --git a/modules/codec-unit/c++/unit_print.hpp b/modules/codec-unit/c++/unit_print.hpp new file mode 100644 index 0000000..724e9d6 --- /dev/null +++ b/modules/codec-unit/c++/unit_print.hpp @@ -0,0 +1,54 @@ +#pragma once + +#include + +namespace std { +template +inline ostream& operator<<(ostream& o, const saw::schema::UnitElement&){ + o< +struct unit_print { + static_assert(always_false, "Template type not supported"); +}; + +template +struct unit_print, schema::UnitElement...> { + static std::ostream& print(std::ostream& o){ + schema::UnitElement element; + + std::ostream& o_ret = o << element; + + if constexpr (sizeof...(UTL) > 0) { + std::ostream& o_ret_next = o_ret << ' ' << '*' << ' '; + return unit_print...>::print(o_ret_next); + } + + return o_ret<<']'; + } +}; +} +} + +namespace std { +template +inline ostream& operator<<(ostream& o, const saw::data, Encode>& unit); + +template +inline ostream& operator<<(ostream& o, const saw::data...>, Encode>& unit){ + o << unit.handle().get(); + if constexpr (sizeof...(UnitT) > 0) { + auto& o_ret = o << ' '<<'['; + return saw::impl::unit_print...>::print(o_ret); + } + return o; +} +} diff --git a/modules/codec-unit/tests/codec-unit.cpp b/modules/codec-unit/tests/codec-unit.cpp index 99645bd..6ffc4fc 100644 --- a/modules/codec-unit/tests/codec-unit.cpp +++ b/modules/codec-unit/tests/codec-unit.cpp @@ -3,6 +3,7 @@ #include #include "../c++/unit.hpp" +#include "../c++/unit_print.hpp" namespace { namespace sch { @@ -60,4 +61,9 @@ SAW_TEST("Codec Unit/Division"){ SAW_EXPECT(c == data>{5u}, "Expected result 5"); } + +SAW_TEST("Codec Unit/Print"){ + using namespace saw; + // TODO +} } -- cgit v1.2.3