Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string>
- #include <vector>
- #include <map>
- enum Type {
- object,
- array,
- string,
- number,
- boolean,
- null
- };
- class Value {
- public:
- virtual ~Value() = 0;
- Type getType();
- virtual std::string toString() const = 0;
- virtual Value* parse(const std::string& jsonString) = 0;
- };
- class JSONString : public Value {
- public:
- JSONString(std::string value);
- ~JSONString();
- std::string getValue();
- std::string toString() const override;
- JSONString* parse(const std::string& json_string) override;
- };
- class JSONNumber : public Value {
- public:
- JSONNumber(double value);
- ~JSONNumber();
- double getValue();
- std::string toString() const override;
- JSONNumber* parse(const std::string& json_string) override;
- };
- class JSONBoolean : public Value {
- public:
- JSONBoolean(bool value);
- ~JSONBoolean();
- bool getValue();
- std::string toString() const override;
- JSONBoolean* parse(const std::string& json_string) override;
- };
- class JSONArray : public Value {
- private:
- std::vector<const Value*> values;
- public:
- JSONArray();
- ~JSONArray();
- std::vector<const Value*> getValues();
- std::string toString() const override;
- JSONArray* parse(const std::string& json_string) override;
- void add(const Value* value);
- const Value* operator[](int index);
- };
- class JSONObject : public Value {
- private:
- std::map<std::string, const Value*> values;
- public:
- JSONObject();
- ~JSONObject();
- std::map<std::string, const Value*> getValues();
- std::string toString() const override;
- JSONObject* parse(const std::string& json_string) override;
- void add(const std::string& key, const Value* value);
- const Value* operator[](const std::string key);
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement