diff options
Diffstat (limited to 'src/jsonable.h')
-rw-r--r-- | src/jsonable.h | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/jsonable.h b/src/jsonable.h index 2c0da6b..0385fb1 100644 --- a/src/jsonable.h +++ b/src/jsonable.h @@ -16,11 +16,11 @@ template<typename T> std::vector<T> json2vec(const nlohmann::json& data) { return std::vector<T>(begin(data), end(data)); } -template<typename T> std::vector<T> jsonList2vec(const std::string& type, const std::vector<std::string>& names) { - std::vector<T> ret; +template<typename T> std::vector<std::shared_ptr<T>> jsonList2ptrvec(const std::string& type, const std::vector<std::string>& names) { + std::vector<std::shared_ptr<T>> ret; for(auto name : names) { auto j = utils::loadJson(type, name); - ret.push_back(T(j, j)); + ret.push_back(std::shared_ptr<T>(new T(j, j))); } return ret; } @@ -32,3 +32,11 @@ template<typename T> std::vector<std::shared_ptr<T>> json2ptrvec(const nlohmann: } return ret; } + +template<typename T> std::vector<nlohmann::json> ptrvec2json(std::vector<T> src) { + std::vector<nlohmann::json> ret; + for(T i : src) { + ret.push_back(i->toJson()); + } + return ret; +} |