summaryrefslogtreecommitdiff
path: root/modules/codec/c++/schema.hpp
diff options
context:
space:
mode:
authorClaudius 'keldu' Holeksa <mail@keldu.de>2024-07-17 18:12:49 +0200
committerClaudius 'keldu' Holeksa <mail@keldu.de>2024-07-17 18:12:49 +0200
commite3836bc6ec4439cad648795515feccfb02dd4394 (patch)
tree0dcbf883bc9f1b5f38d5ed39fdb0358199fff937 /modules/codec/c++/schema.hpp
parent28d1ddb50cb1cfdd4b22fd487ceebc0741825cb0 (diff)
Added Ref and Ptr schema types
Diffstat (limited to 'modules/codec/c++/schema.hpp')
-rw-r--r--modules/codec/c++/schema.hpp34
1 files changed, 29 insertions, 5 deletions
diff --git a/modules/codec/c++/schema.hpp b/modules/codec/c++/schema.hpp
index 6a69425..d3c4616 100644
--- a/modules/codec/c++/schema.hpp
+++ b/modules/codec/c++/schema.hpp
@@ -17,10 +17,10 @@ namespace schema {
*/
struct Void {};
-template <typename T, string_literal Literal> struct Member {
+template <typename Schema, string_literal Literal> struct Member {
static constexpr string_literal name = "Member";
- using ValueType = T;
+ using ValueType = Schema;
static constexpr string_literal KeyLiteral = Literal;
};
@@ -30,8 +30,8 @@ template <typename... T> struct Struct {
"This schema template doesn't support this type of template argument");
};
-template <typename... V, string_literal... K>
-struct Struct<Member<V, K>...> {
+template <typename... Schema, string_literal... Key>
+struct Struct<Member<Schema, Key>...> {
static constexpr string_literal name = "Struct";
};
@@ -68,11 +68,35 @@ template <typename... T> struct Tuple {
*
* data<WrappedExample, encode::Json> ex_data;
*/
-template <typename T, typename Enc>
+template <typename Schema, typename Enc>
class Wrapper {
static constexpr string_literal name = "Wrapper";
};
+/**
+ * The schema version of ref<T>.
+ * See the Ptr<T> comment on this.
+ */
+template<typename Schema>
+class Ref {
+ static constexpr string_literal name = "Ref";
+};
+
+/**
+ * The schema version of ptr<T>
+ * It has the advantage that if used in the data class
+ * it won't change the interface of the data instance.
+ * Meaning that data<Ptr<UInt64>> acts as if it's data<UInt64>
+ * in terms of arithmetic operations. It's mostly useful for arrays of primitive types.
+ * In cases where Array<Float64> should be translated to a double*.
+ * In that case we still want the data class as an accesor on the array, so we provide the
+ * data<Ptr<Float64>> type.
+ */
+template<typename Schema>
+class Ptr {
+ static constexpr string_literal name = "Ptr";
+};
+
struct String {
static constexpr string_literal name = "String";
};