Compare commits

...

1 Commits

Author SHA1 Message Date
Vitaliy Filippov dcb1e476c3 Mutable v3 2022-03-13 12:36:46 +03:00
2 changed files with 13 additions and 13 deletions

View File

@ -156,7 +156,7 @@ protected:
return m_value < static_cast<const Value<tag, T> *>(other)->m_value;
}
const T m_value;
T m_value;
void dump(string &out) const override { json11::dump(m_value, out); }
};
@ -236,7 +236,7 @@ public:
};
class JsonArray final : public Value<Json::ARRAY, Json::array> {
const Json::array &array_items() const override { return m_value; }
Json::array &array_items() override { return m_value; }
const Json & operator[](size_t i) const override;
public:
explicit JsonArray(const Json::array &value) : Value(value) {}
@ -244,7 +244,7 @@ public:
};
class JsonObject final : public Value<Json::OBJECT, Json::object> {
const Json::object &object_items() const override { return m_value; }
Json::object &object_items() override { return m_value; }
const Json & operator[](const string &key) const override;
public:
explicit JsonObject(const Json::object &value) : Value(value) {}
@ -320,12 +320,12 @@ Json::Json(Json::object &&values) : m_ptr(make_shared<JsonObject>(move(valu
Json::Type Json::type() const { return m_ptr->type(); }
double Json::number_value() const { return m_ptr->number_value(); }
int64_ Json::int64_value() const { return m_ptr->int64_value(); }
uint64_ Json::uint64_value() const { return m_ptr->uint64_value(); }
uint64_ Json::uint64_value() const { return m_ptr->uint64_value(); }
bool Json::bool_value() const { return m_ptr->bool_value(); }
string Json::as_string() const { return m_ptr->as_string(); }
const string & Json::string_value() const { return m_ptr->string_value(); }
const vector<Json> & Json::array_items() const { return m_ptr->array_items(); }
const map<string, Json> & Json::object_items() const { return m_ptr->object_items(); }
vector<Json> & Json::array_items() { return m_ptr->array_items(); }
map<string, Json> & Json::object_items() { return m_ptr->object_items(); }
const Json & Json::operator[] (size_t i) const { return (*m_ptr)[i]; }
const Json & Json::operator[] (const string &key) const { return (*m_ptr)[key]; }
@ -335,8 +335,8 @@ uint64_ JsonValue::uint64_value() const { return
bool JsonValue::bool_value() const { return false; }
string JsonValue::as_string() const { return statics().empty_string; }
const string & JsonValue::string_value() const { return statics().empty_string; }
const vector<Json> & JsonValue::array_items() const { return statics().empty_vector; }
const map<string, Json> & JsonValue::object_items() const { return statics().empty_map; }
vector<Json> & JsonValue::array_items() { return statics().stub_vector; }
map<string, Json> & JsonValue::object_items() { return statics().stub_map; }
const Json & JsonValue::operator[] (size_t) const { return static_null(); }
const Json & JsonValue::operator[] (const string &) const { return static_null(); }

View File

@ -150,7 +150,7 @@ public:
int64_ int64_value() const;
uint64_ uint64_value() const;
// Return the enclosed string if this is a string, "" otherwise.
// Return the enclosed value as string.
std::string as_string() const;
// Return the enclosed value if this is a boolean, false otherwise.
@ -158,9 +158,9 @@ public:
// Return the enclosed string if this is a string, "" otherwise.
const std::string &string_value() const;
// Return the enclosed std::vector if this is an array, or an empty vector otherwise.
const array &array_items() const;
array &array_items();
// Return the enclosed std::map if this is an object, or an empty map otherwise.
const object &object_items() const;
object &object_items();
// Return a reference to arr[i] if this is an array, Json() otherwise.
const Json & operator[](size_t i) const;
@ -240,9 +240,9 @@ protected:
virtual bool bool_value() const;
virtual const std::string &string_value() const;
virtual std::string as_string() const;
virtual const Json::array &array_items() const;
virtual Json::array &array_items();
virtual const Json &operator[](size_t i) const;
virtual const Json::object &object_items() const;
virtual Json::object &object_items();
virtual const Json &operator[](const std::string &key) const;
virtual ~JsonValue() {}
};