From 9aaba1211c95dc7e08437a7cca73452181e296d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Sun, 18 Apr 2021 22:25:17 +0200 Subject: Initial support for FRP behaviors --- include/erebos/storage.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'include/erebos/storage.h') 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 #include #include @@ -496,6 +497,8 @@ public: std::optional> update(const std::function(const Stored &)> &) const; WatchedHead watch(const std::function &)> &) const; + Bhv behavior() const; + private: UUID mid; Stored mstored; @@ -526,6 +529,23 @@ public: ~WatchedHead(); }; +template +class HeadBhv : public BhvSource +{ +public: + HeadBhv(const Head & head): + whead(head.watch([this] (const Head & cur) { + BhvCurTime ctime; + whead = cur; + BhvImplBase::updated(ctime); + })) {} + + T get(const BhvCurTime &, const std::monostate &) const { return *whead; } + +private: + WatchedHead whead; +}; + template std::optional> Storage::head(UUID id) const { @@ -583,6 +603,12 @@ WatchedHead Head::watch(const std::function &)> & watch return WatchedHead(*this, wid); } +template +Bhv Head::behavior() const +{ + return make_shared>(*this); +} + template WatchedHead::~WatchedHead() { -- cgit v1.2.3