summaryrefslogtreecommitdiff
path: root/include/erebos/storage.h
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2020-04-16 21:42:45 +0200
committerRoman Smrž <roman.smrz@seznam.cz>2020-04-16 21:42:45 +0200
commit6cf5244bc514042fe419fffe1cd26a7f5e3c778f (patch)
tree4a72abf80980c3d10656bd82606a69329867d057 /include/erebos/storage.h
parenta76a9ad65fa549d2c1650bb5a7d9a657186edc43 (diff)
Remove optional from load result
Makes loading of data well-defined for arbitrary object contents. Introduce zero reference and object to represent missing or mismatched parts.
Diffstat (limited to 'include/erebos/storage.h')
-rw-r--r--include/erebos/storage.h16
1 files changed, 9 insertions, 7 deletions
diff --git a/include/erebos/storage.h b/include/erebos/storage.h
index d5ae45a..d46c056 100644
--- a/include/erebos/storage.h
+++ b/include/erebos/storage.h
@@ -72,6 +72,7 @@ public:
PartialStorage derivePartialStorage() const;
std::optional<Ref> ref(const Digest &) const;
+ Ref zref() const;
std::optional<Object> loadObject(const Digest &) const;
Ref storeObject(const Object &) const;
@@ -103,6 +104,7 @@ public:
explicit Digest(std::array<uint8_t, size> value): value(value) {}
explicit Digest(const std::string &);
explicit operator std::string() const;
+ bool isZero() const;
const std::array<uint8_t, size> & arr() const { return value; }
@@ -151,6 +153,7 @@ public:
Ref & operator=(Ref &&) = default;
static std::optional<Ref> create(Storage, const Digest &);
+ static Ref zcreate(Storage);
constexpr operator bool() const { return true; }
const Object operator*() const;
@@ -265,7 +268,8 @@ class ObjectT
public:
typedef std::variant<
RecordT<S>,
- Blob> Variants;
+ Blob,
+ std::monostate> Variants;
ObjectT(const ObjectT<S> &) = default;
ObjectT(Variants content): content(content) {}
@@ -282,7 +286,7 @@ public:
std::vector<uint8_t>::const_iterator);
static std::vector<ObjectT<S>> decodeMany(const S &, const std::vector<uint8_t> &);
std::vector<uint8_t> encode() const;
- static std::optional<ObjectT<S>> load(const typename S::Ref &);
+ static ObjectT<S> load(const typename S::Ref &);
std::optional<RecordT<S>> asRecord() const;
std::optional<Blob> asBlob() const;
@@ -317,7 +321,7 @@ public:
Stored & operator=(const Stored &) = default;
Stored & operator=(Stored &&) = default;
- static std::optional<Stored<T>> load(const Ref &);
+ static Stored<T> load(const Ref &);
Ref store(const Storage &) const;
bool operator==(const Stored<T> & other) const
@@ -354,11 +358,9 @@ Stored<T> Storage::store(const T & val) const
}
template<typename T>
-std::optional<Stored<T>> Stored<T>::load(const Ref & ref)
+Stored<T> Stored<T>::load(const Ref & ref)
{
- if (auto val = T::load(ref))
- return Stored(ref, std::make_shared<T>(val.value()));
- return std::nullopt;
+ return Stored(ref, std::make_shared<T>(T::load(ref)));
}
template<typename T>