diff options
author | Roman Smrž <roman.smrz@seznam.cz> | 2019-12-11 22:14:12 +0100 |
---|---|---|
committer | Roman Smrž <roman.smrz@seznam.cz> | 2019-12-18 22:26:28 +0100 |
commit | d084c069be38b6f3ad74912ca629403d9fdaec58 (patch) | |
tree | 957e9e2340b291cdff6dac60480d1f4060c106a3 /src/storage.cpp | |
parent | 361891f25ca735fd85db64a14823cc55b8a0619a (diff) |
Identity loading and validation
Diffstat (limited to 'src/storage.cpp')
-rw-r--r-- | src/storage.cpp | 17 |
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)) |