diff options
author | Your Name <you@example.com> | 2021-05-05 09:44:50 -0400 |
---|---|---|
committer | Your Name <you@example.com> | 2021-05-05 09:44:50 -0400 |
commit | 2a9f262e6db5906db445d465e500d7ba8c90fab3 (patch) | |
tree | 34f850754b0c9114ede9d7b2bb8da90dffddc4fe /src/jsonable.h | |
parent | 8614137f7f32f2c9f3c11419110cd70dd7f3b505 (diff) | |
download | dmtool-2a9f262e6db5906db445d465e500d7ba8c90fab3.tar.gz dmtool-2a9f262e6db5906db445d465e500d7ba8c90fab3.tar.bz2 dmtool-2a9f262e6db5906db445d465e500d7ba8c90fab3.zip |
Implemented additional commands
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; +} |