diff options
author | Roman Smrž <roman.smrz@seznam.cz> | 2021-04-27 22:59:52 +0200 |
---|---|---|
committer | Roman Smrž <roman.smrz@seznam.cz> | 2021-05-08 13:23:34 +0200 |
commit | 567156b05183cc63aedbf57c03f26e0eaf43a39e (patch) | |
tree | 56e4ebf2199bd9539222515885f74856de82459c /include/erebos/state.h | |
parent | a511d2d1ef5fa07dde601961fe9394b474aad5ae (diff) |
SharedState type and lens
Diffstat (limited to 'include/erebos/state.h')
-rw-r--r-- | include/erebos/state.h | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/include/erebos/state.h b/include/erebos/state.h index 7060f22..cfa9532 100644 --- a/include/erebos/state.h +++ b/include/erebos/state.h @@ -8,6 +8,7 @@ namespace erebos { using std::optional; +using std::shared_ptr; using std::vector; class LocalState @@ -42,6 +43,24 @@ private: std::shared_ptr<Priv> p; }; +class SharedState +{ +public: + template<class T> optional<T> get() const; + template<typename T> static T lens(const SharedState &); + + bool operator==(const SharedState &) const; + bool operator!=(const SharedState &) const; + +private: + vector<Ref> lookup(UUID) const; + + struct Priv; + SharedState(shared_ptr<Priv> && p): p(std::move(p)) {} + shared_ptr<Priv> p; + friend class LocalState; +}; + template<class T> optional<T> LocalState::shared() const { @@ -57,4 +76,16 @@ LocalState LocalState::shared(const vector<Stored<T>> & v) const return updateShared(T::sharedTypeId, refs); } +template<class T> +optional<T> SharedState::get() const +{ + return T::load(lookup(T::sharedTypeId)); +} + +template<class T> +T SharedState::lens(const SharedState & x) +{ + return T::value_type::load(x.lookup(T::value_type::sharedTypeId)); +} + } |