diff options
author | Claudius "keldu" Holeksa <mail@keldu.de> | 2023-11-26 22:04:04 +0100 |
---|---|---|
committer | Claudius "keldu" Holeksa <mail@keldu.de> | 2023-11-26 22:04:04 +0100 |
commit | 5c34e8ae67998c53c1d4016d5b9f4c02917f0ecf (patch) | |
tree | 521f55ead53f6618721afc67986665b0bc53fb42 /c++/codec | |
parent | 348d6734b34d69c3ebd9982320281a7329ad8730 (diff) |
core,codec,tools: Working on c binding generation
Diffstat (limited to 'c++/codec')
-rw-r--r-- | c++/codec/schema_stringify.h | 118 |
1 files changed, 118 insertions, 0 deletions
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 <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 << ">"; + } +}; + +} |