erg@google.com | d5fffd4 | 2011-01-08 03:06:45 +0900 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
license.bot | f003cfe | 2008-08-24 09:55:55 +0900 | [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 | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 4 | |
viettrungluu@chromium.org | 496dec2 | 2010-07-31 13:56:14 +0900 | [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 | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 11 | // |
viettrungluu@chromium.org | 496dec2 | 2010-07-31 13:56:14 +0900 | [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 | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 15 | // |
viettrungluu@chromium.org | 496dec2 | 2010-07-31 13:56:14 +0900 | [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 | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 20 | |
darin@chromium.org | 01f1070 | 2008-09-27 05:22:42 +0900 | [diff] [blame] | 21 | #ifndef BASE_VALUES_H_ |
| 22 | #define BASE_VALUES_H_ |
thakis@chromium.org | 01d1452 | 2010-07-27 08:08:24 +0900 | [diff] [blame] | 23 | #pragma once |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 24 | |
| 25 | #include <iterator> |
| 26 | #include <map> |
nsylvain@chromium.org | 1242667 | 2009-03-04 07:59:43 +0900 | [diff] [blame] | 27 | #include <string> |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 28 | #include <vector> |
| 29 | |
darin@chromium.org | e585bed | 2011-08-06 00:34:00 +0900 | [diff] [blame] | 30 | #include "base/base_export.h" |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 31 | #include "base/basictypes.h" |
tfarina@chromium.org | cc17740 | 2011-08-12 05:56:32 +0900 | [diff] [blame] | 32 | #include "base/compiler_specific.h" |
munjal@chromium.org | 3b2d3a4 | 2010-01-16 05:09:03 +0900 | [diff] [blame] | 33 | #include "base/string16.h" |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 34 | |
dmazzoni@chromium.org | 13e5365 | 2011-07-13 04:15:03 +0900 | [diff] [blame] | 35 | // This file declares "using base::Value", etc. at the bottom, so that |
| 36 | // current code can use these classes without the base namespace. In |
| 37 | // new code, please always use base::Value, etc. or add your own |
| 38 | // "using" declaration. |
| 39 | // http://crbug.com/88666 |
| 40 | namespace base { |
| 41 | |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 42 | class BinaryValue; |
| 43 | class DictionaryValue; |
bauerb@chromium.org | 6fca958 | 2011-02-22 01:35:04 +0900 | [diff] [blame] | 44 | class FundamentalValue; |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 45 | class ListValue; |
bauerb@chromium.org | 6fca958 | 2011-02-22 01:35:04 +0900 | [diff] [blame] | 46 | class StringValue; |
| 47 | class Value; |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 48 | |
| 49 | typedef std::vector<Value*> ValueVector; |
viettrungluu@chromium.org | 178423d | 2010-07-31 04:47:47 +0900 | [diff] [blame] | 50 | typedef std::map<std::string, Value*> ValueMap; |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 51 | |
tfarina@chromium.org | 2e2a902 | 2011-08-06 03:20:05 +0900 | [diff] [blame] | 52 | // The Value class is the base class for Values. A Value can be instantiated |
| 53 | // via the Create*Value() factory methods, or by directly creating instances of |
| 54 | // the subclasses. |
darin@chromium.org | e585bed | 2011-08-06 00:34:00 +0900 | [diff] [blame] | 55 | class BASE_EXPORT Value { |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 56 | public: |
tfarina@chromium.org | 254780a | 2011-08-13 05:59:02 +0900 | [diff] [blame] | 57 | enum Type { |
erg@google.com | d5fffd4 | 2011-01-08 03:06:45 +0900 | [diff] [blame] | 58 | TYPE_NULL = 0, |
| 59 | TYPE_BOOLEAN, |
| 60 | TYPE_INTEGER, |
arv@chromium.org | 13413eb | 2011-02-01 10:02:07 +0900 | [diff] [blame] | 61 | TYPE_DOUBLE, |
erg@google.com | d5fffd4 | 2011-01-08 03:06:45 +0900 | [diff] [blame] | 62 | TYPE_STRING, |
| 63 | TYPE_BINARY, |
| 64 | TYPE_DICTIONARY, |
| 65 | TYPE_LIST |
| 66 | }; |
| 67 | |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 68 | virtual ~Value(); |
| 69 | |
| 70 | // Convenience methods for creating Value objects for various |
| 71 | // kinds of values without thinking about which class implements them. |
| 72 | // These can always be expected to return a valid Value*. |
| 73 | static Value* CreateNullValue(); |
akalin@chromium.org | 810f92f | 2011-01-18 11:16:59 +0900 | [diff] [blame] | 74 | static FundamentalValue* CreateBooleanValue(bool in_value); |
| 75 | static FundamentalValue* CreateIntegerValue(int in_value); |
arv@chromium.org | 13413eb | 2011-02-01 10:02:07 +0900 | [diff] [blame] | 76 | static FundamentalValue* CreateDoubleValue(double in_value); |
akalin@chromium.org | 810f92f | 2011-01-18 11:16:59 +0900 | [diff] [blame] | 77 | static StringValue* CreateStringValue(const std::string& in_value); |
| 78 | static StringValue* CreateStringValue(const string16& in_value); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 79 | |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 80 | // Returns the type of the value stored by the current Value object. |
| 81 | // Each type will be implemented by only one subclass of Value, so it's |
tfarina@chromium.org | 254780a | 2011-08-13 05:59:02 +0900 | [diff] [blame] | 82 | // safe to use the Type to determine whether you can cast from |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 83 | // Value* to (Implementing Class)*. Also, a Value object never changes |
| 84 | // its type after construction. |
tfarina@chromium.org | 254780a | 2011-08-13 05:59:02 +0900 | [diff] [blame] | 85 | Type GetType() const { return type_; } |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 86 | |
| 87 | // Returns true if the current object represents a given type. |
tfarina@chromium.org | 254780a | 2011-08-13 05:59:02 +0900 | [diff] [blame] | 88 | bool IsType(Type type) const { return type == type_; } |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 89 | |
| 90 | // These methods allow the convenient retrieval of settings. |
| 91 | // If the current setting object can be converted into the given type, |
skerner@chromium.org | 53f71f0 | 2010-04-09 04:06:15 +0900 | [diff] [blame] | 92 | // the value is returned through the |out_value| parameter and true is |
| 93 | // returned; otherwise, false is returned and |out_value| is unchanged. |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 94 | virtual bool GetAsBoolean(bool* out_value) const; |
| 95 | virtual bool GetAsInteger(int* out_value) const; |
arv@chromium.org | 13413eb | 2011-02-01 10:02:07 +0900 | [diff] [blame] | 96 | virtual bool GetAsDouble(double* out_value) const; |
scherkus@chromium.org | 2b923e7 | 2008-12-11 10:23:17 +0900 | [diff] [blame] | 97 | virtual bool GetAsString(std::string* out_value) const; |
viettrungluu@chromium.org | 31b80ba | 2010-08-04 00:42:58 +0900 | [diff] [blame] | 98 | virtual bool GetAsString(string16* out_value) const; |
scottbyer@google.com | 673b876 | 2010-12-07 09:35:29 +0900 | [diff] [blame] | 99 | virtual bool GetAsList(ListValue** out_value); |
bauerb@chromium.org | 6878e50 | 2011-07-12 18:04:38 +0900 | [diff] [blame] | 100 | virtual bool GetAsList(const ListValue** out_value) const; |
battre@chromium.org | 29eaa25 | 2011-11-26 10:11:44 +0900 | [diff] [blame] | 101 | virtual bool GetAsDictionary(DictionaryValue** out_value); |
| 102 | virtual bool GetAsDictionary(const DictionaryValue** out_value) const; |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 103 | |
| 104 | // This creates a deep copy of the entire Value tree, and returns a pointer |
| 105 | // to the copy. The caller gets ownership of the copy, of course. |
akalin@chromium.org | 810f92f | 2011-01-18 11:16:59 +0900 | [diff] [blame] | 106 | // |
| 107 | // Subclasses return their own type directly in their overrides; |
| 108 | // this works because C++ supports covariant return types. |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 109 | virtual Value* DeepCopy() const; |
| 110 | |
| 111 | // Compares if two Value objects have equal contents. |
| 112 | virtual bool Equals(const Value* other) const; |
| 113 | |
bauerb@chromium.org | fbd55e1 | 2010-12-07 03:13:43 +0900 | [diff] [blame] | 114 | // Compares if two Value objects have equal contents. Can handle NULLs. |
| 115 | // NULLs are considered equal but different from Value::CreateNullValue(). |
| 116 | static bool Equals(const Value* a, const Value* b); |
| 117 | |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 118 | protected: |
| 119 | // This isn't safe for end-users (they should use the Create*Value() |
| 120 | // static methods above), but it's useful for subclasses. |
tfarina@chromium.org | 254780a | 2011-08-13 05:59:02 +0900 | [diff] [blame] | 121 | explicit Value(Type type); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 122 | |
| 123 | private: |
sky@chromium.org | 8d103c7 | 2011-08-25 06:17:59 +0900 | [diff] [blame] | 124 | Value(); |
jcampan@chromium.org | d110567 | 2009-09-15 01:56:12 +0900 | [diff] [blame] | 125 | |
sky@chromium.org | 8d103c7 | 2011-08-25 06:17:59 +0900 | [diff] [blame] | 126 | Type type_; |
sky@chromium.org | 142c71c | 2011-08-23 12:40:57 +0900 | [diff] [blame] | 127 | |
jcampan@chromium.org | d110567 | 2009-09-15 01:56:12 +0900 | [diff] [blame] | 128 | DISALLOW_COPY_AND_ASSIGN(Value); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 129 | }; |
| 130 | |
| 131 | // FundamentalValue represents the simple fundamental types of values. |
darin@chromium.org | e585bed | 2011-08-06 00:34:00 +0900 | [diff] [blame] | 132 | class BASE_EXPORT FundamentalValue : public Value { |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 133 | public: |
erg@chromium.org | 493f5f6 | 2010-07-16 06:03:54 +0900 | [diff] [blame] | 134 | explicit FundamentalValue(bool in_value); |
| 135 | explicit FundamentalValue(int in_value); |
| 136 | explicit FundamentalValue(double in_value); |
erg@google.com | 2d9b43e | 2010-12-09 03:06:44 +0900 | [diff] [blame] | 137 | virtual ~FundamentalValue(); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 138 | |
tfarina@chromium.org | cc17740 | 2011-08-12 05:56:32 +0900 | [diff] [blame] | 139 | // Overridden from Value: |
| 140 | virtual bool GetAsBoolean(bool* out_value) const OVERRIDE; |
| 141 | virtual bool GetAsInteger(int* out_value) const OVERRIDE; |
| 142 | virtual bool GetAsDouble(double* out_value) const OVERRIDE; |
| 143 | virtual FundamentalValue* DeepCopy() const OVERRIDE; |
| 144 | virtual bool Equals(const Value* other) const OVERRIDE; |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 145 | |
| 146 | private: |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 147 | union { |
| 148 | bool boolean_value_; |
| 149 | int integer_value_; |
arv@chromium.org | 13413eb | 2011-02-01 10:02:07 +0900 | [diff] [blame] | 150 | double double_value_; |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 151 | }; |
jcampan@chromium.org | d110567 | 2009-09-15 01:56:12 +0900 | [diff] [blame] | 152 | |
| 153 | DISALLOW_COPY_AND_ASSIGN(FundamentalValue); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 154 | }; |
| 155 | |
darin@chromium.org | e585bed | 2011-08-06 00:34:00 +0900 | [diff] [blame] | 156 | class BASE_EXPORT StringValue : public Value { |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 157 | public: |
scherkus@chromium.org | 2b923e7 | 2008-12-11 10:23:17 +0900 | [diff] [blame] | 158 | // Initializes a StringValue with a UTF-8 narrow character string. |
jcampan@chromium.org | d110567 | 2009-09-15 01:56:12 +0900 | [diff] [blame] | 159 | explicit StringValue(const std::string& in_value); |
scherkus@chromium.org | 2b923e7 | 2008-12-11 10:23:17 +0900 | [diff] [blame] | 160 | |
munjal@chromium.org | 3b2d3a4 | 2010-01-16 05:09:03 +0900 | [diff] [blame] | 161 | // Initializes a StringValue with a string16. |
| 162 | explicit StringValue(const string16& in_value); |
viettrungluu@chromium.org | 31b80ba | 2010-08-04 00:42:58 +0900 | [diff] [blame] | 163 | |
erg@google.com | 2d9b43e | 2010-12-09 03:06:44 +0900 | [diff] [blame] | 164 | virtual ~StringValue(); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 165 | |
tfarina@chromium.org | cc17740 | 2011-08-12 05:56:32 +0900 | [diff] [blame] | 166 | // Overridden from Value: |
| 167 | virtual bool GetAsString(std::string* out_value) const OVERRIDE; |
| 168 | virtual bool GetAsString(string16* out_value) const OVERRIDE; |
| 169 | virtual StringValue* DeepCopy() const OVERRIDE; |
| 170 | virtual bool Equals(const Value* other) const OVERRIDE; |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 171 | |
| 172 | private: |
scherkus@chromium.org | 2b923e7 | 2008-12-11 10:23:17 +0900 | [diff] [blame] | 173 | std::string value_; |
jcampan@chromium.org | d110567 | 2009-09-15 01:56:12 +0900 | [diff] [blame] | 174 | |
| 175 | DISALLOW_COPY_AND_ASSIGN(StringValue); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 176 | }; |
| 177 | |
darin@chromium.org | e585bed | 2011-08-06 00:34:00 +0900 | [diff] [blame] | 178 | class BASE_EXPORT BinaryValue: public Value { |
jcampan@chromium.org | d110567 | 2009-09-15 01:56:12 +0900 | [diff] [blame] | 179 | public: |
erg@google.com | d5fffd4 | 2011-01-08 03:06:45 +0900 | [diff] [blame] | 180 | virtual ~BinaryValue(); |
| 181 | |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 182 | // Creates a Value to represent a binary buffer. The new object takes |
| 183 | // ownership of the pointer passed in, if successful. |
| 184 | // Returns NULL if buffer is NULL. |
| 185 | static BinaryValue* Create(char* buffer, size_t size); |
| 186 | |
| 187 | // For situations where you want to keep ownership of your buffer, this |
| 188 | // factory method creates a new BinaryValue by copying the contents of the |
| 189 | // buffer that's passed in. |
| 190 | // Returns NULL if buffer is NULL. |
mpcomplete@chromium.org | 554d431 | 2009-10-07 03:15:58 +0900 | [diff] [blame] | 191 | static BinaryValue* CreateWithCopiedBuffer(const char* buffer, size_t size); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 192 | |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 193 | size_t GetSize() const { return size_; } |
| 194 | char* GetBuffer() { return buffer_; } |
mpcomplete@chromium.org | 554d431 | 2009-10-07 03:15:58 +0900 | [diff] [blame] | 195 | const char* GetBuffer() const { return buffer_; } |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 196 | |
erg@google.com | d5fffd4 | 2011-01-08 03:06:45 +0900 | [diff] [blame] | 197 | // Overridden from Value: |
tfarina@chromium.org | cc17740 | 2011-08-12 05:56:32 +0900 | [diff] [blame] | 198 | virtual BinaryValue* DeepCopy() const OVERRIDE; |
| 199 | virtual bool Equals(const Value* other) const OVERRIDE; |
erg@google.com | d5fffd4 | 2011-01-08 03:06:45 +0900 | [diff] [blame] | 200 | |
jcampan@chromium.org | d110567 | 2009-09-15 01:56:12 +0900 | [diff] [blame] | 201 | private: |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 202 | // Constructor is private so that only objects with valid buffer pointers |
| 203 | // and size values can be created. |
deanm@google.com | 522c383 | 2008-08-04 22:56:25 +0900 | [diff] [blame] | 204 | BinaryValue(char* buffer, size_t size); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 205 | |
| 206 | char* buffer_; |
| 207 | size_t size_; |
jcampan@chromium.org | d110567 | 2009-09-15 01:56:12 +0900 | [diff] [blame] | 208 | |
| 209 | DISALLOW_COPY_AND_ASSIGN(BinaryValue); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 210 | }; |
| 211 | |
viettrungluu@chromium.org | 496dec2 | 2010-07-31 13:56:14 +0900 | [diff] [blame] | 212 | // DictionaryValue provides a key-value dictionary with (optional) "path" |
| 213 | // parsing for recursive access; see the comment at the top of the file. Keys |
| 214 | // are |std::string|s and should be UTF-8 encoded. |
darin@chromium.org | e585bed | 2011-08-06 00:34:00 +0900 | [diff] [blame] | 215 | class BASE_EXPORT DictionaryValue : public Value { |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 216 | public: |
erg@chromium.org | 493f5f6 | 2010-07-16 06:03:54 +0900 | [diff] [blame] | 217 | DictionaryValue(); |
erg@google.com | 2d9b43e | 2010-12-09 03:06:44 +0900 | [diff] [blame] | 218 | virtual ~DictionaryValue(); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 219 | |
battre@chromium.org | 29eaa25 | 2011-11-26 10:11:44 +0900 | [diff] [blame] | 220 | // Overridden from Value: |
| 221 | virtual bool GetAsDictionary(DictionaryValue** out_value) OVERRIDE; |
| 222 | virtual bool GetAsDictionary( |
| 223 | const DictionaryValue** out_value) const OVERRIDE; |
| 224 | |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 225 | // Returns true if the current dictionary has a value for the given key. |
viettrungluu@chromium.org | 178423d | 2010-07-31 04:47:47 +0900 | [diff] [blame] | 226 | bool HasKey(const std::string& key) const; |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 227 | |
jcampan@chromium.org | 9b0f7be | 2009-04-15 09:17:53 +0900 | [diff] [blame] | 228 | // Returns the number of Values in this dictionary. |
pkasting@chromium.org | 36515db | 2009-11-26 05:47:52 +0900 | [diff] [blame] | 229 | size_t size() const { return dictionary_.size(); } |
| 230 | |
| 231 | // Returns whether the dictionary is empty. |
| 232 | bool empty() const { return dictionary_.empty(); } |
jcampan@chromium.org | 9b0f7be | 2009-04-15 09:17:53 +0900 | [diff] [blame] | 233 | |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 234 | // Clears any current contents of this dictionary. |
deanm@google.com | 522c383 | 2008-08-04 22:56:25 +0900 | [diff] [blame] | 235 | void Clear(); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 236 | |
| 237 | // Sets the Value associated with the given path starting from this object. |
| 238 | // A path has the form "<key>" or "<key>.<key>.[...]", where "." indexes |
| 239 | // into the next DictionaryValue down. Obviously, "." can't be used |
| 240 | // within a key, but there are no other restrictions on keys. |
| 241 | // If the key at any step of the way doesn't exist, or exists but isn't |
| 242 | // a DictionaryValue, a new DictionaryValue will be created and attached |
| 243 | // to the path in that location. |
jcampan@chromium.org | 9b0f7be | 2009-04-15 09:17:53 +0900 | [diff] [blame] | 244 | // Note that the dictionary takes ownership of the value referenced by |
pkasting@chromium.org | 36515db | 2009-11-26 05:47:52 +0900 | [diff] [blame] | 245 | // |in_value|, and therefore |in_value| must be non-NULL. |
viettrungluu@chromium.org | 178423d | 2010-07-31 04:47:47 +0900 | [diff] [blame] | 246 | void Set(const std::string& path, Value* in_value); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 247 | |
| 248 | // Convenience forms of Set(). These methods will replace any existing |
| 249 | // value at that path, even if it has a different type. |
viettrungluu@chromium.org | 178423d | 2010-07-31 04:47:47 +0900 | [diff] [blame] | 250 | void SetBoolean(const std::string& path, bool in_value); |
| 251 | void SetInteger(const std::string& path, int in_value); |
arv@chromium.org | 13413eb | 2011-02-01 10:02:07 +0900 | [diff] [blame] | 252 | void SetDouble(const std::string& path, double in_value); |
viettrungluu@chromium.org | 178423d | 2010-07-31 04:47:47 +0900 | [diff] [blame] | 253 | void SetString(const std::string& path, const std::string& in_value); |
viettrungluu@chromium.org | b7b6aa0 | 2010-08-05 01:58:12 +0900 | [diff] [blame] | 254 | void SetString(const std::string& path, const string16& in_value); |
pkasting@chromium.org | 36515db | 2009-11-26 05:47:52 +0900 | [diff] [blame] | 255 | |
| 256 | // Like Set(), but without special treatment of '.'. This allows e.g. URLs to |
| 257 | // be used as paths. |
viettrungluu@chromium.org | 178423d | 2010-07-31 04:47:47 +0900 | [diff] [blame] | 258 | void SetWithoutPathExpansion(const std::string& key, Value* in_value); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 259 | |
| 260 | // Gets the Value associated with the given path starting from this object. |
| 261 | // A path has the form "<key>" or "<key>.<key>.[...]", where "." indexes |
| 262 | // into the next DictionaryValue down. If the path can be resolved |
| 263 | // successfully, the value for the last key in the path will be returned |
skerner@chromium.org | 53f71f0 | 2010-04-09 04:06:15 +0900 | [diff] [blame] | 264 | // through the |out_value| parameter, and the function will return true. |
| 265 | // Otherwise, it will return false and |out_value| will be untouched. |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 266 | // Note that the dictionary always owns the value that's returned. |
viettrungluu@chromium.org | 178423d | 2010-07-31 04:47:47 +0900 | [diff] [blame] | 267 | bool Get(const std::string& path, Value** out_value) const; |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 268 | |
| 269 | // These are convenience forms of Get(). The value will be retrieved |
| 270 | // and the return value will be true if the path is valid and the value at |
| 271 | // the end of the path can be returned in the form specified. |
viettrungluu@chromium.org | 178423d | 2010-07-31 04:47:47 +0900 | [diff] [blame] | 272 | bool GetBoolean(const std::string& path, bool* out_value) const; |
| 273 | bool GetInteger(const std::string& path, int* out_value) const; |
arv@chromium.org | 13413eb | 2011-02-01 10:02:07 +0900 | [diff] [blame] | 274 | bool GetDouble(const std::string& path, double* out_value) const; |
viettrungluu@chromium.org | 178423d | 2010-07-31 04:47:47 +0900 | [diff] [blame] | 275 | bool GetString(const std::string& path, std::string* out_value) const; |
viettrungluu@chromium.org | 58767ef | 2010-08-05 04:35:33 +0900 | [diff] [blame] | 276 | bool GetString(const std::string& path, string16* out_value) const; |
evan@chromium.org | d9ab8de | 2010-02-19 22:32:16 +0900 | [diff] [blame] | 277 | bool GetStringASCII(const std::string& path, std::string* out_value) const; |
viettrungluu@chromium.org | 178423d | 2010-07-31 04:47:47 +0900 | [diff] [blame] | 278 | bool GetBinary(const std::string& path, BinaryValue** out_value) const; |
| 279 | bool GetDictionary(const std::string& path, |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 280 | DictionaryValue** out_value) const; |
viettrungluu@chromium.org | 178423d | 2010-07-31 04:47:47 +0900 | [diff] [blame] | 281 | bool GetList(const std::string& path, ListValue** out_value) const; |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 282 | |
pkasting@chromium.org | 36515db | 2009-11-26 05:47:52 +0900 | [diff] [blame] | 283 | // Like Get(), but without special treatment of '.'. This allows e.g. URLs to |
| 284 | // be used as paths. |
viettrungluu@chromium.org | 178423d | 2010-07-31 04:47:47 +0900 | [diff] [blame] | 285 | bool GetWithoutPathExpansion(const std::string& key, |
pkasting@chromium.org | 36515db | 2009-11-26 05:47:52 +0900 | [diff] [blame] | 286 | Value** out_value) const; |
viettrungluu@chromium.org | 178423d | 2010-07-31 04:47:47 +0900 | [diff] [blame] | 287 | bool GetIntegerWithoutPathExpansion(const std::string& key, |
pkasting@chromium.org | 36515db | 2009-11-26 05:47:52 +0900 | [diff] [blame] | 288 | int* out_value) const; |
arv@chromium.org | 13413eb | 2011-02-01 10:02:07 +0900 | [diff] [blame] | 289 | bool GetDoubleWithoutPathExpansion(const std::string& key, |
jam@chromium.org | 5bd5392 | 2010-10-01 16:28:25 +0900 | [diff] [blame] | 290 | double* out_value) const; |
viettrungluu@chromium.org | 178423d | 2010-07-31 04:47:47 +0900 | [diff] [blame] | 291 | bool GetStringWithoutPathExpansion(const std::string& key, |
pkasting@chromium.org | 36515db | 2009-11-26 05:47:52 +0900 | [diff] [blame] | 292 | std::string* out_value) const; |
viettrungluu@chromium.org | 58767ef | 2010-08-05 04:35:33 +0900 | [diff] [blame] | 293 | bool GetStringWithoutPathExpansion(const std::string& key, |
| 294 | string16* out_value) const; |
viettrungluu@chromium.org | 178423d | 2010-07-31 04:47:47 +0900 | [diff] [blame] | 295 | bool GetDictionaryWithoutPathExpansion(const std::string& key, |
pkasting@chromium.org | 36515db | 2009-11-26 05:47:52 +0900 | [diff] [blame] | 296 | DictionaryValue** out_value) const; |
viettrungluu@chromium.org | 178423d | 2010-07-31 04:47:47 +0900 | [diff] [blame] | 297 | bool GetListWithoutPathExpansion(const std::string& key, |
pkasting@chromium.org | 36515db | 2009-11-26 05:47:52 +0900 | [diff] [blame] | 298 | ListValue** out_value) const; |
| 299 | |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 300 | // Removes the Value with the specified path from this dictionary (or one |
| 301 | // of its child dictionaries, if the path is more than just a local key). |
| 302 | // If |out_value| is non-NULL, the removed Value AND ITS OWNERSHIP will be |
| 303 | // passed out via out_value. If |out_value| is NULL, the removed value will |
| 304 | // be deleted. This method returns true if |path| is a valid path; otherwise |
| 305 | // it will return false and the DictionaryValue object will be unchanged. |
viettrungluu@chromium.org | 178423d | 2010-07-31 04:47:47 +0900 | [diff] [blame] | 306 | bool Remove(const std::string& path, Value** out_value); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 307 | |
pkasting@chromium.org | 36515db | 2009-11-26 05:47:52 +0900 | [diff] [blame] | 308 | // Like Remove(), but without special treatment of '.'. This allows e.g. URLs |
| 309 | // to be used as paths. |
viettrungluu@chromium.org | 178423d | 2010-07-31 04:47:47 +0900 | [diff] [blame] | 310 | bool RemoveWithoutPathExpansion(const std::string& key, Value** out_value); |
pkasting@chromium.org | 36515db | 2009-11-26 05:47:52 +0900 | [diff] [blame] | 311 | |
tony@chromium.org | e4948ab | 2009-12-02 09:20:32 +0900 | [diff] [blame] | 312 | // Makes a copy of |this| but doesn't include empty dictionaries and lists in |
| 313 | // the copy. This never returns NULL, even if |this| itself is empty. |
| 314 | DictionaryValue* DeepCopyWithoutEmptyChildren(); |
| 315 | |
mnissler@chromium.org | 17cee0e | 2010-05-14 22:17:40 +0900 | [diff] [blame] | 316 | // Merge a given dictionary into this dictionary. This is done recursively, |
| 317 | // i.e. any subdictionaries will be merged as well. In case of key collisions, |
| 318 | // the passed in dictionary takes precedence and data already present will be |
| 319 | // replaced. |
| 320 | void MergeDictionary(const DictionaryValue* dictionary); |
| 321 | |
akalin@chromium.org | 71cd130 | 2011-05-10 18:23:39 +0900 | [diff] [blame] | 322 | // Swaps contents with the |other| dictionary. |
| 323 | void Swap(DictionaryValue* other) { |
| 324 | dictionary_.swap(other->dictionary_); |
| 325 | } |
| 326 | |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 327 | // This class provides an iterator for the keys in the dictionary. |
| 328 | // It can't be used to modify the dictionary. |
pkasting@chromium.org | 36515db | 2009-11-26 05:47:52 +0900 | [diff] [blame] | 329 | // |
| 330 | // YOU SHOULD ALWAYS USE THE XXXWithoutPathExpansion() APIs WITH THESE, NOT |
| 331 | // THE NORMAL XXX() APIs. This makes sure things will work correctly if any |
| 332 | // keys have '.'s in them. |
darin@chromium.org | 020e0b1 | 2011-04-30 03:08:21 +0900 | [diff] [blame] | 333 | class key_iterator |
viettrungluu@chromium.org | 178423d | 2010-07-31 04:47:47 +0900 | [diff] [blame] | 334 | : private std::iterator<std::input_iterator_tag, const std::string> { |
jar@chromium.org | af39a37 | 2009-02-18 07:50:14 +0900 | [diff] [blame] | 335 | public: |
jcampan@chromium.org | d110567 | 2009-09-15 01:56:12 +0900 | [diff] [blame] | 336 | explicit key_iterator(ValueMap::const_iterator itr) { itr_ = itr; } |
erg@google.com | bf6ce9f | 2010-01-27 08:08:02 +0900 | [diff] [blame] | 337 | key_iterator operator++() { |
| 338 | ++itr_; |
| 339 | return *this; |
| 340 | } |
viettrungluu@chromium.org | 178423d | 2010-07-31 04:47:47 +0900 | [diff] [blame] | 341 | const std::string& operator*() { return itr_->first; } |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 342 | bool operator!=(const key_iterator& other) { return itr_ != other.itr_; } |
| 343 | bool operator==(const key_iterator& other) { return itr_ == other.itr_; } |
| 344 | |
jar@chromium.org | af39a37 | 2009-02-18 07:50:14 +0900 | [diff] [blame] | 345 | private: |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 346 | ValueMap::const_iterator itr_; |
| 347 | }; |
| 348 | |
| 349 | key_iterator begin_keys() const { return key_iterator(dictionary_.begin()); } |
| 350 | key_iterator end_keys() const { return key_iterator(dictionary_.end()); } |
| 351 | |
kalman@chromium.org | 1604ad6 | 2011-11-09 06:26:41 +0900 | [diff] [blame] | 352 | // This class provides an iterator over both keys and values in the |
| 353 | // dictionary. It can't be used to modify the dictionary. |
| 354 | class Iterator { |
| 355 | public: |
| 356 | explicit Iterator(const DictionaryValue& target) |
| 357 | : target_(target), it_(target.dictionary_.begin()) {} |
| 358 | |
| 359 | bool HasNext() const { return it_ != target_.dictionary_.end(); } |
| 360 | void Advance() { ++it_; } |
| 361 | |
| 362 | const std::string& key() const { return it_->first; } |
| 363 | const Value& value() const { return *it_->second; } |
| 364 | |
| 365 | private: |
| 366 | const DictionaryValue& target_; |
| 367 | ValueMap::const_iterator it_; |
| 368 | }; |
| 369 | |
erg@google.com | d5fffd4 | 2011-01-08 03:06:45 +0900 | [diff] [blame] | 370 | // Overridden from Value: |
tfarina@chromium.org | cc17740 | 2011-08-12 05:56:32 +0900 | [diff] [blame] | 371 | virtual DictionaryValue* DeepCopy() const OVERRIDE; |
| 372 | virtual bool Equals(const Value* other) const OVERRIDE; |
erg@google.com | d5fffd4 | 2011-01-08 03:06:45 +0900 | [diff] [blame] | 373 | |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 374 | private: |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 375 | ValueMap dictionary_; |
jcampan@chromium.org | d110567 | 2009-09-15 01:56:12 +0900 | [diff] [blame] | 376 | |
| 377 | DISALLOW_COPY_AND_ASSIGN(DictionaryValue); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 378 | }; |
| 379 | |
| 380 | // This type of Value represents a list of other Value values. |
darin@chromium.org | e585bed | 2011-08-06 00:34:00 +0900 | [diff] [blame] | 381 | class BASE_EXPORT ListValue : public Value { |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 382 | public: |
erg@google.com | d5fffd4 | 2011-01-08 03:06:45 +0900 | [diff] [blame] | 383 | typedef ValueVector::iterator iterator; |
| 384 | typedef ValueVector::const_iterator const_iterator; |
| 385 | |
erg@chromium.org | 493f5f6 | 2010-07-16 06:03:54 +0900 | [diff] [blame] | 386 | ListValue(); |
hans@chromium.org | 78b7593 | 2011-05-25 18:08:19 +0900 | [diff] [blame] | 387 | virtual ~ListValue(); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 388 | |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 389 | // Clears the contents of this ListValue |
| 390 | void Clear(); |
| 391 | |
| 392 | // Returns the number of Values in this list. |
| 393 | size_t GetSize() const { return list_.size(); } |
| 394 | |
tony@chromium.org | e4948ab | 2009-12-02 09:20:32 +0900 | [diff] [blame] | 395 | // Returns whether the list is empty. |
| 396 | bool empty() const { return list_.empty(); } |
| 397 | |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 398 | // Sets the list item at the given index to be the Value specified by |
| 399 | // the value given. If the index beyond the current end of the list, null |
| 400 | // Values will be used to pad out the list. |
| 401 | // Returns true if successful, or false if the index was negative or |
| 402 | // the value is a null pointer. |
| 403 | bool Set(size_t index, Value* in_value); |
| 404 | |
skerner@chromium.org | 53f71f0 | 2010-04-09 04:06:15 +0900 | [diff] [blame] | 405 | // Gets the Value at the given index. Modifies |out_value| (and returns true) |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 406 | // only if the index falls within the current list range. |
skerner@chromium.org | 53f71f0 | 2010-04-09 04:06:15 +0900 | [diff] [blame] | 407 | // Note that the list always owns the Value passed out via |out_value|. |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 408 | bool Get(size_t index, Value** out_value) const; |
| 409 | |
skerner@chromium.org | 53f71f0 | 2010-04-09 04:06:15 +0900 | [diff] [blame] | 410 | // Convenience forms of Get(). Modifies |out_value| (and returns true) |
| 411 | // only if the index is valid and the Value at that index can be returned |
| 412 | // in the specified form. |
aa@chromium.org | c93b02f | 2009-01-21 06:05:32 +0900 | [diff] [blame] | 413 | bool GetBoolean(size_t index, bool* out_value) const; |
| 414 | bool GetInteger(size_t index, int* out_value) const; |
arv@chromium.org | 13413eb | 2011-02-01 10:02:07 +0900 | [diff] [blame] | 415 | bool GetDouble(size_t index, double* out_value) const; |
aa@chromium.org | c93b02f | 2009-01-21 06:05:32 +0900 | [diff] [blame] | 416 | bool GetString(size_t index, std::string* out_value) const; |
viettrungluu@chromium.org | 58767ef | 2010-08-05 04:35:33 +0900 | [diff] [blame] | 417 | bool GetString(size_t index, string16* out_value) const; |
aa@chromium.org | c93b02f | 2009-01-21 06:05:32 +0900 | [diff] [blame] | 418 | bool GetBinary(size_t index, BinaryValue** out_value) const; |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 419 | bool GetDictionary(size_t index, DictionaryValue** out_value) const; |
aa@chromium.org | c93b02f | 2009-01-21 06:05:32 +0900 | [diff] [blame] | 420 | bool GetList(size_t index, ListValue** out_value) const; |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 421 | |
| 422 | // Removes the Value with the specified index from this list. |
| 423 | // If |out_value| is non-NULL, the removed Value AND ITS OWNERSHIP will be |
ericroman@google.com | 3d19ee5 | 2009-01-06 03:37:51 +0900 | [diff] [blame] | 424 | // passed out via |out_value|. If |out_value| is NULL, the removed value will |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 425 | // be deleted. This method returns true if |index| is valid; otherwise |
| 426 | // it will return false and the ListValue object will be unchanged. |
| 427 | bool Remove(size_t index, Value** out_value); |
| 428 | |
pkasting@chromium.org | dfe6a69 | 2009-12-01 04:59:11 +0900 | [diff] [blame] | 429 | // Removes the first instance of |value| found in the list, if any, and |
tfarina@chromium.org | 09cf434 | 2011-08-14 02:34:31 +0900 | [diff] [blame] | 430 | // deletes it. |index| is the location where |value| was found. Returns false |
| 431 | // if not found. |
| 432 | bool Remove(const Value& value, size_t* index); |
pkasting@chromium.org | 727139c | 2009-05-09 09:33:04 +0900 | [diff] [blame] | 433 | |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 434 | // Appends a Value to the end of the list. |
| 435 | void Append(Value* in_value); |
| 436 | |
markusheintz@chromium.org | 7862187 | 2011-03-18 22:56:38 +0900 | [diff] [blame] | 437 | // Appends a Value if it's not already present. Takes ownership of the |
| 438 | // |in_value|. Returns true if successful, or false if the value was already |
| 439 | // present. If the value was already present the |in_value| is deleted. |
zork@chromium.org | b5f742b | 2010-04-13 06:48:10 +0900 | [diff] [blame] | 440 | bool AppendIfNotPresent(Value* in_value); |
| 441 | |
erikkay@chromium.org | 9034a23 | 2009-08-29 05:26:05 +0900 | [diff] [blame] | 442 | // Insert a Value at index. |
| 443 | // Returns true if successful, or false if the index was out of range. |
| 444 | bool Insert(size_t index, Value* in_value); |
| 445 | |
pastarmovj@chromium.org | 1602a47 | 2011-09-20 00:23:10 +0900 | [diff] [blame] | 446 | // Searches for the first instance of |value| in the list using the Equals |
| 447 | // method of the Value type. |
| 448 | // Returns a const_iterator to the found item or to end() if none exists. |
| 449 | const_iterator Find(const Value& value) const; |
| 450 | |
brettw@chromium.org | 2031cd8 | 2010-08-20 03:05:56 +0900 | [diff] [blame] | 451 | // Swaps contents with the |other| list. |
| 452 | void Swap(ListValue* other) { |
| 453 | list_.swap(other->list_); |
| 454 | } |
| 455 | |
tfarina@chromium.org | cc17740 | 2011-08-12 05:56:32 +0900 | [diff] [blame] | 456 | // Iteration. |
| 457 | iterator begin() { return list_.begin(); } |
| 458 | iterator end() { return list_.end(); } |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 459 | |
tfarina@chromium.org | cc17740 | 2011-08-12 05:56:32 +0900 | [diff] [blame] | 460 | const_iterator begin() const { return list_.begin(); } |
| 461 | const_iterator end() const { return list_.end(); } |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 462 | |
erg@google.com | d5fffd4 | 2011-01-08 03:06:45 +0900 | [diff] [blame] | 463 | // Overridden from Value: |
tfarina@chromium.org | cc17740 | 2011-08-12 05:56:32 +0900 | [diff] [blame] | 464 | virtual bool GetAsList(ListValue** out_value) OVERRIDE; |
| 465 | virtual bool GetAsList(const ListValue** out_value) const OVERRIDE; |
| 466 | virtual ListValue* DeepCopy() const OVERRIDE; |
| 467 | virtual bool Equals(const Value* other) const OVERRIDE; |
erg@google.com | d5fffd4 | 2011-01-08 03:06:45 +0900 | [diff] [blame] | 468 | |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 469 | private: |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 470 | ValueVector list_; |
jcampan@chromium.org | d110567 | 2009-09-15 01:56:12 +0900 | [diff] [blame] | 471 | |
| 472 | DISALLOW_COPY_AND_ASSIGN(ListValue); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 473 | }; |
| 474 | |
| 475 | // This interface is implemented by classes that know how to serialize and |
| 476 | // deserialize Value objects. |
darin@chromium.org | e585bed | 2011-08-06 00:34:00 +0900 | [diff] [blame] | 477 | class BASE_EXPORT ValueSerializer { |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 478 | public: |
erg@chromium.org | 493f5f6 | 2010-07-16 06:03:54 +0900 | [diff] [blame] | 479 | virtual ~ValueSerializer(); |
mmentovai@google.com | 4a5b627 | 2008-08-07 00:46:59 +0900 | [diff] [blame] | 480 | |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 481 | virtual bool Serialize(const Value& root) = 0; |
| 482 | |
| 483 | // This method deserializes the subclass-specific format into a Value object. |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 484 | // If the return value is non-NULL, the caller takes ownership of returned |
erikkay@chromium.org | 64b2cf4 | 2010-04-07 00:42:39 +0900 | [diff] [blame] | 485 | // Value. If the return value is NULL, and if error_code is non-NULL, |
| 486 | // error_code will be set with the underlying error. |
| 487 | // If |error_message| is non-null, it will be filled in with a formatted |
| 488 | // error message including the location of the error if appropriate. |
| 489 | virtual Value* Deserialize(int* error_code, std::string* error_str) = 0; |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 490 | }; |
| 491 | |
dmazzoni@chromium.org | 13e5365 | 2011-07-13 04:15:03 +0900 | [diff] [blame] | 492 | } // namespace base |
| 493 | |
| 494 | // http://crbug.com/88666 |
dmazzoni@chromium.org | 13e5365 | 2011-07-13 04:15:03 +0900 | [diff] [blame] | 495 | using base::DictionaryValue; |
dmazzoni@chromium.org | 13e5365 | 2011-07-13 04:15:03 +0900 | [diff] [blame] | 496 | using base::ListValue; |
| 497 | using base::StringValue; |
| 498 | using base::Value; |
dmazzoni@chromium.org | 13e5365 | 2011-07-13 04:15:03 +0900 | [diff] [blame] | 499 | |
darin@chromium.org | 01f1070 | 2008-09-27 05:22:42 +0900 | [diff] [blame] | 500 | #endif // BASE_VALUES_H_ |