[email protected] | 1350256 | 2012-05-09 21:54:27 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 4 | |
[email protected] | 9e4cda733 | 2010-07-31 04:56:14 | [diff] [blame] | 5 | // This file specifies a recursive data storage class called Value intended for |
| 6 | // storing setting and other persistable data. It includes the ability to |
| 7 | // specify (recursive) lists and dictionaries, so it's fairly expressive. |
| 8 | // However, the API is optimized for the common case, namely storing a |
| 9 | // hierarchical tree of simple values. Given a DictionaryValue root, you can |
| 10 | // easily do things like: |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 11 | // |
[email protected] | 9e4cda733 | 2010-07-31 04:56:14 | [diff] [blame] | 12 | // root->SetString("global.pages.homepage", "http://goateleporter.com"); |
| 13 | // std::string homepage = "http://google.com"; // default/fallback value |
| 14 | // root->GetString("global.pages.homepage", &homepage); |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 15 | // |
[email protected] | 9e4cda733 | 2010-07-31 04:56:14 | [diff] [blame] | 16 | // where "global" and "pages" are also DictionaryValues, and "homepage" is a |
| 17 | // string setting. If some elements of the path didn't exist yet, the |
| 18 | // SetString() method would create the missing elements and attach them to root |
| 19 | // before attaching the homepage value. |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 20 | |
[email protected] | 101d542 | 2008-09-26 20:22:42 | [diff] [blame] | 21 | #ifndef BASE_VALUES_H_ |
| 22 | #define BASE_VALUES_H_ |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 23 | |
| 24 | #include <iterator> |
| 25 | #include <map> |
[email protected] | 8e50b60 | 2009-03-03 22:59:43 | [diff] [blame] | 26 | #include <string> |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 27 | #include <vector> |
| 28 | |
[email protected] | 0bea725 | 2011-08-05 15:34:00 | [diff] [blame] | 29 | #include "base/base_export.h" |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 30 | #include "base/basictypes.h" |
[email protected] | e878919 | 2011-08-11 20:56:32 | [diff] [blame] | 31 | #include "base/compiler_specific.h" |
[email protected] | 9101ef1e | 2010-01-15 20:09:03 | [diff] [blame] | 32 | #include "base/string16.h" |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 33 | |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 34 | // This file declares "using base::Value", etc. at the bottom, so that |
| 35 | // current code can use these classes without the base namespace. In |
| 36 | // new code, please always use base::Value, etc. or add your own |
| 37 | // "using" declaration. |
| 38 | // http://crbug.com/88666 |
| 39 | namespace base { |
| 40 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 41 | class BinaryValue; |
| 42 | class DictionaryValue; |
[email protected] | 68d9d35 | 2011-02-21 16:35:04 | [diff] [blame] | 43 | class FundamentalValue; |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 44 | class ListValue; |
[email protected] | 68d9d35 | 2011-02-21 16:35:04 | [diff] [blame] | 45 | class StringValue; |
| 46 | class Value; |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 47 | |
| 48 | typedef std::vector<Value*> ValueVector; |
[email protected] | e7b418b | 2010-07-30 19:47:47 | [diff] [blame] | 49 | typedef std::map<std::string, Value*> ValueMap; |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 50 | |
[email protected] | b59ea31 | 2011-08-05 18:20:05 | [diff] [blame] | 51 | // The Value class is the base class for Values. A Value can be instantiated |
| 52 | // via the Create*Value() factory methods, or by directly creating instances of |
| 53 | // the subclasses. |
[email protected] | 0bea725 | 2011-08-05 15:34:00 | [diff] [blame] | 54 | class BASE_EXPORT Value { |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 55 | public: |
[email protected] | bab1c13f | 2011-08-12 20:59:02 | [diff] [blame] | 56 | enum Type { |
[email protected] | a502bbe7 | 2011-01-07 18:06:45 | [diff] [blame] | 57 | TYPE_NULL = 0, |
| 58 | TYPE_BOOLEAN, |
| 59 | TYPE_INTEGER, |
[email protected] | fb534c9 | 2011-02-01 01:02:07 | [diff] [blame] | 60 | TYPE_DOUBLE, |
[email protected] | a502bbe7 | 2011-01-07 18:06:45 | [diff] [blame] | 61 | TYPE_STRING, |
| 62 | TYPE_BINARY, |
| 63 | TYPE_DICTIONARY, |
| 64 | TYPE_LIST |
| 65 | }; |
| 66 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 67 | virtual ~Value(); |
| 68 | |
| 69 | // Convenience methods for creating Value objects for various |
| 70 | // kinds of values without thinking about which class implements them. |
| 71 | // These can always be expected to return a valid Value*. |
| 72 | static Value* CreateNullValue(); |
[email protected] | 16f47e08 | 2011-01-18 02:16:59 | [diff] [blame] | 73 | static FundamentalValue* CreateBooleanValue(bool in_value); |
| 74 | static FundamentalValue* CreateIntegerValue(int in_value); |
[email protected] | fb534c9 | 2011-02-01 01:02:07 | [diff] [blame] | 75 | static FundamentalValue* CreateDoubleValue(double in_value); |
[email protected] | 16f47e08 | 2011-01-18 02:16:59 | [diff] [blame] | 76 | static StringValue* CreateStringValue(const std::string& in_value); |
| 77 | static StringValue* CreateStringValue(const string16& in_value); |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 78 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 79 | // Returns the type of the value stored by the current Value object. |
| 80 | // Each type will be implemented by only one subclass of Value, so it's |
[email protected] | bab1c13f | 2011-08-12 20:59:02 | [diff] [blame] | 81 | // safe to use the Type to determine whether you can cast from |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 82 | // Value* to (Implementing Class)*. Also, a Value object never changes |
| 83 | // its type after construction. |
[email protected] | bab1c13f | 2011-08-12 20:59:02 | [diff] [blame] | 84 | Type GetType() const { return type_; } |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 85 | |
| 86 | // Returns true if the current object represents a given type. |
[email protected] | bab1c13f | 2011-08-12 20:59:02 | [diff] [blame] | 87 | bool IsType(Type type) const { return type == type_; } |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 88 | |
| 89 | // These methods allow the convenient retrieval of settings. |
| 90 | // If the current setting object can be converted into the given type, |
[email protected] | 35213ce9 | 2010-04-08 19:06:15 | [diff] [blame] | 91 | // the value is returned through the |out_value| parameter and true is |
| 92 | // returned; otherwise, false is returned and |out_value| is unchanged. |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 93 | virtual bool GetAsBoolean(bool* out_value) const; |
| 94 | virtual bool GetAsInteger(int* out_value) const; |
[email protected] | fb534c9 | 2011-02-01 01:02:07 | [diff] [blame] | 95 | virtual bool GetAsDouble(double* out_value) const; |
[email protected] | 4cd5f6a | 2008-12-11 01:23:17 | [diff] [blame] | 96 | virtual bool GetAsString(std::string* out_value) const; |
[email protected] | e2e593d | 2010-08-03 15:42:58 | [diff] [blame] | 97 | virtual bool GetAsString(string16* out_value) const; |
[email protected] | 81f9fe0b | 2010-12-07 00:35:29 | [diff] [blame] | 98 | virtual bool GetAsList(ListValue** out_value); |
[email protected] | 35552dc5 | 2011-07-12 09:04:38 | [diff] [blame] | 99 | virtual bool GetAsList(const ListValue** out_value) const; |
[email protected] | 5cf906f8 | 2011-11-26 01:11:44 | [diff] [blame] | 100 | virtual bool GetAsDictionary(DictionaryValue** out_value); |
| 101 | virtual bool GetAsDictionary(const DictionaryValue** out_value) const; |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 102 | |
| 103 | // This creates a deep copy of the entire Value tree, and returns a pointer |
| 104 | // to the copy. The caller gets ownership of the copy, of course. |
[email protected] | 16f47e08 | 2011-01-18 02:16:59 | [diff] [blame] | 105 | // |
| 106 | // Subclasses return their own type directly in their overrides; |
| 107 | // this works because C++ supports covariant return types. |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 108 | virtual Value* DeepCopy() const; |
| 109 | |
| 110 | // Compares if two Value objects have equal contents. |
| 111 | virtual bool Equals(const Value* other) const; |
| 112 | |
[email protected] | 73c4793 | 2010-12-06 18:13:43 | [diff] [blame] | 113 | // Compares if two Value objects have equal contents. Can handle NULLs. |
| 114 | // NULLs are considered equal but different from Value::CreateNullValue(). |
| 115 | static bool Equals(const Value* a, const Value* b); |
| 116 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 117 | protected: |
| 118 | // This isn't safe for end-users (they should use the Create*Value() |
| 119 | // static methods above), but it's useful for subclasses. |
[email protected] | bab1c13f | 2011-08-12 20:59:02 | [diff] [blame] | 120 | explicit Value(Type type); |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 121 | |
| 122 | private: |
[email protected] | 9b5f56b4 | 2011-08-24 21:17:59 | [diff] [blame] | 123 | Value(); |
[email protected] | 7867cd0 | 2009-09-14 16:56:12 | [diff] [blame] | 124 | |
[email protected] | 9b5f56b4 | 2011-08-24 21:17:59 | [diff] [blame] | 125 | Type type_; |
[email protected] | 2f0a647 | 2011-08-23 03:40:57 | [diff] [blame] | 126 | |
[email protected] | 7867cd0 | 2009-09-14 16:56:12 | [diff] [blame] | 127 | DISALLOW_COPY_AND_ASSIGN(Value); |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 128 | }; |
| 129 | |
| 130 | // FundamentalValue represents the simple fundamental types of values. |
[email protected] | 0bea725 | 2011-08-05 15:34:00 | [diff] [blame] | 131 | class BASE_EXPORT FundamentalValue : public Value { |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 132 | public: |
[email protected] | 3a3d4747 | 2010-07-15 21:03:54 | [diff] [blame] | 133 | explicit FundamentalValue(bool in_value); |
| 134 | explicit FundamentalValue(int in_value); |
| 135 | explicit FundamentalValue(double in_value); |
[email protected] | 78994ab0 | 2010-12-08 18:06:44 | [diff] [blame] | 136 | virtual ~FundamentalValue(); |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 137 | |
[email protected] | e878919 | 2011-08-11 20:56:32 | [diff] [blame] | 138 | // Overridden from Value: |
| 139 | virtual bool GetAsBoolean(bool* out_value) const OVERRIDE; |
| 140 | virtual bool GetAsInteger(int* out_value) const OVERRIDE; |
| 141 | virtual bool GetAsDouble(double* out_value) const OVERRIDE; |
| 142 | virtual FundamentalValue* DeepCopy() const OVERRIDE; |
| 143 | virtual bool Equals(const Value* other) const OVERRIDE; |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 144 | |
| 145 | private: |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 146 | union { |
| 147 | bool boolean_value_; |
| 148 | int integer_value_; |
[email protected] | fb534c9 | 2011-02-01 01:02:07 | [diff] [blame] | 149 | double double_value_; |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 150 | }; |
[email protected] | 7867cd0 | 2009-09-14 16:56:12 | [diff] [blame] | 151 | |
| 152 | DISALLOW_COPY_AND_ASSIGN(FundamentalValue); |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 153 | }; |
| 154 | |
[email protected] | 0bea725 | 2011-08-05 15:34:00 | [diff] [blame] | 155 | class BASE_EXPORT StringValue : public Value { |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 156 | public: |
[email protected] | 4cd5f6a | 2008-12-11 01:23:17 | [diff] [blame] | 157 | // Initializes a StringValue with a UTF-8 narrow character string. |
[email protected] | 7867cd0 | 2009-09-14 16:56:12 | [diff] [blame] | 158 | explicit StringValue(const std::string& in_value); |
[email protected] | 4cd5f6a | 2008-12-11 01:23:17 | [diff] [blame] | 159 | |
[email protected] | 9101ef1e | 2010-01-15 20:09:03 | [diff] [blame] | 160 | // Initializes a StringValue with a string16. |
| 161 | explicit StringValue(const string16& in_value); |
[email protected] | e2e593d | 2010-08-03 15:42:58 | [diff] [blame] | 162 | |
[email protected] | 78994ab0 | 2010-12-08 18:06:44 | [diff] [blame] | 163 | virtual ~StringValue(); |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 164 | |
[email protected] | e878919 | 2011-08-11 20:56:32 | [diff] [blame] | 165 | // Overridden from Value: |
| 166 | virtual bool GetAsString(std::string* out_value) const OVERRIDE; |
| 167 | virtual bool GetAsString(string16* out_value) const OVERRIDE; |
| 168 | virtual StringValue* DeepCopy() const OVERRIDE; |
| 169 | virtual bool Equals(const Value* other) const OVERRIDE; |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 170 | |
| 171 | private: |
[email protected] | 4cd5f6a | 2008-12-11 01:23:17 | [diff] [blame] | 172 | std::string value_; |
[email protected] | 7867cd0 | 2009-09-14 16:56:12 | [diff] [blame] | 173 | |
| 174 | DISALLOW_COPY_AND_ASSIGN(StringValue); |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 175 | }; |
| 176 | |
[email protected] | 0bea725 | 2011-08-05 15:34:00 | [diff] [blame] | 177 | class BASE_EXPORT BinaryValue: public Value { |
[email protected] | 7867cd0 | 2009-09-14 16:56:12 | [diff] [blame] | 178 | public: |
[email protected] | 00590b3 | 2012-05-19 19:31:16 | [diff] [blame] | 179 | virtual ~BinaryValue(); |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 180 | |
[email protected] | 0d0ed0c | 2012-05-20 02:34:57 | [diff] [blame] | 181 | // Creates a Value to represent a binary buffer. The new object takes |
| 182 | // ownership of the pointer passed in, if successful. |
| 183 | // Returns NULL if buffer is NULL. |
| 184 | static BinaryValue* Create(char* buffer, size_t size); |
| 185 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 186 | // For situations where you want to keep ownership of your buffer, this |
| 187 | // factory method creates a new BinaryValue by copying the contents of the |
| 188 | // buffer that's passed in. |
[email protected] | 0d0ed0c | 2012-05-20 02:34:57 | [diff] [blame] | 189 | // Returns NULL if buffer is NULL. |
[email protected] | e4dad9fb | 2009-10-06 18:15:58 | [diff] [blame] | 190 | static BinaryValue* CreateWithCopiedBuffer(const char* buffer, size_t size); |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 191 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 192 | size_t GetSize() const { return size_; } |
[email protected] | 0d0ed0c | 2012-05-20 02:34:57 | [diff] [blame] | 193 | char* GetBuffer() { return buffer_; } |
| 194 | const char* GetBuffer() const { return buffer_; } |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 195 | |
[email protected] | a502bbe7 | 2011-01-07 18:06:45 | [diff] [blame] | 196 | // Overridden from Value: |
[email protected] | e878919 | 2011-08-11 20:56:32 | [diff] [blame] | 197 | virtual BinaryValue* DeepCopy() const OVERRIDE; |
| 198 | virtual bool Equals(const Value* other) const OVERRIDE; |
[email protected] | a502bbe7 | 2011-01-07 18:06:45 | [diff] [blame] | 199 | |
[email protected] | 7867cd0 | 2009-09-14 16:56:12 | [diff] [blame] | 200 | private: |
[email protected] | 0d0ed0c | 2012-05-20 02:34:57 | [diff] [blame] | 201 | // Constructor is private so that only objects with valid buffer pointers |
| 202 | // and size values can be created. |
| 203 | BinaryValue(char* buffer, size_t size); |
| 204 | |
| 205 | char* buffer_; |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 206 | size_t size_; |
[email protected] | 7867cd0 | 2009-09-14 16:56:12 | [diff] [blame] | 207 | |
| 208 | DISALLOW_COPY_AND_ASSIGN(BinaryValue); |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 209 | }; |
| 210 | |
[email protected] | 9e4cda733 | 2010-07-31 04:56:14 | [diff] [blame] | 211 | // DictionaryValue provides a key-value dictionary with (optional) "path" |
| 212 | // parsing for recursive access; see the comment at the top of the file. Keys |
| 213 | // are |std::string|s and should be UTF-8 encoded. |
[email protected] | 0bea725 | 2011-08-05 15:34:00 | [diff] [blame] | 214 | class BASE_EXPORT DictionaryValue : public Value { |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 215 | public: |
[email protected] | 3a3d4747 | 2010-07-15 21:03:54 | [diff] [blame] | 216 | DictionaryValue(); |
[email protected] | 78994ab0 | 2010-12-08 18:06:44 | [diff] [blame] | 217 | virtual ~DictionaryValue(); |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 218 | |
[email protected] | 5cf906f8 | 2011-11-26 01:11:44 | [diff] [blame] | 219 | // Overridden from Value: |
| 220 | virtual bool GetAsDictionary(DictionaryValue** out_value) OVERRIDE; |
| 221 | virtual bool GetAsDictionary( |
| 222 | const DictionaryValue** out_value) const OVERRIDE; |
| 223 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 224 | // Returns true if the current dictionary has a value for the given key. |
[email protected] | e7b418b | 2010-07-30 19:47:47 | [diff] [blame] | 225 | bool HasKey(const std::string& key) const; |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 226 | |
[email protected] | fb804132c | 2009-04-15 00:17:53 | [diff] [blame] | 227 | // Returns the number of Values in this dictionary. |
[email protected] | 4dad9ad8 | 2009-11-25 20:47:52 | [diff] [blame] | 228 | size_t size() const { return dictionary_.size(); } |
| 229 | |
| 230 | // Returns whether the dictionary is empty. |
| 231 | bool empty() const { return dictionary_.empty(); } |
[email protected] | fb804132c | 2009-04-15 00:17:53 | [diff] [blame] | 232 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 233 | // Clears any current contents of this dictionary. |
[email protected] | af5ed4a | 2008-08-04 13:56:25 | [diff] [blame] | 234 | void Clear(); |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 235 | |
| 236 | // Sets the Value associated with the given path starting from this object. |
| 237 | // A path has the form "<key>" or "<key>.<key>.[...]", where "." indexes |
| 238 | // into the next DictionaryValue down. Obviously, "." can't be used |
| 239 | // within a key, but there are no other restrictions on keys. |
| 240 | // If the key at any step of the way doesn't exist, or exists but isn't |
| 241 | // a DictionaryValue, a new DictionaryValue will be created and attached |
| 242 | // to the path in that location. |
[email protected] | fb804132c | 2009-04-15 00:17:53 | [diff] [blame] | 243 | // Note that the dictionary takes ownership of the value referenced by |
[email protected] | 4dad9ad8 | 2009-11-25 20:47:52 | [diff] [blame] | 244 | // |in_value|, and therefore |in_value| must be non-NULL. |
[email protected] | e7b418b | 2010-07-30 19:47:47 | [diff] [blame] | 245 | void Set(const std::string& path, Value* in_value); |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 246 | |
| 247 | // Convenience forms of Set(). These methods will replace any existing |
| 248 | // value at that path, even if it has a different type. |
[email protected] | e7b418b | 2010-07-30 19:47:47 | [diff] [blame] | 249 | void SetBoolean(const std::string& path, bool in_value); |
| 250 | void SetInteger(const std::string& path, int in_value); |
[email protected] | fb534c9 | 2011-02-01 01:02:07 | [diff] [blame] | 251 | void SetDouble(const std::string& path, double in_value); |
[email protected] | e7b418b | 2010-07-30 19:47:47 | [diff] [blame] | 252 | void SetString(const std::string& path, const std::string& in_value); |
[email protected] | ff4c1d8 | 2010-08-04 16:58:12 | [diff] [blame] | 253 | void SetString(const std::string& path, const string16& in_value); |
[email protected] | 4dad9ad8 | 2009-11-25 20:47:52 | [diff] [blame] | 254 | |
| 255 | // Like Set(), but without special treatment of '.'. This allows e.g. URLs to |
| 256 | // be used as paths. |
[email protected] | e7b418b | 2010-07-30 19:47:47 | [diff] [blame] | 257 | void SetWithoutPathExpansion(const std::string& key, Value* in_value); |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 258 | |
[email protected] | 095812b | 2012-09-14 02:14:01 | [diff] [blame^] | 259 | // Convenience forms of SetWithoutPathExpansion(). |
| 260 | void SetBooleanWithoutPathExpansion(const std::string& path, bool in_value); |
| 261 | void SetIntegerWithoutPathExpansion(const std::string& path, int in_value); |
| 262 | void SetDoubleWithoutPathExpansion(const std::string& path, double in_value); |
| 263 | void SetStringWithoutPathExpansion(const std::string& path, |
| 264 | const std::string& in_value); |
| 265 | void SetStringWithoutPathExpansion(const std::string& path, |
| 266 | const string16& in_value); |
| 267 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 268 | // Gets the Value associated with the given path starting from this object. |
| 269 | // A path has the form "<key>" or "<key>.<key>.[...]", where "." indexes |
| 270 | // 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 |
[email protected] | 35213ce9 | 2010-04-08 19:06:15 | [diff] [blame] | 272 | // through the |out_value| parameter, and the function will return true. |
| 273 | // Otherwise, it will return false and |out_value| will be untouched. |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 274 | // Note that the dictionary always owns the value that's returned. |
[email protected] | a61890e | 2012-07-27 22:27:11 | [diff] [blame] | 275 | bool Get(const std::string& path, const Value** out_value) const; |
| 276 | bool Get(const std::string& path, Value** out_value); |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 277 | |
| 278 | // These are convenience forms of Get(). The value will be retrieved |
| 279 | // and the return value will be true if the path is valid and the value at |
| 280 | // the end of the path can be returned in the form specified. |
[email protected] | e7b418b | 2010-07-30 19:47:47 | [diff] [blame] | 281 | bool GetBoolean(const std::string& path, bool* out_value) const; |
| 282 | bool GetInteger(const std::string& path, int* out_value) const; |
[email protected] | fb534c9 | 2011-02-01 01:02:07 | [diff] [blame] | 283 | bool GetDouble(const std::string& path, double* out_value) const; |
[email protected] | e7b418b | 2010-07-30 19:47:47 | [diff] [blame] | 284 | bool GetString(const std::string& path, std::string* out_value) const; |
[email protected] | 698f7f4 | 2010-08-04 19:35:33 | [diff] [blame] | 285 | bool GetString(const std::string& path, string16* out_value) const; |
[email protected] | 9430e4b | 2010-02-19 13:32:16 | [diff] [blame] | 286 | bool GetStringASCII(const std::string& path, std::string* out_value) const; |
[email protected] | a61890e | 2012-07-27 22:27:11 | [diff] [blame] | 287 | bool GetBinary(const std::string& path, const BinaryValue** out_value) const; |
| 288 | bool GetBinary(const std::string& path, BinaryValue** out_value); |
[email protected] | e7b418b | 2010-07-30 19:47:47 | [diff] [blame] | 289 | bool GetDictionary(const std::string& path, |
[email protected] | a61890e | 2012-07-27 22:27:11 | [diff] [blame] | 290 | const DictionaryValue** out_value) const; |
| 291 | bool GetDictionary(const std::string& path, DictionaryValue** out_value); |
| 292 | bool GetList(const std::string& path, const ListValue** out_value) const; |
| 293 | bool GetList(const std::string& path, ListValue** out_value); |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 294 | |
[email protected] | 4dad9ad8 | 2009-11-25 20:47:52 | [diff] [blame] | 295 | // Like Get(), but without special treatment of '.'. This allows e.g. URLs to |
| 296 | // be used as paths. |
[email protected] | e7b418b | 2010-07-30 19:47:47 | [diff] [blame] | 297 | bool GetWithoutPathExpansion(const std::string& key, |
[email protected] | a61890e | 2012-07-27 22:27:11 | [diff] [blame] | 298 | const Value** out_value) const; |
| 299 | bool GetWithoutPathExpansion(const std::string& key, Value** out_value); |
[email protected] | e7b418b | 2010-07-30 19:47:47 | [diff] [blame] | 300 | bool GetIntegerWithoutPathExpansion(const std::string& key, |
[email protected] | 4dad9ad8 | 2009-11-25 20:47:52 | [diff] [blame] | 301 | int* out_value) const; |
[email protected] | fb534c9 | 2011-02-01 01:02:07 | [diff] [blame] | 302 | bool GetDoubleWithoutPathExpansion(const std::string& key, |
[email protected] | a61890e | 2012-07-27 22:27:11 | [diff] [blame] | 303 | double* out_value) const; |
[email protected] | e7b418b | 2010-07-30 19:47:47 | [diff] [blame] | 304 | bool GetStringWithoutPathExpansion(const std::string& key, |
[email protected] | 4dad9ad8 | 2009-11-25 20:47:52 | [diff] [blame] | 305 | std::string* out_value) const; |
[email protected] | 698f7f4 | 2010-08-04 19:35:33 | [diff] [blame] | 306 | bool GetStringWithoutPathExpansion(const std::string& key, |
| 307 | string16* out_value) const; |
[email protected] | a61890e | 2012-07-27 22:27:11 | [diff] [blame] | 308 | bool GetDictionaryWithoutPathExpansion( |
| 309 | const std::string& key, |
| 310 | const DictionaryValue** out_value) const; |
[email protected] | e7b418b | 2010-07-30 19:47:47 | [diff] [blame] | 311 | bool GetDictionaryWithoutPathExpansion(const std::string& key, |
[email protected] | a61890e | 2012-07-27 22:27:11 | [diff] [blame] | 312 | DictionaryValue** out_value); |
[email protected] | e7b418b | 2010-07-30 19:47:47 | [diff] [blame] | 313 | bool GetListWithoutPathExpansion(const std::string& key, |
[email protected] | a61890e | 2012-07-27 22:27:11 | [diff] [blame] | 314 | const ListValue** out_value) const; |
| 315 | bool GetListWithoutPathExpansion(const std::string& key, |
| 316 | ListValue** out_value); |
[email protected] | 4dad9ad8 | 2009-11-25 20:47:52 | [diff] [blame] | 317 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 318 | // Removes the Value with the specified path from this dictionary (or one |
| 319 | // of its child dictionaries, if the path is more than just a local key). |
| 320 | // If |out_value| is non-NULL, the removed Value AND ITS OWNERSHIP will be |
| 321 | // passed out via out_value. If |out_value| is NULL, the removed value will |
| 322 | // be deleted. This method returns true if |path| is a valid path; otherwise |
| 323 | // it will return false and the DictionaryValue object will be unchanged. |
[email protected] | 6e680cf | 2012-05-16 15:23:30 | [diff] [blame] | 324 | virtual bool Remove(const std::string& path, Value** out_value); |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 325 | |
[email protected] | 4dad9ad8 | 2009-11-25 20:47:52 | [diff] [blame] | 326 | // Like Remove(), but without special treatment of '.'. This allows e.g. URLs |
| 327 | // to be used as paths. |
[email protected] | 6e680cf | 2012-05-16 15:23:30 | [diff] [blame] | 328 | virtual bool RemoveWithoutPathExpansion(const std::string& key, |
| 329 | Value** out_value); |
[email protected] | 4dad9ad8 | 2009-11-25 20:47:52 | [diff] [blame] | 330 | |
[email protected] | ec330b5 | 2009-12-02 00:20:32 | [diff] [blame] | 331 | // Makes a copy of |this| but doesn't include empty dictionaries and lists in |
| 332 | // the copy. This never returns NULL, even if |this| itself is empty. |
| 333 | DictionaryValue* DeepCopyWithoutEmptyChildren(); |
| 334 | |
[email protected] | 1350256 | 2012-05-09 21:54:27 | [diff] [blame] | 335 | // Merge |dictionary| into this dictionary. This is done recursively, i.e. any |
| 336 | // sub-dictionaries will be merged as well. In case of key collisions, the |
| 337 | // passed in dictionary takes precedence and data already present will be |
| 338 | // replaced. Values within |dictionary| are deep-copied, so |dictionary| may |
| 339 | // be freed any time after this call. |
[email protected] | c378cca | 2010-05-14 13:17:40 | [diff] [blame] | 340 | void MergeDictionary(const DictionaryValue* dictionary); |
| 341 | |
[email protected] | ec5263a | 2011-05-10 09:23:39 | [diff] [blame] | 342 | // Swaps contents with the |other| dictionary. |
[email protected] | 6e680cf | 2012-05-16 15:23:30 | [diff] [blame] | 343 | virtual void Swap(DictionaryValue* other); |
[email protected] | ec5263a | 2011-05-10 09:23:39 | [diff] [blame] | 344 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 345 | // This class provides an iterator for the keys in the dictionary. |
| 346 | // It can't be used to modify the dictionary. |
[email protected] | 4dad9ad8 | 2009-11-25 20:47:52 | [diff] [blame] | 347 | // |
| 348 | // YOU SHOULD ALWAYS USE THE XXXWithoutPathExpansion() APIs WITH THESE, NOT |
| 349 | // THE NORMAL XXX() APIs. This makes sure things will work correctly if any |
| 350 | // keys have '.'s in them. |
[email protected] | a34cc09 | 2012-08-10 12:45:35 | [diff] [blame] | 351 | class BASE_EXPORT key_iterator |
[email protected] | e7b418b | 2010-07-30 19:47:47 | [diff] [blame] | 352 | : private std::iterator<std::input_iterator_tag, const std::string> { |
[email protected] | 03c5e86 | 2009-02-17 22:50:14 | [diff] [blame] | 353 | public: |
[email protected] | a34cc09 | 2012-08-10 12:45:35 | [diff] [blame] | 354 | explicit key_iterator(ValueMap::const_iterator itr); |
| 355 | // Not explicit, because this is a copy constructor. |
| 356 | key_iterator(const key_iterator& rhs); |
[email protected] | 2fdc86a | 2010-01-26 23:08:02 | [diff] [blame] | 357 | key_iterator operator++() { |
| 358 | ++itr_; |
| 359 | return *this; |
| 360 | } |
[email protected] | e7b418b | 2010-07-30 19:47:47 | [diff] [blame] | 361 | const std::string& operator*() { return itr_->first; } |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 362 | bool operator!=(const key_iterator& other) { return itr_ != other.itr_; } |
| 363 | bool operator==(const key_iterator& other) { return itr_ == other.itr_; } |
| 364 | |
[email protected] | 03c5e86 | 2009-02-17 22:50:14 | [diff] [blame] | 365 | private: |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 366 | ValueMap::const_iterator itr_; |
| 367 | }; |
| 368 | |
| 369 | key_iterator begin_keys() const { return key_iterator(dictionary_.begin()); } |
| 370 | key_iterator end_keys() const { return key_iterator(dictionary_.end()); } |
| 371 | |
[email protected] | 32c0e00 | 2011-11-08 21:26:41 | [diff] [blame] | 372 | // This class provides an iterator over both keys and values in the |
| 373 | // dictionary. It can't be used to modify the dictionary. |
[email protected] | a34cc09 | 2012-08-10 12:45:35 | [diff] [blame] | 374 | class BASE_EXPORT Iterator { |
[email protected] | 32c0e00 | 2011-11-08 21:26:41 | [diff] [blame] | 375 | public: |
[email protected] | a34cc09 | 2012-08-10 12:45:35 | [diff] [blame] | 376 | explicit Iterator(const DictionaryValue& target); |
[email protected] | 32c0e00 | 2011-11-08 21:26:41 | [diff] [blame] | 377 | |
| 378 | bool HasNext() const { return it_ != target_.dictionary_.end(); } |
| 379 | void Advance() { ++it_; } |
| 380 | |
| 381 | const std::string& key() const { return it_->first; } |
| 382 | const Value& value() const { return *it_->second; } |
| 383 | |
| 384 | private: |
| 385 | const DictionaryValue& target_; |
| 386 | ValueMap::const_iterator it_; |
| 387 | }; |
| 388 | |
[email protected] | a502bbe7 | 2011-01-07 18:06:45 | [diff] [blame] | 389 | // Overridden from Value: |
[email protected] | e878919 | 2011-08-11 20:56:32 | [diff] [blame] | 390 | virtual DictionaryValue* DeepCopy() const OVERRIDE; |
| 391 | virtual bool Equals(const Value* other) const OVERRIDE; |
[email protected] | a502bbe7 | 2011-01-07 18:06:45 | [diff] [blame] | 392 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 393 | private: |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 394 | ValueMap dictionary_; |
[email protected] | 7867cd0 | 2009-09-14 16:56:12 | [diff] [blame] | 395 | |
| 396 | DISALLOW_COPY_AND_ASSIGN(DictionaryValue); |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 397 | }; |
| 398 | |
| 399 | // This type of Value represents a list of other Value values. |
[email protected] | 0bea725 | 2011-08-05 15:34:00 | [diff] [blame] | 400 | class BASE_EXPORT ListValue : public Value { |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 401 | public: |
[email protected] | a502bbe7 | 2011-01-07 18:06:45 | [diff] [blame] | 402 | typedef ValueVector::iterator iterator; |
| 403 | typedef ValueVector::const_iterator const_iterator; |
| 404 | |
[email protected] | 3a3d4747 | 2010-07-15 21:03:54 | [diff] [blame] | 405 | ListValue(); |
[email protected] | 3690ebe0 | 2011-05-25 09:08:19 | [diff] [blame] | 406 | virtual ~ListValue(); |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 407 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 408 | // Clears the contents of this ListValue |
| 409 | void Clear(); |
| 410 | |
| 411 | // Returns the number of Values in this list. |
| 412 | size_t GetSize() const { return list_.size(); } |
| 413 | |
[email protected] | ec330b5 | 2009-12-02 00:20:32 | [diff] [blame] | 414 | // Returns whether the list is empty. |
| 415 | bool empty() const { return list_.empty(); } |
| 416 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 417 | // Sets the list item at the given index to be the Value specified by |
| 418 | // the value given. If the index beyond the current end of the list, null |
| 419 | // Values will be used to pad out the list. |
| 420 | // Returns true if successful, or false if the index was negative or |
| 421 | // the value is a null pointer. |
| 422 | bool Set(size_t index, Value* in_value); |
| 423 | |
[email protected] | 35213ce9 | 2010-04-08 19:06:15 | [diff] [blame] | 424 | // Gets the Value at the given index. Modifies |out_value| (and returns true) |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 425 | // only if the index falls within the current list range. |
[email protected] | 35213ce9 | 2010-04-08 19:06:15 | [diff] [blame] | 426 | // Note that the list always owns the Value passed out via |out_value|. |
[email protected] | 5d30f92bf | 2012-08-03 08:43:37 | [diff] [blame] | 427 | bool Get(size_t index, const Value** out_value) const; |
| 428 | bool Get(size_t index, Value** out_value); |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 429 | |
[email protected] | 35213ce9 | 2010-04-08 19:06:15 | [diff] [blame] | 430 | // Convenience forms of Get(). Modifies |out_value| (and returns true) |
| 431 | // only if the index is valid and the Value at that index can be returned |
| 432 | // in the specified form. |
[email protected] | f82fb495 | 2009-01-20 21:05:32 | [diff] [blame] | 433 | bool GetBoolean(size_t index, bool* out_value) const; |
| 434 | bool GetInteger(size_t index, int* out_value) const; |
[email protected] | fb534c9 | 2011-02-01 01:02:07 | [diff] [blame] | 435 | bool GetDouble(size_t index, double* out_value) const; |
[email protected] | f82fb495 | 2009-01-20 21:05:32 | [diff] [blame] | 436 | bool GetString(size_t index, std::string* out_value) const; |
[email protected] | 698f7f4 | 2010-08-04 19:35:33 | [diff] [blame] | 437 | bool GetString(size_t index, string16* out_value) const; |
[email protected] | 5d30f92bf | 2012-08-03 08:43:37 | [diff] [blame] | 438 | bool GetBinary(size_t index, const BinaryValue** out_value) const; |
| 439 | bool GetBinary(size_t index, BinaryValue** out_value); |
| 440 | bool GetDictionary(size_t index, const DictionaryValue** out_value) const; |
| 441 | bool GetDictionary(size_t index, DictionaryValue** out_value); |
| 442 | bool GetList(size_t index, const ListValue** out_value) const; |
| 443 | bool GetList(size_t index, ListValue** out_value); |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 444 | |
| 445 | // Removes the Value with the specified index from this list. |
| 446 | // If |out_value| is non-NULL, the removed Value AND ITS OWNERSHIP will be |
[email protected] | b930d13 | 2009-01-05 18:37:51 | [diff] [blame] | 447 | // passed out via |out_value|. If |out_value| is NULL, the removed value will |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 448 | // be deleted. This method returns true if |index| is valid; otherwise |
| 449 | // it will return false and the ListValue object will be unchanged. |
[email protected] | 6e680cf | 2012-05-16 15:23:30 | [diff] [blame] | 450 | virtual bool Remove(size_t index, Value** out_value); |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 451 | |
[email protected] | 6832cbe | 2009-11-30 19:59:11 | [diff] [blame] | 452 | // Removes the first instance of |value| found in the list, if any, and |
[email protected] | 4fc3c564 | 2011-08-13 17:34:31 | [diff] [blame] | 453 | // deletes it. |index| is the location where |value| was found. Returns false |
| 454 | // if not found. |
| 455 | bool Remove(const Value& value, size_t* index); |
[email protected] | e7f5c6f | 2009-05-09 00:33:04 | [diff] [blame] | 456 | |
[email protected] | 3cbe081 | 2012-07-03 02:51:43 | [diff] [blame] | 457 | // Removes the element at |iter|. If |out_value| is NULL, the value will be |
| 458 | // deleted, otherwise ownership of the value is passed back to the caller. |
| 459 | void Erase(iterator iter, Value** out_value); |
| 460 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 461 | // Appends a Value to the end of the list. |
| 462 | void Append(Value* in_value); |
| 463 | |
[email protected] | 095812b | 2012-09-14 02:14:01 | [diff] [blame^] | 464 | // Convenience forms of Append. |
| 465 | void AppendBoolean(bool in_value); |
| 466 | void AppendInteger(int in_value); |
| 467 | void AppendDouble(double in_value); |
| 468 | void AppendString(const std::string& in_value); |
| 469 | void AppendString(const string16& in_value); |
| 470 | void AppendStrings(const std::vector<std::string>& in_values); |
| 471 | void AppendStrings(const std::vector<string16>& in_values); |
| 472 | |
[email protected] | e36eaac | 2011-03-18 13:56:38 | [diff] [blame] | 473 | // Appends a Value if it's not already present. Takes ownership of the |
| 474 | // |in_value|. Returns true if successful, or false if the value was already |
| 475 | // present. If the value was already present the |in_value| is deleted. |
[email protected] | 84064220 | 2010-04-12 21:48:10 | [diff] [blame] | 476 | bool AppendIfNotPresent(Value* in_value); |
| 477 | |
[email protected] | 86c008e8 | 2009-08-28 20:26:05 | [diff] [blame] | 478 | // Insert a Value at index. |
| 479 | // Returns true if successful, or false if the index was out of range. |
| 480 | bool Insert(size_t index, Value* in_value); |
| 481 | |
[email protected] | 5fb3537 | 2011-09-19 15:23:10 | [diff] [blame] | 482 | // Searches for the first instance of |value| in the list using the Equals |
| 483 | // method of the Value type. |
| 484 | // Returns a const_iterator to the found item or to end() if none exists. |
| 485 | const_iterator Find(const Value& value) const; |
| 486 | |
[email protected] | 8b8e7c9 | 2010-08-19 18:05:56 | [diff] [blame] | 487 | // Swaps contents with the |other| list. |
[email protected] | 6e680cf | 2012-05-16 15:23:30 | [diff] [blame] | 488 | virtual void Swap(ListValue* other); |
[email protected] | 8b8e7c9 | 2010-08-19 18:05:56 | [diff] [blame] | 489 | |
[email protected] | e878919 | 2011-08-11 20:56:32 | [diff] [blame] | 490 | // Iteration. |
| 491 | iterator begin() { return list_.begin(); } |
| 492 | iterator end() { return list_.end(); } |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 493 | |
[email protected] | e878919 | 2011-08-11 20:56:32 | [diff] [blame] | 494 | const_iterator begin() const { return list_.begin(); } |
| 495 | const_iterator end() const { return list_.end(); } |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 496 | |
[email protected] | a502bbe7 | 2011-01-07 18:06:45 | [diff] [blame] | 497 | // Overridden from Value: |
[email protected] | e878919 | 2011-08-11 20:56:32 | [diff] [blame] | 498 | virtual bool GetAsList(ListValue** out_value) OVERRIDE; |
| 499 | virtual bool GetAsList(const ListValue** out_value) const OVERRIDE; |
| 500 | virtual ListValue* DeepCopy() const OVERRIDE; |
| 501 | virtual bool Equals(const Value* other) const OVERRIDE; |
[email protected] | a502bbe7 | 2011-01-07 18:06:45 | [diff] [blame] | 502 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 503 | private: |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 504 | ValueVector list_; |
[email protected] | 7867cd0 | 2009-09-14 16:56:12 | [diff] [blame] | 505 | |
| 506 | DISALLOW_COPY_AND_ASSIGN(ListValue); |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 507 | }; |
| 508 | |
| 509 | // This interface is implemented by classes that know how to serialize and |
| 510 | // deserialize Value objects. |
[email protected] | 0bea725 | 2011-08-05 15:34:00 | [diff] [blame] | 511 | class BASE_EXPORT ValueSerializer { |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 512 | public: |
[email protected] | 3a3d4747 | 2010-07-15 21:03:54 | [diff] [blame] | 513 | virtual ~ValueSerializer(); |
[email protected] | abb9d0c | 2008-08-06 15:46:59 | [diff] [blame] | 514 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 515 | virtual bool Serialize(const Value& root) = 0; |
| 516 | |
| 517 | // This method deserializes the subclass-specific format into a Value object. |
[email protected] | b4cebf8 | 2008-12-29 19:59:08 | [diff] [blame] | 518 | // If the return value is non-NULL, the caller takes ownership of returned |
[email protected] | ba39967 | 2010-04-06 15:42:39 | [diff] [blame] | 519 | // Value. If the return value is NULL, and if error_code is non-NULL, |
| 520 | // error_code will be set with the underlying error. |
| 521 | // If |error_message| is non-null, it will be filled in with a formatted |
| 522 | // error message including the location of the error if appropriate. |
| 523 | virtual Value* Deserialize(int* error_code, std::string* error_str) = 0; |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 524 | }; |
| 525 | |
[email protected] | e4ef831 | 2012-09-12 03:39:35 | [diff] [blame] | 526 | // Stream operator so Values can be used in assertion statements. |
| 527 | BASE_EXPORT std::ostream& operator<<(std::ostream& out, const Value& value); |
| 528 | |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 529 | } // namespace base |
| 530 | |
| 531 | // http://crbug.com/88666 |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 532 | using base::DictionaryValue; |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 533 | using base::ListValue; |
| 534 | using base::StringValue; |
| 535 | using base::Value; |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 536 | |
[email protected] | 101d542 | 2008-09-26 20:22:42 | [diff] [blame] | 537 | #endif // BASE_VALUES_H_ |