From 46c896bcd78d31130321562b0659e28230261b8e Mon Sep 17 00:00:00 2001 From: Dylan Date: Sat, 6 Jun 2026 18:05:19 +1200 Subject: feat: Initial commit, json data structure and serializing to json --- src/json.hpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/json.hpp (limited to 'src/json.hpp') diff --git a/src/json.hpp b/src/json.hpp new file mode 100644 index 0000000..6f19ddd --- /dev/null +++ b/src/json.hpp @@ -0,0 +1,28 @@ +#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 + void JSON::set(T value) + { + if(children.size() != 0) + throw std::runtime_error("Node is not a leaf (has children already)!"); + isLeaf = true; + dataSerializer = JSON::serializeData; + data = std::make_shared(value); + } + +} -- cgit v1.2.3