diff options
author | Roman Smrž <roman.smrz@seznam.cz> | 2021-04-18 22:25:17 +0200 |
---|---|---|
committer | Roman Smrž <roman.smrz@seznam.cz> | 2021-04-18 22:28:59 +0200 |
commit | 9aaba1211c95dc7e08437a7cca73452181e296d6 (patch) | |
tree | b11cb72c1515fb7b284e98708d6b6f4a8fbae3ab /include/erebos/storage.h | |
parent | c3d6046b25ef0786b8d2919dfa9db4eb05114501 (diff) |
Initial support for FRP behaviors
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() { |