diff options
Diffstat (limited to 'modules/codec/c++/schema_factory.hpp')
-rw-r--r-- | modules/codec/c++/schema_factory.hpp | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/modules/codec/c++/schema_factory.hpp b/modules/codec/c++/schema_factory.hpp new file mode 100644 index 0000000..f39c93c --- /dev/null +++ b/modules/codec/c++/schema_factory.hpp @@ -0,0 +1,49 @@ +#pragma once + +#include "schema.hpp + +namespace saw { +template<typename T> +struct schema_factory { + using Schema = T; + static_assert(always_false<T>, "Not supported"); +}; + +template<typename... T, string_literal... Keys> +struct schema_factory<schema::Struct<schema::Member<T,Keys>...>> { + using Schema = schema::Struct<schema::Member<T,Keys>...>; + + template<typename TA, string_literal KA> + constexpr schema_factory<schema::Struct<schema::Member<T,Keys>...,schema::Member<TA,KA>>> add() const noexcept { + return {}; + } +}; + +template<typename... T, string_literal... Keys> +struct schema_factory<schema::Union<schema::Member<T,Keys>...>> { + using Schema = schema::Union<schema::Member<T,Keys>...>; + + template<typename TA, string_literal KA> + constexpr schema_factory<schema::Union<schema::Member<T,Keys>...,schema::Member<TA,KA>>> add() const noexcept { + return {}; + } +}; + +template<typename... T> +struct schema_factory<schema::Tuple<T...>> { + using Schema = schema::Tuple<T...>; + + template<typename TA> + constexpr schema_factory<schema::Tuple<T...,TA>> add() const noexcept { + return {}; + } +}; + +/** + * This creates the base schema. For example an empty struct,tuple,union or anything else. + */ +template<typename T> +constexpr schema_factory<T> build_schema() noexcept { + return {}; +} +} |