diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-04-17 21:41:26 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-11-07 16:41:37 +0000 |
commit | 71c5280bc6393669777147b5036dc510e74d93c4 (patch) | |
tree | 4efcc41b8d87f2c4a0dff3b6ad852bdaf809f514 /lib/persistance.cpp | |
parent | Initial commit of basis persistence (diff) | |
download | ilt-71c5280bc6393669777147b5036dc510e74d93c4.tar.bz2 ilt-71c5280bc6393669777147b5036dc510e74d93c4.tar.xz ilt-71c5280bc6393669777147b5036dc510e74d93c4.zip |
Second swing persistance
Mostly functional JSON deserialising for most types.
Diffstat (limited to 'lib/persistance.cpp')
-rw-r--r-- | lib/persistance.cpp | 74 |
1 files changed, 74 insertions, 0 deletions
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 <map> + +namespace Persistanace { + using NamedTypeFactories = std::map<std::string_view, std::function<std::unique_ptr<Persistable>()>>; + static NamedTypeFactories namedTypeFactories; + + void + Persistable::addFactory(const std::string_view t, std::function<std::unique_ptr<Persistable>()> f) + { + namedTypeFactories.emplace(t, std::move(f)); + } + + std::unique_ptr<Persistable> + 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<float>::ArrayLike); + static_assert(!SelectionT<bool>::ArrayLike); + static_assert(!SelectionT<std::string>::ArrayLike); + static_assert(SelectionT<std::vector<float>>::ArrayLike); + static_assert(SelectionT<glm::vec3>::ArrayLike); + static_assert(SelectionT<std::vector<glm::vec3>>::ArrayLike); +} |