| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // This file specifies a recursive data storage class called Value intended for | 5 // This file specifies a recursive data storage class called Value intended for |
| 6 // storing settings and other persistable data. | 6 // storing settings and other persistable data. |
| 7 // | 7 // |
| 8 // A Value represents something that can be stored in JSON or passed to/from | 8 // A Value represents something that can be stored in JSON or passed to/from |
| 9 // JavaScript. As such, it is NOT a generalized variant type, since only the | 9 // JavaScript. As such, it is NOT a generalized variant type, since only the |
| 10 // types supported by JavaScript/JSON are supported. | 10 // types supported by JavaScript/JSON are supported. |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 // Clears any current contents of this dictionary. | 231 // Clears any current contents of this dictionary. |
| 232 void Clear(); | 232 void Clear(); |
| 233 | 233 |
| 234 // Sets the Value associated with the given path starting from this object. | 234 // Sets the Value associated with the given path starting from this object. |
| 235 // A path has the form "<key>" or "<key>.<key>.[...]", where "." indexes | 235 // A path has the form "<key>" or "<key>.<key>.[...]", where "." indexes |
| 236 // into the next DictionaryValue down. Obviously, "." can't be used | 236 // into the next DictionaryValue down. Obviously, "." can't be used |
| 237 // within a key, but there are no other restrictions on keys. | 237 // within a key, but there are no other restrictions on keys. |
| 238 // If the key at any step of the way doesn't exist, or exists but isn't | 238 // If the key at any step of the way doesn't exist, or exists but isn't |
| 239 // a DictionaryValue, a new DictionaryValue will be created and attached | 239 // a DictionaryValue, a new DictionaryValue will be created and attached |
| 240 // to the path in that location. |in_value| must be non-null. | 240 // to the path in that location. |in_value| must be non-null. |
| 241 void Set(StringPiece path, std::unique_ptr<Value> in_value); | 241 // Returns a pointer to the inserted value. |
| 242 Value* Set(StringPiece path, std::unique_ptr<Value> in_value); |
| 242 // Deprecated version of the above. TODO(estade): remove. | 243 // Deprecated version of the above. TODO(estade): remove. |
| 243 void Set(StringPiece path, Value* in_value); | 244 Value* Set(StringPiece path, Value* in_value); |
| 244 | 245 |
| 245 // Convenience forms of Set(). These methods will replace any existing | 246 // Convenience forms of Set(). These methods will replace any existing |
| 246 // value at that path, even if it has a different type. | 247 // value at that path, even if it has a different type. |
| 247 void SetBoolean(StringPiece path, bool in_value); | 248 Value* SetBoolean(StringPiece path, bool in_value); |
| 248 void SetInteger(StringPiece path, int in_value); | 249 Value* SetInteger(StringPiece path, int in_value); |
| 249 void SetDouble(StringPiece path, double in_value); | 250 Value* SetDouble(StringPiece path, double in_value); |
| 250 void SetString(StringPiece path, StringPiece in_value); | 251 Value* SetString(StringPiece path, StringPiece in_value); |
| 251 void SetString(StringPiece path, const string16& in_value); | 252 Value* SetString(StringPiece path, const string16& in_value); |
| 253 DictionaryValue* SetDictionary(StringPiece path, |
| 254 std::unique_ptr<DictionaryValue> in_value); |
| 255 ListValue* SetList(StringPiece path, std::unique_ptr<ListValue> in_value); |
| 252 | 256 |
| 253 // Like Set(), but without special treatment of '.'. This allows e.g. URLs to | 257 // Like Set(), but without special treatment of '.'. This allows e.g. URLs to |
| 254 // be used as paths. | 258 // be used as paths. |
| 255 void SetWithoutPathExpansion(StringPiece key, | 259 Value* SetWithoutPathExpansion(StringPiece key, |
| 256 std::unique_ptr<Value> in_value); | 260 std::unique_ptr<Value> in_value); |
| 257 // Deprecated version of the above. TODO(estade): remove. | 261 // Deprecated version of the above. TODO(estade): remove. |
| 258 void SetWithoutPathExpansion(StringPiece key, Value* in_value); | 262 Value* SetWithoutPathExpansion(StringPiece key, Value* in_value); |
| 259 | 263 |
| 260 // Convenience forms of SetWithoutPathExpansion(). | 264 // Convenience forms of SetWithoutPathExpansion(). |
| 261 void SetBooleanWithoutPathExpansion(StringPiece path, bool in_value); | 265 Value* SetBooleanWithoutPathExpansion(StringPiece path, bool in_value); |
| 262 void SetIntegerWithoutPathExpansion(StringPiece path, int in_value); | 266 Value* SetIntegerWithoutPathExpansion(StringPiece path, int in_value); |
| 263 void SetDoubleWithoutPathExpansion(StringPiece path, double in_value); | 267 Value* SetDoubleWithoutPathExpansion(StringPiece path, double in_value); |
| 264 void SetStringWithoutPathExpansion(StringPiece path, StringPiece in_value); | 268 Value* SetStringWithoutPathExpansion(StringPiece path, StringPiece in_value); |
| 265 void SetStringWithoutPathExpansion(StringPiece path, | 269 Value* SetStringWithoutPathExpansion(StringPiece path, |
| 266 const string16& in_value); | 270 const string16& in_value); |
| 271 DictionaryValue* SetDictionaryWithoutPathExpansion( |
| 272 StringPiece path, |
| 273 std::unique_ptr<DictionaryValue> in_value); |
| 274 ListValue* SetListWithoutPathExpansion(StringPiece path, |
| 275 std::unique_ptr<ListValue> in_value); |
| 267 | 276 |
| 268 // Gets the Value associated with the given path starting from this object. | 277 // Gets the Value associated with the given path starting from this object. |
| 269 // A path has the form "<key>" or "<key>.<key>.[...]", where "." indexes | 278 // A path has the form "<key>" or "<key>.<key>.[...]", where "." indexes |
| 270 // into the next DictionaryValue down. If the path can be resolved | 279 // into the next DictionaryValue down. If the path can be resolved |
| 271 // successfully, the value for the last key in the path will be returned | 280 // successfully, the value for the last key in the path will be returned |
| 272 // through the |out_value| parameter, and the function will return true. | 281 // through the |out_value| parameter, and the function will return true. |
| 273 // Otherwise, it will return false and |out_value| will be untouched. | 282 // Otherwise, it will return false and |out_value| will be untouched. |
| 274 // Note that the dictionary always owns the value that's returned. | 283 // Note that the dictionary always owns the value that's returned. |
| 275 // |out_value| is optional and will only be set if non-NULL. | 284 // |out_value| is optional and will only be set if non-NULL. |
| 276 bool Get(StringPiece path, const Value** out_value) const; | 285 bool Get(StringPiece path, const Value** out_value) const; |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 return out << static_cast<const Value&>(value); | 545 return out << static_cast<const Value&>(value); |
| 537 } | 546 } |
| 538 | 547 |
| 539 // Stream operator so that enum class Types can be used in log statements. | 548 // Stream operator so that enum class Types can be used in log statements. |
| 540 BASE_EXPORT std::ostream& operator<<(std::ostream& out, | 549 BASE_EXPORT std::ostream& operator<<(std::ostream& out, |
| 541 const Value::Type& type); | 550 const Value::Type& type); |
| 542 | 551 |
| 543 } // namespace base | 552 } // namespace base |
| 544 | 553 |
| 545 #endif // BASE_VALUES_H_ | 554 #endif // BASE_VALUES_H_ |
| OLD | NEW |