summaryrefslogtreecommitdiff
path: root/lib/persistence.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2021-05-08 20:16:32 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2021-11-07 16:41:37 +0000
commit112c02f40806f550370b3928f3c1965b5bee5262 (patch)
treedcee2ff5f436522f498e751e1c317145135f46e7 /lib/persistence.cpp
parentImport setValue, silence clang warning (diff)
downloadilt-112c02f40806f550370b3928f3c1965b5bee5262.tar.bz2
ilt-112c02f40806f550370b3928f3c1965b5bee5262.tar.xz
ilt-112c02f40806f550370b3928f3c1965b5bee5262.zip
Implement writing shared objects with @id
Diffstat (limited to 'lib/persistence.cpp')
-rw-r--r--lib/persistence.cpp56
1 files changed, 56 insertions, 0 deletions
diff --git a/lib/persistence.cpp b/lib/persistence.cpp
index 4f1be8f..b85bff2 100644
--- a/lib/persistence.cpp
+++ b/lib/persistence.cpp
@@ -1,5 +1,6 @@
#include "persistence.h"
#include <map>
+#include <sstream>
namespace Persistence {
using Factories
@@ -26,6 +27,61 @@ namespace Persistence {
return namedTypeFactories.at(t).second();
}
+ [[nodiscard]] std::string
+ Persistable::getId() const
+ {
+ std::stringstream ss;
+ ss << std::hex << this;
+ return ss.str();
+ }
+
+ PersistenceSelect::PersistenceSelect(const std::string & n) : name {n} { }
+
+ PersistenceStore::NameAction
+ PersistenceSelect::setName(const std::string_view key)
+ {
+ return (key == name) ? NameAction::Push : NameAction::Ignore;
+ }
+
+ void
+ PersistenceSelect::setType(const std::string_view, const Persistable *)
+ {
+ }
+
+ PersistenceWrite::PersistenceWrite(const Writer & o, bool sh) : out {o}, shared {sh} { }
+
+ PersistenceStore::NameAction
+ PersistenceWrite::setName(const std::string_view key)
+ {
+ if (!first) {
+ out.nextValue();
+ }
+ else {
+ first = false;
+ }
+ out.pushKey(key);
+ return NameAction::HandleAndContinue;
+ }
+
+ void
+ PersistenceWrite::selHandler()
+ {
+ this->sel->write(out);
+ };
+
+ void
+ PersistenceWrite::setType(const std::string_view tn, const Persistable * p)
+ {
+ out.pushKey("@typeid");
+ out.pushValue(tn);
+ first = false;
+ if (shared) {
+ out.nextValue();
+ out.pushKey("@id");
+ out.pushValue(p->getId());
+ }
+ }
+
void
Selection::setValue(float)
{