From dfce4d0398a8bafbb7ad7a31345af181c0269c09 Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 15 Apr 2021 15:23:23 -0400 Subject: Added spells --- src/jsonable.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/jsonable.h') diff --git a/src/jsonable.h b/src/jsonable.h index 87f3f66..4be2bec 100644 --- a/src/jsonable.h +++ b/src/jsonable.h @@ -1,7 +1,32 @@ #pragma once #include "json.hpp" +#include "utils.h" +#include +#include class Jsonable { public: virtual nlohmann::json toJson(void) const = 0; + operator nlohmann::json() const {return toJson();} }; + +template std::vector json2vec(const nlohmann::json& data) { + using std::begin; using std::end; + return std::vector(begin(data), end(data)); +} + +template std::vector jsonList2vec(const std::string& type, const std::vector& names) { + std::vector ret; + for(auto name : names) { + ret.push_back(utils::loadJson(type, name)); + } + return ret; +} + +template std::vector> json2ptrvec(const nlohmann::json& data) { + std::vector> ret; + for(nlohmann::json d : data) { + ret.push_back(T::create(d)); + } + return ret; +} -- cgit v1.2.3