From 71c5280bc6393669777147b5036dc510e74d93c4 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 17 Apr 2021 21:41:26 +0100 Subject: Second swing persistance Mostly functional JSON deserialising for most types. --- lib/persistance.cpp | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 lib/persistance.cpp (limited to 'lib/persistance.cpp') diff --git a/lib/persistance.cpp b/lib/persistance.cpp new file mode 100644 index 0000000..7539b44 --- /dev/null +++ b/lib/persistance.cpp @@ -0,0 +1,74 @@ +#include "persistance.h" +#include + +namespace Persistanace { + using NamedTypeFactories = std::map()>>; + static NamedTypeFactories namedTypeFactories; + + void + Persistable::addFactory(const std::string_view t, std::function()> f) + { + namedTypeFactories.emplace(t, std::move(f)); + } + + std::unique_ptr + Persistable::callFactory(const std::string_view t) + { + return namedTypeFactories.at(t)(); + } + + void + Selection::operator()(float &) + { + throw std::runtime_error("Unexpected float"); + } + + void + Selection::operator()(bool &) + { + throw std::runtime_error("Unexpected bool"); + } + + void + Selection::operator()(const std::nullptr_t &) + { + throw std::runtime_error("Unexpected null"); + } + + void + Selection::operator()(std::string &) + { + throw std::runtime_error("Unexpected string"); + } + + void + Selection::BeginArray(Stack &) + { + throw std::runtime_error("Unexpected array"); + } + + SelectionPtr + Selection::BeginObject() + { + throw std::runtime_error("Unexpected object"); + } + + void + Selection::beforeValue(Stack &) + { + throw std::runtime_error("Unexpected value"); + } + + SelectionPtr + Selection::select(const std::string &) + { + throw std::runtime_error("Unexpected persist"); + } + + static_assert(!SelectionT::ArrayLike); + static_assert(!SelectionT::ArrayLike); + static_assert(!SelectionT::ArrayLike); + static_assert(SelectionT>::ArrayLike); + static_assert(SelectionT::ArrayLike); + static_assert(SelectionT>::ArrayLike); +} -- cgit v1.2.3