summaryrefslogtreecommitdiff
path: root/modules/codec/c++/schema_factory.h
blob: bb8588fa43028f872ee560a3b3b56b530ff83470 (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
#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 {};
		}
};

/**
 * 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 {};
}
}