forstio/source/forstio/schema.h

52 lines
1.3 KiB
C
Raw Permalink Normal View History

2021-11-11 00:20:21 +01:00
#pragma once
2021-11-29 15:08:18 +01:00
#include "string_literal.h"
2021-11-12 18:31:18 +01:00
2021-12-29 19:26:22 +01:00
namespace saw {
2021-11-11 00:20:21 +01:00
namespace schema {
2021-11-29 15:08:18 +01:00
template <class T, StringLiteral Literal> struct NamedMember {};
2021-11-12 18:31:18 +01:00
2021-12-12 12:17:10 +01:00
template <class... T> struct Struct;
2021-11-12 18:31:18 +01:00
2021-12-18 17:26:14 +01:00
template <class... V, StringLiteral... K>
struct Struct<NamedMember<V, K>...> {};
2021-11-12 18:31:18 +01:00
2021-12-12 12:17:10 +01:00
template <class... T> struct Union;
2021-11-12 18:31:18 +01:00
2021-12-18 17:26:14 +01:00
template <class... V, StringLiteral... K> struct Union<NamedMember<V, K>...> {};
2021-11-11 00:20:21 +01:00
2021-12-12 12:17:10 +01:00
template <class T> struct Array {};
template <class... T> struct Tuple {};
2021-11-11 00:20:21 +01:00
struct String {};
2021-11-29 15:08:18 +01:00
struct SignedInteger {};
struct UnsignedInteger {};
2021-11-29 15:08:18 +01:00
struct FloatingPoint {};
2021-12-05 16:17:23 +01:00
template <class T, size_t N> struct Primitive {
static_assert(((std::is_same_v<T, SignedInteger> ||
std::is_same_v<T, UnsignedInteger>)&&(N == 1 || N == 2 ||
N == 4 || N == 8)) ||
2021-12-05 16:17:23 +01:00
(std::is_same_v<T, FloatingPoint> && (N == 4 || N == 8)),
"Primitive Type is not supported");
2021-11-29 15:08:18 +01:00
};
using Int8 = Primitive<SignedInteger, 1>;
using Int16 = Primitive<SignedInteger, 2>;
using Int32 = Primitive<SignedInteger, 4>;
using Int64 = Primitive<SignedInteger, 8>;
2021-11-29 15:08:18 +01:00
using UInt8 = Primitive<UnsignedInteger, 1>;
using UInt16 = Primitive<UnsignedInteger, 2>;
using UInt32 = Primitive<UnsignedInteger, 4>;
using UInt64 = Primitive<UnsignedInteger, 8>;
2021-11-29 15:08:18 +01:00
using Float32 = Primitive<FloatingPoint, 4>;
using Float64 = Primitive<FloatingPoint, 8>;
2021-11-12 18:31:18 +01:00
} // namespace schema
2021-12-29 19:26:22 +01:00
} // namespace saw