summaryrefslogtreecommitdiff
path: root/modules/codec/schema_stringify.h
diff options
context:
space:
mode:
Diffstat (limited to 'modules/codec/schema_stringify.h')
-rw-r--r--modules/codec/schema_stringify.h118
1 files changed, 118 insertions, 0 deletions
diff --git a/modules/codec/schema_stringify.h b/modules/codec/schema_stringify.h
new file mode 100644
index 0000000..a82081a
--- /dev/null
+++ b/modules/codec/schema_stringify.h
@@ -0,0 +1,118 @@
+#pragma once
+
+#include "schema.h"
+
+#include <sstream>
+#include <type_traits>
+
+namespace saw {
+template<typename Schema>
+struct schema_stringify {
+ static_assert(always_false<Schema>, "Not supported");
+};
+
+template<typename T, size_t Dim>
+struct schema_stringify<schema::Array<T,Dim>> {
+ static void apply(std::stringstream& iss) {
+ iss << "saw::schema::Array<";
+ schema_stringify<T>::apply(iss);
+ iss << ",";
+ iss << ct_convert_to_digits<Dim, 10>::literal.view();
+ iss << ">";
+ }
+};
+
+template<typename T, size_t N>
+struct schema_stringify<schema::Primitive<T,N>> {
+ static void apply(std::stringstream& iss) {
+ iss << "saw::schema::Primitive<";
+ schema_stringify<T>::apply(iss);
+ iss << ",";
+ iss << ct_convert_to_digits<N,10>::literal.view();
+ iss << ">";
+ }
+};
+
+template<>
+struct schema_stringify<schema::SignedInteger> {
+ static void apply(std::stringstream& iss) {
+ iss << "saw:schema::SignedInteger";
+ }
+};
+
+template<>
+struct schema_stringify<schema::UnsignedInteger> {
+ static void apply(std::stringstream& iss) {
+ iss << "saw:schema::UnsignedInteger";
+ }
+};
+
+template<>
+struct schema_stringify<schema::FloatingPoint> {
+ static void apply(std::stringstream& iss) {
+ iss << "saw:schema::FloatingPoint";
+ }
+};
+
+template<typename... T>
+struct schema_stringify_member {
+ static void apply(std::stringstream& iss) {
+ (void)iss;
+ }
+};
+
+template<typename T0, string_literal Name, typename... TL>
+struct schema_stringify_member<schema::Member<T0,Name>, TL...> {
+
+ static void apply(std::stringstream& iss) {
+ iss << "saw::schema::Member<";
+ schema_stringify<T0>::apply(iss);
+ iss << ",\"";
+ iss << Name.view();
+ iss << "\">";
+ if constexpr ( sizeof...(TL) > 0){
+ iss << ",";
+ schema_stringify_member<TL...>::apply(iss);
+ }
+ }
+};
+
+template<typename... T, string_literal... Lits>
+struct schema_stringify<schema::Struct<schema::Member<T,Lits>...>> {
+ static void apply(std::stringstream& iss) {
+ iss << "saw::schema::Struct<";
+ schema_stringify_member<schema::Member<T,Lits>...>::apply(iss);
+ iss << ">";
+ }
+};
+
+template<typename... T, string_literal... Lits>
+struct schema_stringify<schema::Union<schema::Member<T,Lits>...>> {
+ static void apply(std::stringstream& iss) {
+ iss << "saw::schema::Union<";
+ schema_stringify_member<schema::Member<T,Lits>...>::apply(iss);
+ iss << ">";
+ }
+};
+
+template<typename Req, typename Resp>
+struct schema_stringify<schema::Function<Req, Resp>> {
+ static void apply(std::stringstream& iss){
+ iss << "saw::schema::Function<";
+ schema_stringify<Req>::apply(iss);
+ iss << ",";
+ schema_stringify<Resp>::apply(iss);
+ iss << ">";
+ }
+};
+
+template<typename... T, string_literal... Lits>
+struct schema_stringify<schema::Interface<schema::Member<T,Lits>...>>{
+ static void apply(std::stringstream& iss){
+ iss << "saw::schema::Interface<";
+ schema_stringify_member<schema::Member<T,Lits>...>::apply(iss);
+ iss << ">";
+ }
+};
+
+}