From 5c34e8ae67998c53c1d4016d5b9f4c02917f0ecf Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Sun, 26 Nov 2023 22:04:04 +0100 Subject: core,codec,tools: Working on c binding generation --- c++/codec/schema_stringify.h | 118 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 c++/codec/schema_stringify.h (limited to 'c++/codec/schema_stringify.h') diff --git a/c++/codec/schema_stringify.h b/c++/codec/schema_stringify.h new file mode 100644 index 0000000..a82081a --- /dev/null +++ b/c++/codec/schema_stringify.h @@ -0,0 +1,118 @@ +#pragma once + +#include "schema.h" + +#include +#include + +namespace saw { +template +struct schema_stringify { + static_assert(always_false, "Not supported"); +}; + +template +struct schema_stringify> { + static void apply(std::stringstream& iss) { + iss << "saw::schema::Array<"; + schema_stringify::apply(iss); + iss << ","; + iss << ct_convert_to_digits::literal.view(); + iss << ">"; + } +}; + +template +struct schema_stringify> { + static void apply(std::stringstream& iss) { + iss << "saw::schema::Primitive<"; + schema_stringify::apply(iss); + iss << ","; + iss << ct_convert_to_digits::literal.view(); + iss << ">"; + } +}; + +template<> +struct schema_stringify { + static void apply(std::stringstream& iss) { + iss << "saw:schema::SignedInteger"; + } +}; + +template<> +struct schema_stringify { + static void apply(std::stringstream& iss) { + iss << "saw:schema::UnsignedInteger"; + } +}; + +template<> +struct schema_stringify { + static void apply(std::stringstream& iss) { + iss << "saw:schema::FloatingPoint"; + } +}; + +template +struct schema_stringify_member { + static void apply(std::stringstream& iss) { + (void)iss; + } +}; + +template +struct schema_stringify_member, TL...> { + + static void apply(std::stringstream& iss) { + iss << "saw::schema::Member<"; + schema_stringify::apply(iss); + iss << ",\""; + iss << Name.view(); + iss << "\">"; + if constexpr ( sizeof...(TL) > 0){ + iss << ","; + schema_stringify_member::apply(iss); + } + } +}; + +template +struct schema_stringify...>> { + static void apply(std::stringstream& iss) { + iss << "saw::schema::Struct<"; + schema_stringify_member...>::apply(iss); + iss << ">"; + } +}; + +template +struct schema_stringify...>> { + static void apply(std::stringstream& iss) { + iss << "saw::schema::Union<"; + schema_stringify_member...>::apply(iss); + iss << ">"; + } +}; + +template +struct schema_stringify> { + static void apply(std::stringstream& iss){ + iss << "saw::schema::Function<"; + schema_stringify::apply(iss); + iss << ","; + schema_stringify::apply(iss); + iss << ">"; + } +}; + +template +struct schema_stringify...>>{ + static void apply(std::stringstream& iss){ + iss << "saw::schema::Interface<"; + schema_stringify_member...>::apply(iss); + iss << ">"; + } +}; + +} -- cgit v1.2.3