diff options
author | Claudius "keldu" Holeksa <mail@keldu.de> | 2023-12-04 17:32:38 +0100 |
---|---|---|
committer | Claudius "keldu" Holeksa <mail@keldu.de> | 2023-12-04 17:32:38 +0100 |
commit | ad15f0ec0074c1245505a016d348bcc1ce9ad01b (patch) | |
tree | 7ad30b3e0b253cf7d4d547cc605bc288fc1cfbc3 /modules/codec | |
parent | a863f9af9fff0ecb276c6769149d9672961b7533 (diff) |
codec: Added simple schema build helper
Diffstat (limited to 'modules/codec')
-rw-r--r-- | modules/codec/c++/schema_builder.h | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/modules/codec/c++/schema_builder.h b/modules/codec/c++/schema_builder.h new file mode 100644 index 0000000..91094fe --- /dev/null +++ b/modules/codec/c++/schema_builder.h @@ -0,0 +1,46 @@ +#pragma once + +#include "schema.h" + +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 {}; + } +}; + +template<typename T> +constexpr schema_factory<T> build_schema() noexcept { + return {}; +} +} |