Lines Matching refs:Value
5 // This file specifies a recursive data storage class called Value intended for
8 // A Value represents something that can be stored in JSON or passed to/from
14 // something like this, either use a double or make a string value containing
43 class Value;
45 typedef std::vector<Value*> ValueVector;
46 typedef std::map<std::string, Value*> ValueMap;
48 // The Value class is the base class for Values. A Value can be instantiated
49 // via the Create*Value() factory methods, or by directly creating instances of
53 class BASE_EXPORT Value {
67 virtual ~Value();
69 static scoped_ptr<Value> CreateNullValue();
71 // Returns the type of the value stored by the current Value object.
72 // Each type will be implemented by only one subclass of Value, so it's
74 // Value* to (Implementing Class)*. Also, a Value object never changes
81 // These methods allow the convenient retrieval of the contents of the Value.
82 // If the current object can be converted into the given type, the value is
98 // This creates a deep copy of the entire Value tree, and returns a pointer
103 virtual Value* DeepCopy() const;
105 scoped_ptr<Value> CreateDeepCopy() const;
107 // Compares if two Value objects have equal contents.
108 virtual bool Equals(const Value* other) const;
110 // Compares if two Value objects have equal contents. Can handle NULLs.
111 // NULLs are considered equal but different from Value::CreateNullValue().
112 static bool Equals(const Value* a, const Value* b);
116 explicit Value(Type type);
117 Value(const Value& that);
118 Value& operator=(const Value& that);
125 class BASE_EXPORT FundamentalValue : public Value {
132 // Overridden from Value:
139 bool Equals(const Value* other) const override;
149 class BASE_EXPORT StringValue : public Value {
163 // Overridden from Value:
168 bool Equals(const Value* other) const override;
174 class BASE_EXPORT BinaryValue: public Value {
196 // Overridden from Value:
199 bool Equals(const Value* other) const override;
208 // DictionaryValue provides a key-value dictionary with (optional) "path"
211 class BASE_EXPORT DictionaryValue : public Value {
213 // Returns |value| if it is a dictionary, nullptr otherwise.
214 static scoped_ptr<DictionaryValue> From(scoped_ptr<Value> value);
219 // Overridden from Value:
223 // Returns true if the current dictionary has a value for the given key.
235 // Sets the Value associated with the given path starting from this object.
242 void Set(const std::string& path, scoped_ptr<Value> in_value);
244 void Set(const std::string& path, Value* in_value);
247 // value at that path, even if it has a different type.
257 scoped_ptr<Value> in_value);
259 void SetWithoutPathExpansion(const std::string& key, Value* in_value);
270 // Gets the Value associated with the given path starting from this object.
273 // successfully, the value for the last key in the path will be returned
276 // Note that the dictionary always owns the value that's returned.
278 bool Get(StringPiece path, const Value** out_value) const;
279 bool Get(StringPiece path, Value** out_value);
281 // These are convenience forms of Get(). The value will be retrieved
282 // and the return value will be true if the path is valid and the value at
304 const Value** out_value) const;
305 bool GetWithoutPathExpansion(const std::string& key, Value** out_value);
326 // Removes the Value with the specified path from this dictionary (or one
328 // If |out_value| is non-NULL, the removed Value will be passed out via
329 // |out_value|. If |out_value| is NULL, the removed value will be deleted.
332 virtual bool Remove(const std::string& path, scoped_ptr<Value>* out_value);
337 scoped_ptr<Value>* out_value);
340 // after removing the value at |path|.
342 scoped_ptr<Value>* out_value);
369 const Value& value() const { return *it_->second; }
376 // Overridden from Value:
380 bool Equals(const Value* other) const override;
388 // This type of Value represents a list of other Value values.
389 class BASE_EXPORT ListValue : public Value {
394 // Returns |value| if it is a list, nullptr otherwise.
395 static scoped_ptr<ListValue> From(scoped_ptr<Value> value);
409 // Sets the list item at the given index to be the Value specified by
410 // the value given. If the index beyond the current end of the list, null
413 // the value is a null pointer.
414 bool Set(size_t index, Value* in_value);
416 bool Set(size_t index, scoped_ptr<Value> in_value);
418 // Gets the Value at the given index. Modifies |out_value| (and returns true)
420 // Note that the list always owns the Value passed out via |out_value|.
422 bool Get(size_t index, const Value** out_value) const;
423 bool Get(size_t index, Value** out_value);
426 // only if the index is valid and the Value at that index can be returned
443 // Removes the Value with the specified index from this list.
444 // If |out_value| is non-NULL, the removed Value AND ITS OWNERSHIP will be
445 // passed out via |out_value|. If |out_value| is NULL, the removed value will
448 virtual bool Remove(size_t index, scoped_ptr<Value>* out_value);
450 // Removes the first instance of |value| found in the list, if any, and
451 // deletes it. |index| is the location where |value| was found. Returns false
453 bool Remove(const Value& value, size_t* index);
455 // Removes the element at |iter|. If |out_value| is NULL, the value will be
456 // deleted, otherwise ownership of the value is passed back to the caller.
459 iterator Erase(iterator iter, scoped_ptr<Value>* out_value);
461 // Appends a Value to the end of the list.
462 void Append(scoped_ptr<Value> in_value);
464 void Append(Value* in_value);
475 // Appends a Value if it's not already present. Takes ownership of the
476 // |in_value|. Returns true if successful, or false if the value was already
477 // present. If the value was already present the |in_value| is deleted.
478 bool AppendIfNotPresent(Value* in_value);
480 // Insert a Value at index.
482 bool Insert(size_t index, Value* in_value);
484 // Searches for the first instance of |value| in the list using the Equals
485 // method of the Value type.
487 const_iterator Find(const Value& value) const;
499 // Overridden from Value:
503 bool Equals(const Value* other) const override;
515 // Value objects.
520 virtual bool Serialize(const Value& root) = 0;
523 // This interface is implemented by classes that know how to deserialize Value
529 // This method deserializes the subclass-specific format into a Value object.
530 // If the return value is non-NULL, the caller takes ownership of returned
531 // Value. If the return value is NULL, and if error_code is non-NULL,
535 virtual scoped_ptr<Value> Deserialize(int* error_code,
543 BASE_EXPORT std::ostream& operator<<(std::ostream& out, const Value& value);
546 const FundamentalValue& value) {
547 return out << static_cast<const Value&>(value);
551 const StringValue& value) {
552 return out << static_cast<const Value&>(value);
556 const DictionaryValue& value) {
557 return out << static_cast<const Value&>(value);
561 const ListValue& value) {
562 return out << static_cast<const Value&>(value);