diff options
| author | Dylan <boss@tehbox.org> | 2026-06-06 18:05:19 +1200 |
|---|---|---|
| committer | Dylan <boss@tehbox.org> | 2026-06-06 18:05:19 +1200 |
| commit | 46c896bcd78d31130321562b0659e28230261b8e (patch) | |
| tree | 66174f484693763b7a7ca678fda8ea4b2b98cbe7 /src/json.hpp | |
| download | tehjson-46c896bcd78d31130321562b0659e28230261b8e.tar.gz tehjson-46c896bcd78d31130321562b0659e28230261b8e.zip | |
feat: Initial commit, json data structure and serializing to json
Diffstat (limited to 'src/json.hpp')
| -rw-r--r-- | src/json.hpp | 28 |
1 files changed, 28 insertions, 0 deletions
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 <stdexcept> +#include <iostream> + +namespace TehJSON +{ + + template<typename T> + T& JSON::get() + { + if(!isLeaf) + throw std::runtime_error("Node is not a leaf!"); + + return *static_cast<T*>(data.get()); + } + + template<typename T> + 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<T>; + data = std::make_shared<T>(value); + } + +} |
