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
76
77
78
79
80
81
82
83
84
85
86
|
#pragma once
#include "schema.hpp"
namespace saw {
template<typename Schema>
struct meta_schema {
static_assert(always_false<Schema>, "Not supported Schema.");
};
template<>
struct meta_schema<schema::Void> {
using Schema = schema::Void;
using MetaSchema = schema::Void;
};
template<>
struct meta_schema<schema::Bool> {
using Schema = schema::Bool;
using MetaSchema = schema::Void;
};
template<typename T, uint64_t N>
struct meta_schema<schema::Primitive<T,N>> {
using MetaSchema = schema::Void;
using Schema = schema::Primitive<T,N>;
};
template<typename TA, uint64_t NA, typename TB, uint64_t NB>
struct meta_schema<schema::MixedPrecision<schema::Primitive<TA,NA>, schema::Primitive<TB,NB> >> {
using Schema = schema::MixedPrecision<schema::Primitive<TA,NA>, schema::Primitive<TB,NB>>;
using MetaSchema = schema::Void;
};
template<typename T>
struct meta_schema<schema::Ref<T>> {
using MetaSchema = schema::Void;
using Schema = schema::Ref<T>;
};
template<typename Key, typename Value>
struct meta_schema<schema::Map<Key,Value>> {
using MetaSchema = schema::Void;
using Schema = schema::Map<Key,Value>;
};
template<typename... T, string_literal... Lit>
struct meta_schema<schema::Struct<schema::Member<T,Lit>...>> {
using MetaSchema = schema::Struct<schema::Member<typename meta_schema<T>::MetaSchema,Lit>...>;
using Schema = schema::Struct<schema::Member<T,Lit>...>;
};
template<typename... T, string_literal... Lit>
struct meta_schema<schema::Union<schema::Member<T,Lit>...>> {
using MetaSchema = schema::Union<schema::Member<typename meta_schema<T>::MetaSchema,Lit>...>;
using Schema = schema::Union<schema::Member<T,Lit>...>;
};
template<typename... T>
struct meta_schema<schema::Tuple<T...>> {
using MetaSchema = schema::Tuple<typename meta_schema<T>::MetaSchema...>;
using Schema = schema::Tuple<T...>;
};
template<>
struct meta_schema<schema::String> {
using MetaSchema = schema::UInt64;
using Schema = schema::String;
};
/**
* Technically we also can distinguish if T is primitive.
*/
template<typename T, uint64_t Dim>
struct meta_schema<schema::Array<T,Dim>> {
using MetaSchema = schema::FixedArray<schema::UInt64,Dim>;
using Schema = schema::Array<T,Dim>;
};
template<typename T, uint64_t... Dim>
struct meta_schema<schema::FixedArray<T,Dim...>> {
using MetaSchema = schema::Void;
using Schema = schema::FixedArray<T,Dim...>;
};
}
|