#pragma once #include "Text.h" #include "Array.h" namespace Framework { namespace JSON { enum JSONType { NULL_, BOOLEAN, NUMBER, STRING, ARRAY, OBJECT }; class JSONArray; class JSONObject; class JSONValue { private: JSONType type; protected: JSONValue( JSONType type ); public: JSONValue(); JSONType getType() const; virtual Text toString() const; }; class JSONBool : public JSONValue { private: bool b; public: JSONBool( bool b ); bool getBool() const; Text toString() const override; }; class JSONNumber : public JSONValue { private: double number; public: JSONNumber( double num ); double getNumber() const; Text toString() const override; }; class JSONString : public JSONValue { private: Text string; public: JSONString( Text string ); Text getString() const; Text toString() const override; }; class JSONArray : public JSONValue { private: Array< JSONValue > *array; public: JSONArray(); JSONArray( Text string ); JSONArray( const JSONArray &arr ); ~JSONArray(); JSONArray &operator=( const JSONArray &arr ); void addValue( JSONValue value ); JSONValue getValue( int i ) const; int getLength() const; Text toString() const override; }; class JSONObject : public JSONValue { private: Array< Text > *fields; Array< JSONValue > *values; public: JSONObject(); JSONObject( Text string ); JSONObject( const JSONObject &obj ); ~JSONObject(); JSONObject &operator=( const JSONObject &obj ); bool addValue( Text field, JSONValue value ); bool removeValue( Text field ); bool hasValue( Text field ); JSONValue getValue( Text field ); Iterator< Text > getFields(); Iterator< JSONValue > getValues(); Text toString() const override; }; namespace Parser { int findObjectEndInArray( const char *str ); Text removeWhitespace( const char *str ); JSONValue getValue( const char *str ); int findFieldEndInObject( const char *str ); int findValueEndInObject( const char *str ); }; } }