diff options
author | Roman Smrž <roman.smrz@seznam.cz> | 2022-12-18 21:33:15 +0100 |
---|---|---|
committer | Roman Smrž <roman.smrz@seznam.cz> | 2022-12-18 21:37:13 +0100 |
commit | 27911e4c08bd97570e528b2f35fe8fb73503c35b (patch) | |
tree | f95ceacd60ba3e88698d5911fae0518018733212 | |
parent | 86293ff20d9f8625615e855d98249175e8cd5cd3 (diff) |
Storage: add Head::reload method
-rw-r--r-- | include/erebos/storage.h | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/include/erebos/storage.h b/include/erebos/storage.h index 62619a2..01aeada 100644 --- a/include/erebos/storage.h +++ b/include/erebos/storage.h @@ -547,6 +547,7 @@ public: const Stored<T> & stored() const { return mstored; } const Ref & ref() const { return mstored.ref(); } + optional<Head<T>> reload() const; 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; @@ -632,6 +633,12 @@ Head<T> Storage::storeHead(const Stored<T> & val) const } template<typename T> +optional<Head<T>> Head<T>::reload() const +{ + return ref().storage().template head<T>(id()); +} + +template<typename T> std::optional<Head<T>> Head<T>::update(const std::function<Stored<T>(const Stored<T> &)> & f) const { auto res = Storage::updateHead(T::headTypeId, mid, ref(), [&f, this](const Ref & r) { @@ -657,7 +664,7 @@ WatchedHead<T> Head<T>::watch(const std::function<void(const Head<T> &)> & watch template<typename T> Bhv<T> Head<T>::behavior() const { - auto cur = ref().storage().template head<T>(id()); + auto cur = reload(); return make_shared<HeadBhv<T>>(cur ? *cur : *this); } |