#include "json.h" #include #include namespace TehJSON { template T& JSON::get() { if(!isLeaf) throw std::runtime_error("Node is not a leaf!"); return *static_cast(data.get()); } template std::string TehJSON::JSON::serializeData(std::vector* data) { std::string res = "["; for(int i = 0; i < data->size(); i++) { T x = data->at(i); // res += "inty"; res += TehJSON::JSON::serializeData(&x); if(i != data->size() - 1) res += ", "; } res += "]"; return res; } template void TehJSON::JSON::set(std::vector value) { if(children.size() != 0) throw std::runtime_error("Node is not a leaf (has children already)!"); isLeaf = true; dataSerializer = [](std::shared_ptr data) -> std::string { return TehJSON::JSON::serializeData((std::vector*)(data.get())); }; data = std::make_shared>(value); } template void JSON::set(T value) { if(children.size() != 0) throw std::runtime_error("Node is not a leaf (has children already)!"); isLeaf = true; dataSerializer = [](std::shared_ptr data) -> std::string { return JSON::serializeData((T*)(data.get())); }; data = std::make_shared(value); } }