summaryrefslogtreecommitdiff
path: root/modules/codec/c++/schema_stringify.hpp
blob: 797823a6c9e07aef344752db84bfbfc0cc32bd9c (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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#pragma once

#include "schema.hpp"

#include <sstream>
#include <type_traits>

namespace saw {
template<typename Schema>
struct schema_stringify {
		static_assert(always_false<Schema>, "Not supported");
};

template<typename T, size_t Dim>
struct schema_stringify<schema::Array<T,Dim>> {
		static void apply(std::stringstream& iss) {
				iss << "saw::schema::Array<";
				schema_stringify<T>::apply(iss);
				iss << ",";
				iss << ct_convert_to_digits<Dim, 10>::literal.view();
				iss << ">";
		}
};

template<typename T, size_t N>
struct schema_stringify<schema::Primitive<T,N>> {
		static void apply(std::stringstream& iss) {
				iss << "saw::schema::Primitive<";
				schema_stringify<T>::apply(iss);
				iss << ",";
				iss << ct_convert_to_digits<N,10>::literal.view();
				iss << ">";
		}
};

template<>
struct schema_stringify<schema::SignedInteger> {
		static void apply(std::stringstream& iss) {
				iss << "saw::schema::SignedInteger";
		}
};

template<>
struct schema_stringify<schema::UnsignedInteger> {
		static void apply(std::stringstream& iss) {
				iss << "saw::schema::UnsignedInteger";
		}
};

template<>
struct schema_stringify<schema::FloatingPoint> {
		static void apply(std::stringstream& iss) {
				iss << "saw::schema::FloatingPoint";
		}
};

template<typename... T>
struct schema_stringify_member {
		static void apply(std::stringstream& iss) {
				(void)iss;
		}
};

template<typename T0, string_literal Name, typename... TL>
struct schema_stringify_member<schema::Member<T0,Name>, TL...> {

		static void apply(std::stringstream& iss) {
				iss << "saw::schema::Member<";
				schema_stringify<T0>::apply(iss);
				iss << ",\"";
				iss << Name.view();
				iss << "\">";
				if constexpr ( sizeof...(TL) > 0){
						iss << ",";
						schema_stringify_member<TL...>::apply(iss);
				}
		}
};

template<typename... T, string_literal... Lits>
struct schema_stringify<schema::Struct<schema::Member<T,Lits>...>> {
		static void apply(std::stringstream& iss) {
				iss << "saw::schema::Struct<";
				schema_stringify_member<schema::Member<T,Lits>...>::apply(iss);
				iss << ">";
		}
};

template<typename... T, string_literal... Lits>
struct schema_stringify<schema::Union<schema::Member<T,Lits>...>> {
		static void apply(std::stringstream& iss) {
				iss << "saw::schema::Union<";
				schema_stringify_member<schema::Member<T,Lits>...>::apply(iss);
				iss << ">";
		}
};

template<typename Req, typename Resp>
struct schema_stringify<schema::Function<Req, Resp>> {
		static void apply(std::stringstream& iss){
				iss << "saw::schema::Function<";
				schema_stringify<Req>::apply(iss);
				iss << ",";
				schema_stringify<Resp>::apply(iss);
				iss << ">";
		}
};

template<typename... T, string_literal... Lits>
struct schema_stringify<schema::Interface<schema::Member<T,Lits>...>>{
		static void apply(std::stringstream& iss){
				iss << "saw::schema::Interface<";
				schema_stringify_member<schema::Member<T,Lits>...>::apply(iss);
				iss << ">";
		}
};

}