summaryrefslogtreecommitdiff
path: root/modules/codec/c++/schema_factory.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'modules/codec/c++/schema_factory.hpp')
-rw-r--r--modules/codec/c++/schema_factory.hpp29
1 files changed, 27 insertions, 2 deletions
diff --git a/modules/codec/c++/schema_factory.hpp b/modules/codec/c++/schema_factory.hpp
index 8896fdf..6b824f4 100644
--- a/modules/codec/c++/schema_factory.hpp
+++ b/modules/codec/c++/schema_factory.hpp
@@ -11,11 +11,35 @@ struct schema_factory {
template<typename... T, string_literal... Keys>
struct schema_factory<schema::Struct<schema::Member<T,Keys>...>> {
+private:
+public:
using Schema = schema::Struct<schema::Member<T,Keys>...>;
+
+ template<string_literal KA>
+ static constexpr bool has_key() noexcept {
+ return schema_has_key<KA, Schema>::value;
+ }
+
+ template<typename TA, string_literal KA>
+ static constexpr bool has_member() noexcept {
+ return schema_has_member<schema::Member<TA,KA>, Schema>::value;
+ }
+
+ template<typename TA, string_literal KA>
+ constexpr auto add_maybe() const noexcept {
+ if constexpr (!has_key<KA>()) {
+ return schema_factory<schema::Struct<schema::Member<T,Keys>..., schema::Member<TA,KA>>>{};
+ } else if constexpr (has_member<TA,KA>() ){
+ return schema_factory<schema::Struct<schema::Member<T,Keys>...> >{};
+ } else {
+ static_assert(always_false<TA>, "Struct already has the provided Key, but a mismatching Type");
+ }
+ }
template<typename TA, string_literal KA>
constexpr schema_factory<schema::Struct<schema::Member<T,Keys>...,schema::Member<TA,KA>>> add() const noexcept {
- return {};
+ static_assert(!has_key<KA>(), "Can't add member. Name is already in use.");
+ return {};
}
};
@@ -25,7 +49,8 @@ struct schema_factory<schema::Union<schema::Member<T,Keys>...>> {
template<typename TA, string_literal KA>
constexpr schema_factory<schema::Union<schema::Member<T,Keys>...,schema::Member<TA,KA>>> add() const noexcept {
- return {};
+ static_assert(!has_key<KA>(), "Can't add member. Name is already in use.");
+ return {};
}
};