summaryrefslogtreecommitdiff
path: root/modules/codec-unit/c++
diff options
context:
space:
mode:
Diffstat (limited to 'modules/codec-unit/c++')
-rw-r--r--modules/codec-unit/c++/unit_print.hpp54
1 files changed, 54 insertions, 0 deletions
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 <iostream>
+
+namespace std {
+template<typename UT, int64_t UE>
+inline ostream& operator<<(ostream& o, const saw::schema::UnitElement<UT,UE>&){
+ o<<UT::short_name;
+ if constexpr (UE != 1){
+ o<<'^'<<'('<<UE<<')';
+ }
+ return o;
+}
+}
+
+namespace saw {
+namespace impl {
+template<typename... T>
+struct unit_print {
+ static_assert(always_false<T...>, "Template type not supported");
+};
+
+template<typename UT, int64_t UE, typename... UTL, int64_t... UEL>
+struct unit_print<schema::UnitElement<UT,UE>, schema::UnitElement<UTL,UEL>...> {
+ static std::ostream& print(std::ostream& o){
+ schema::UnitElement<UT,UE> element;
+
+ std::ostream& o_ret = o << element;
+
+ if constexpr (sizeof...(UTL) > 0) {
+ std::ostream& o_ret_next = o_ret << ' ' << '*' << ' ';
+ return unit_print<schema::UnitElement<UTL,UEL>...>::print(o_ret_next);
+ }
+
+ return o_ret<<']';
+ }
+};
+}
+}
+
+namespace std {
+template<typename Store, typename Encode, typename... T>
+inline ostream& operator<<(ostream& o, const saw::data<saw::schema::Unit<Store,T...>, Encode>& unit);
+
+template<typename StorageT, typename Encode, typename... UnitT, int64_t... UnitE>
+inline ostream& operator<<(ostream& o, const saw::data<saw::schema::Unit<StorageT,saw::schema::UnitElement<UnitT,UnitE>...>, Encode>& unit){
+ o << unit.handle().get();
+ if constexpr (sizeof...(UnitT) > 0) {
+ auto& o_ret = o << ' '<<'[';
+ return saw::impl::unit_print<saw::schema::UnitElement<UnitT,UnitE>...>::print(o_ret);
+ }
+ return o;
+}
+}