| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- //
- // jsonizer_ios.tpp
- // serializer
- //
- // Created by Sam Jaffe on 3/18/23.
- //
- #include <fstream>
- #include <sstream>
- #include <json/json.h>
- #include <serializer/jsonizer.h>
- namespace serializer {
- template <typename T> T Jsonizer::from_json(Json::Value const & json) const {
- std::decay_t<T> tmp;
- from_json(tmp, json);
- return tmp;
- }
- template <typename T> T Jsonizer::from_stream(std::istream & in) const {
- Json::Value root;
- in >> root;
- return from_json<T>(root);
- }
- template <typename T> T Jsonizer::from_string(std::string const & in) const {
- std::stringstream ss;
- ss << in;
- return from_stream<T>(ss);
- }
- template <typename T>
- void Jsonizer::to_stream(T const & value, std::ostream & out) const {
- Json::Value root = to_json(value);
- out << root;
- }
- template <typename T> T Jsonizer::from_file(std::string const & file) const {
- std::ifstream in(file);
- return from_stream<T>(in);
- }
- }
|