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.h | |
| download | tehjson-46c896bcd78d31130321562b0659e28230261b8e.tar.gz tehjson-46c896bcd78d31130321562b0659e28230261b8e.zip | |
feat: Initial commit, json data structure and serializing to json
Diffstat (limited to 'src/json.h')
| -rw-r--r-- | src/json.h | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/json.h b/src/json.h new file mode 100644 index 0000000..d1d7938 --- /dev/null +++ b/src/json.h @@ -0,0 +1,40 @@ +#include <cstddef> +#include <map> +#include <memory> +#include <string> + +namespace TehJSON +{ + class JSON + { + public: + JSON(); + JSON(const JSON& other) = default; + ~JSON(); + + // Leaf methods + template <typename T> + T& get(); + template <typename T> + void set(T value); + std::string leafType(); + std::string getSerialized(); + std::string _getSerialized(int currIndent); + template <typename T> + static std::string serializeData(std::shared_ptr<void> data); + + // Non leaf methods + JSON& operator[](std::string name); + size_t childCount(); + // std::vector<std::string> childNames(); + private: + bool isLeaf = false; + + // Leaf data fields + std::shared_ptr<void> data; + std::string (*dataSerializer)(std::shared_ptr<void>); + + // Not leaf data fields + std::map<std::string, JSON> children; + }; +} |
