summaryrefslogtreecommitdiff
path: root/modules/codec/c++/forst.tmpl.hpp
blob: a52f0b95bc3ac62acf5a06a81c6ea0be8b5fbc0f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
namespace saw {
namespace impl {

/**
 * 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 constexpr uint64_t max_layers() 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::ValueType>::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<0u>();
};

template<typename... T>
struct forst_codec_info<schema::Tuple<T...>> {
public:
	template<uint64_t i>
	static constexpr uint64_t max_layers() noexcept {
		if constexpr ( i < sizeof...(T) ) {
			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<0u>();
};
}
}