diff options
author | Claudius "keldu" Holeksa <mail@keldu.de> | 2023-07-20 17:02:05 +0200 |
---|---|---|
committer | Claudius "keldu" Holeksa <mail@keldu.de> | 2023-07-20 17:02:05 +0200 |
commit | fac9e8bec1983fa9dff8f447fef106e427dfec26 (patch) | |
tree | 2221d4216873fa8250dd5ff45f00d0d6b46eab26 /c++/codec/schema.h | |
parent | 398164432abcf599eaa51ebc4088024b7f46b97f (diff) |
c++: Renamed src to c++
Diffstat (limited to 'c++/codec/schema.h')
-rw-r--r-- | c++/codec/schema.h | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/c++/codec/schema.h b/c++/codec/schema.h new file mode 100644 index 0000000..2f63fe9 --- /dev/null +++ b/c++/codec/schema.h @@ -0,0 +1,93 @@ +#pragma once + +#include <forstio/core/common.h> +#include <forstio/core/string_literal.h> + +namespace saw { +namespace schema { +// NOLINTBEGIN +template <typename T, string_literal Literal> struct Member {}; + +template <typename... T> struct Struct { + static_assert( + always_false<T...>, + "This schema template doesn't support this type of template argument"); +}; + +template <typename... V, string_literal... K> +struct Struct<Member<V, K>...> {}; + +template <typename... T> struct Union { + static_assert( + always_false<T...>, + "This schema template doesn't support this type of template argument"); +}; + +template <typename... V, string_literal... K> +struct Union<Member<V, K>...> {}; + +template <typename T, size_t Dim = 1> struct Array {}; + +template <class T> struct is_array { + constexpr static bool value = false; +}; + +template <class T, size_t Dim> struct is_array<schema::Array<T,Dim>> { + constexpr static bool value = true; +}; + +template<typename T, size_t... S> struct FixedArray {}; + +template <typename... T> struct Tuple {}; + +/** + * This acts as a separator of different encodings being mashed together + */ +template <typename T, typename Enc> +class Wrapper {}; + +struct String {}; + +struct SignedInteger {}; +struct UnsignedInteger {}; +struct FloatingPoint {}; + +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)) || + (std::is_same_v<T, FloatingPoint> && (N == 4 || N == 8)), + "Primitive Type is not supported"); +}; + +using Int8 = Primitive<SignedInteger, 1>; +using Int16 = Primitive<SignedInteger, 2>; +using Int32 = Primitive<SignedInteger, 4>; +using Int64 = Primitive<SignedInteger, 8>; + +using UInt8 = Primitive<UnsignedInteger, 1>; +using UInt16 = Primitive<UnsignedInteger, 2>; +using UInt32 = Primitive<UnsignedInteger, 4>; +using UInt64 = Primitive<UnsignedInteger, 8>; + +using Float32 = Primitive<FloatingPoint, 4>; +using Float64 = Primitive<FloatingPoint, 8>; + +/** + * Classes enabling Rpc calls + */ +template <class Request, class Response, string_literal Literal> +struct Function {}; + +template <class... T> struct Interface { + static_assert( + always_false<T...>, + "This schema template doesn't support this type of template argument"); +}; + +template <class... Request, class... Response, string_literal... Literal> +struct Interface<Function<Request, Response, Literal>...> {}; + +// NOLINTEND +} // namespace schema +} // namespace saw |