summaryrefslogtreecommitdiff
path: root/modules/codec/c++/schema_meta.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'modules/codec/c++/schema_meta.hpp')
-rw-r--r--modules/codec/c++/schema_meta.hpp68
1 files changed, 68 insertions, 0 deletions
diff --git a/modules/codec/c++/schema_meta.hpp b/modules/codec/c++/schema_meta.hpp
new file mode 100644
index 0000000..a37197a
--- /dev/null
+++ b/modules/codec/c++/schema_meta.hpp
@@ -0,0 +1,68 @@
+#pragma once
+
+#include "schema.hpp"
+
+namespace saw {
+
+template<typename Schema>
+struct meta_schema {
+ static_assert(always_false<Schema>, "Not supported Schema.");
+};
+
+template<>
+struct meta_schema<schema::Void> {
+ using Schema = schema::Void;
+ using MetaSchema = schema::Void;
+};
+
+template<typename T, uint64_t N>
+struct meta_schema<schema::Primitive<T,N>> {
+ using MetaSchema = schema::Void;
+ using Schema = schema::Primitive<T,N>;
+};
+
+template<typename TA, uint64_t NA, typename TB, uint64_t NB>
+struct meta_schema<schema::MixedPrecision<schema::Primitive<TA,NA>, schema::Primitive<TB,NB> >> {
+ using Schema = schema::MixedPrecision<schema::Primitive<TA,NA>, schema::Primitive<TB,NB>>;
+ using MetaSchema = schema::Void;
+};
+
+template<typename... T, string_literal... Lit>
+struct meta_schema<schema::Struct<schema::Member<T,Lit>...>> {
+ using MetaSchema = schema::Struct<schema::Member<typename meta_schema<T>::MetaSchema,Lit>...>;
+ using Schema = schema::Struct<schema::Member<T,Lit>...>;
+};
+
+template<typename... T, string_literal... Lit>
+struct meta_schema<schema::Union<schema::Member<T,Lit>...>> {
+ using MetaSchema = schema::Union<schema::Member<typename meta_schema<T>::MetaSchema,Lit>...>;
+ using Schema = schema::Union<schema::Member<T,Lit>...>;
+};
+
+template<typename... T>
+struct meta_schema<schema::Tuple<T...>> {
+ using MetaSchema = schema::Tuple<typename meta_schema<T>::MetaSchema...>;
+ using Schema = schema::Tuple<T...>;
+};
+
+template<>
+struct meta_schema<schema::String> {
+ using MetaSchema = schema::UInt64;
+ using Schema = schema::String;
+};
+
+/**
+ * Technically we also can distinguish if T is primitive.
+ */
+template<typename T, uint64_t Dim>
+struct meta_schema<schema::Array<T,Dim>> {
+ using MetaSchema = schema::FixedArray<schema::UInt64,Dim>;
+ using Schema = schema::Array<T,Dim>;
+};
+
+template<typename T, uint64_t Dim>
+struct meta_schema<schema::FixedArray<T,Dim>> {
+ using MetaSchema = schema::Void;
+ using Schema = schema::FixedArray<T,Dim>;
+};
+}