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 +++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 modules/codec-unit/c++/unit_print.hpp (limited to '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; +} +} -- cgit v1.2.3