diff options
Diffstat (limited to 'include/erebos/storage.h')
-rw-r--r-- | include/erebos/storage.h | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/include/erebos/storage.h b/include/erebos/storage.h index 7ec73ab..2d00cc3 100644 --- a/include/erebos/storage.h +++ b/include/erebos/storage.h @@ -1,5 +1,6 @@ #pragma once +#include <erebos/frp.h> #include <erebos/time.h> #include <erebos/uuid.h> @@ -496,6 +497,8 @@ public: std::optional<Head<T>> update(const std::function<Stored<T>(const Stored<T> &)> &) const; WatchedHead<T> watch(const std::function<void(const Head<T> &)> &) const; + Bhv<T> behavior() const; + private: UUID mid; Stored<T> mstored; @@ -526,6 +529,23 @@ public: ~WatchedHead(); }; +template<class T> +class HeadBhv : public BhvSource<T> +{ +public: + HeadBhv(const Head<T> & head): + whead(head.watch([this] (const Head<T> & cur) { + BhvCurTime ctime; + whead = cur; + BhvImplBase::updated(ctime); + })) {} + + T get(const BhvCurTime &, const std::monostate &) const { return *whead; } + +private: + WatchedHead<T> whead; +}; + template<typename T> std::optional<Head<T>> Storage::head(UUID id) const { @@ -583,6 +603,12 @@ WatchedHead<T> Head<T>::watch(const std::function<void(const Head<T> &)> & watch return WatchedHead<T>(*this, wid); } +template<typename T> +Bhv<T> Head<T>::behavior() const +{ + return make_shared<HeadBhv<T>>(*this); +} + template<class T> WatchedHead<T>::~WatchedHead() { |