summaryrefslogtreecommitdiff
path: root/src/storage.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/storage.cpp')
-rw-r--r--src/storage.cpp17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/storage.cpp b/src/storage.cpp
index 2e7feb7..d549959 100644
--- a/src/storage.cpp
+++ b/src/storage.cpp
@@ -22,6 +22,7 @@ using std::copy;
using std::holds_alternative;
using std::ifstream;
using std::make_shared;
+using std::monostate;
using std::nullopt;
using std::runtime_error;
using std::shared_ptr;
@@ -268,6 +269,11 @@ const Object * Ref::operator->() const
}
+Record::Item::operator bool() const
+{
+ return !holds_alternative<monostate>(value);
+}
+
optional<int> Record::Item::asInteger() const
{
if (holds_alternative<int>(value))
@@ -351,16 +357,16 @@ const vector<Record::Item> & Record::items() const
return *ptr;
}
-optional<Record::Item> Record::item(const string & name) const
+Record::Item Record::item(const string & name) const
{
for (auto item : *ptr) {
if (item.name == name)
return item;
}
- return nullopt;
+ return Item("", monostate());
}
-optional<Record::Item> Record::operator[](const string & name) const
+Record::Item Record::operator[](const string & name) const
{
return item(name);
}
@@ -486,6 +492,11 @@ vector<uint8_t> Object::encode() const
return res;
}
+optional<Object> Object::load(const Ref & ref)
+{
+ return *ref;
+}
+
optional<Record> Object::asRecord() const
{
if (holds_alternative<Record>(content))