summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/erebos/state.h31
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));
+}
+
}