#pragma once #include "tokenizer.h" #include #include #include #include #include namespace TehJSON { class JSON { public: JSON(); JSON(const JSON& other) = default; ~JSON(); // Writing methods std::string getSerialized(); std::string _getSerialized(int currIndent); // Reading methods void readFromString(std::string s); // Leaf methods template T& get(); template void set(T value); std::string leafType(); template static std::string serializeData(std::shared_ptr data); // Non leaf methods JSON& operator[](std::string name); size_t childCount(); // std::vector childNames(); private: bool isLeaf = false; // Reading data fields std::vector tokens; int tokenPos = 0; Token consume(); Token consume(TokenType type); TokenType nextTokenType(); int readFromTokens(std::vector tokens, int pos); // Leaf data fields std::shared_ptr data; std::string (*dataSerializer)(std::shared_ptr); // Not leaf data fields std::map children; }; }