From e827200803c1421777c14c62a1b9edf7e139e6c0 Mon Sep 17 00:00:00 2001 From: Claudius 'keldu' Holeksa Date: Thu, 15 Aug 2024 17:15:16 +0200 Subject: Partially fixed map --- modules/codec/c++/data.hpp | 58 +++++++++++++++++++++++++++++++++++++++ modules/codec/c++/schema_meta.hpp | 12 ++++++++ 2 files changed, 70 insertions(+) (limited to 'modules/codec/c++') diff --git a/modules/codec/c++/data.hpp b/modules/codec/c++/data.hpp index e955af0..78fef35 100644 --- a/modules/codec/c++/data.hpp +++ b/modules/codec/c++/data.hpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -481,6 +482,47 @@ public: } }; +template +class data, encode::Native> { +public: + using Schema = schema::Map; + using MetaSchema = typename meta_schema::MetaSchema; +private: + std::map, data> vals_; +public: + data() = default; + + SAW_DEFAULT_COPY(data); + SAW_DEFAULT_MOVE(data); + + data(data init){} + + error_or emplace(ref> key, ref> value){ + auto insert = vals_.emplace(std::make_pair(std::move(key()), std::move(value()))); + if(!insert.second){ + return make_error(); + } + return make_void(); + } + + error_or erase(ref> key){ + auto erase = vals_.erase(key()); + if(erase == 0u){ + return make_error(); + } + return make_void(); + } + + error_or>> find(ref> key){ + auto find = vals_.find(key()); + if(find == vals_.end()){ + return make_error(); + } + + return ptr>{find->second}; + } +}; + template class data, encode::Native, storage::Default> { public: @@ -766,6 +808,22 @@ public: value_.at(i) = val; } + std::string_view stl_view() { + return value_; + } + + template + bool operator==(const data& rhs){ + if(size() != rhs.size()){ + return false; + } + bool eq = true; + for(uint64_t i = 0; i < size(); ++i){ + eq = eq && (get_at(i) == rhs.get_at(i)); + } + return eq; + } + /** * Check if a string_view is equal to this type. */ diff --git a/modules/codec/c++/schema_meta.hpp b/modules/codec/c++/schema_meta.hpp index a37197a..9b111e3 100644 --- a/modules/codec/c++/schema_meta.hpp +++ b/modules/codec/c++/schema_meta.hpp @@ -15,6 +15,12 @@ struct meta_schema { using MetaSchema = schema::Void; }; +template<> +struct meta_schema { + using Schema = schema::Bool; + using MetaSchema = schema::Void; +}; + template struct meta_schema> { using MetaSchema = schema::Void; @@ -27,6 +33,12 @@ struct meta_schema, schema::Prim using MetaSchema = schema::Void; }; +template +struct meta_schema> { + using MetaSchema = schema::Void; + using Schema = schema::Map; +}; + template struct meta_schema...>> { using MetaSchema = schema::Struct::MetaSchema,Lit>...>; -- cgit v1.2.3