diff options
Diffstat (limited to 'modules/codec/c++/forst.tmpl.hpp')
-rw-r--r-- | modules/codec/c++/forst.tmpl.hpp | 70 |
1 files changed, 69 insertions, 1 deletions
diff --git a/modules/codec/c++/forst.tmpl.hpp b/modules/codec/c++/forst.tmpl.hpp index 30d18ef..bfcafae 100644 --- a/modules/codec/c++/forst.tmpl.hpp +++ b/modules/codec/c++/forst.tmpl.hpp @@ -1,7 +1,75 @@ namespace saw { namespace impl { -struct forst_decode { +/** + * This class provides + */ +template<typename Schema> +struct forst_codec_info { + static_assert(always_false<Schema>, "Not supported."); +}; + +template<typename T, uint64_t N> +struct forst_codec_info<schema::Primitive<T,N>> { +private: +public: + static constexpr uint64_t layers = 0u; +}; + +template<> +struct forst_codec_info<schema::String> { +public: + static constexpr uint64_t layers = 1u; +}; + +template<typename T, uint64_t N> +struct forst_codec_info<schema::Array<T,N>> { +public: + static constexpr uint64_t layers = 1u + forst_codec_info<T>::layers; +}; + +template<typename... Members> +struct forst_codec_info<schema::Struct<Members...> > { +public: + template<uint64_t i> + static uint64_t max_layers() constexpr noexcept { + if constexpr ( i < sizeof...(Members) ) { + using MT = typename parameter_pack_type<i, Members...>::type; + + constexpr uint64_t layer_i = forst_codec_info<typename MT::Type>::layers; + + constexpr uint64_t layer_next = max_layers<i+1u>(); + + constexpr uint64_t layer_val = layer_i > layer_next ? layer_i : layer_next; + + return layer_val; + } + return 0u; + } +public: + static constexpr uint64_t layers = max_layers<0>(); +}; + +template<typename... T> +struct forst_codec_info<schema::Tuple<T...>> { +public: + template<uint64_t i> + static uint64_t max_layers() constexpr noexcept { + if constexpr ( i < sizeof...(Members) ) { + using MT = typename parameter_pack_type<i, T...>::type; + + constexpr uint64_t layer_i = forst_codec_info<MT>::layers; + + constexpr uint64_t layer_next = max_layers<i+1u>(); + + constexpr uint64_t layer_val = layer_i > layer_next ? layer_i : layer_next; + + return layer_val; + } + return 0u; + } +public: + static constexpr uint64_t layers = max_layers<0>(); }; } } |