| 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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 | 117 |
| 118 // FundamentalValue represents the simple fundamental types of values. | 118 // FundamentalValue represents the simple fundamental types of values. |
| 119 class BASE_EXPORT FundamentalValue : public Value { | 119 class BASE_EXPORT FundamentalValue : public Value { |
| 120 public: | 120 public: |
| 121 explicit FundamentalValue(bool in_value); | 121 explicit FundamentalValue(bool in_value); |
| 122 explicit FundamentalValue(int in_value); | 122 explicit FundamentalValue(int in_value); |
| 123 explicit FundamentalValue(double in_value); | 123 explicit FundamentalValue(double in_value); |
| 124 virtual ~FundamentalValue(); | 124 virtual ~FundamentalValue(); |
| 125 | 125 |
| 126 // Overridden from Value: | 126 // Overridden from Value: |
| 127 virtual bool GetAsBoolean(bool* out_value) const OVERRIDE; | 127 virtual bool GetAsBoolean(bool* out_value) const override; |
| 128 virtual bool GetAsInteger(int* out_value) const OVERRIDE; | 128 virtual bool GetAsInteger(int* out_value) const override; |
| 129 // Values of both type TYPE_INTEGER and TYPE_DOUBLE can be obtained as | 129 // Values of both type TYPE_INTEGER and TYPE_DOUBLE can be obtained as |
| 130 // doubles. | 130 // doubles. |
| 131 virtual bool GetAsDouble(double* out_value) const OVERRIDE; | 131 virtual bool GetAsDouble(double* out_value) const override; |
| 132 virtual FundamentalValue* DeepCopy() const OVERRIDE; | 132 virtual FundamentalValue* DeepCopy() const override; |
| 133 virtual bool Equals(const Value* other) const OVERRIDE; | 133 virtual bool Equals(const Value* other) const override; |
| 134 | 134 |
| 135 private: | 135 private: |
| 136 union { | 136 union { |
| 137 bool boolean_value_; | 137 bool boolean_value_; |
| 138 int integer_value_; | 138 int integer_value_; |
| 139 double double_value_; | 139 double double_value_; |
| 140 }; | 140 }; |
| 141 }; | 141 }; |
| 142 | 142 |
| 143 class BASE_EXPORT StringValue : public Value { | 143 class BASE_EXPORT StringValue : public Value { |
| 144 public: | 144 public: |
| 145 // Initializes a StringValue with a UTF-8 narrow character string. | 145 // Initializes a StringValue with a UTF-8 narrow character string. |
| 146 explicit StringValue(const std::string& in_value); | 146 explicit StringValue(const std::string& in_value); |
| 147 | 147 |
| 148 // Initializes a StringValue with a string16. | 148 // Initializes a StringValue with a string16. |
| 149 explicit StringValue(const string16& in_value); | 149 explicit StringValue(const string16& in_value); |
| 150 | 150 |
| 151 virtual ~StringValue(); | 151 virtual ~StringValue(); |
| 152 | 152 |
| 153 // Returns |value_| as a pointer or reference. | 153 // Returns |value_| as a pointer or reference. |
| 154 std::string* GetString(); | 154 std::string* GetString(); |
| 155 const std::string& GetString() const; | 155 const std::string& GetString() const; |
| 156 | 156 |
| 157 // Overridden from Value: | 157 // Overridden from Value: |
| 158 virtual bool GetAsString(std::string* out_value) const OVERRIDE; | 158 virtual bool GetAsString(std::string* out_value) const override; |
| 159 virtual bool GetAsString(string16* out_value) const OVERRIDE; | 159 virtual bool GetAsString(string16* out_value) const override; |
| 160 virtual bool GetAsString(const StringValue** out_value) const OVERRIDE; | 160 virtual bool GetAsString(const StringValue** out_value) const override; |
| 161 virtual StringValue* DeepCopy() const OVERRIDE; | 161 virtual StringValue* DeepCopy() const override; |
| 162 virtual bool Equals(const Value* other) const OVERRIDE; | 162 virtual bool Equals(const Value* other) const override; |
| 163 | 163 |
| 164 private: | 164 private: |
| 165 std::string value_; | 165 std::string value_; |
| 166 }; | 166 }; |
| 167 | 167 |
| 168 class BASE_EXPORT BinaryValue: public Value { | 168 class BASE_EXPORT BinaryValue: public Value { |
| 169 public: | 169 public: |
| 170 // Creates a BinaryValue with a null buffer and size of 0. | 170 // Creates a BinaryValue with a null buffer and size of 0. |
| 171 BinaryValue(); | 171 BinaryValue(); |
| 172 | 172 |
| 173 // Creates a BinaryValue, taking ownership of the bytes pointed to by | 173 // Creates a BinaryValue, taking ownership of the bytes pointed to by |
| 174 // |buffer|. | 174 // |buffer|. |
| 175 BinaryValue(scoped_ptr<char[]> buffer, size_t size); | 175 BinaryValue(scoped_ptr<char[]> buffer, size_t size); |
| 176 | 176 |
| 177 virtual ~BinaryValue(); | 177 virtual ~BinaryValue(); |
| 178 | 178 |
| 179 // For situations where you want to keep ownership of your buffer, this | 179 // For situations where you want to keep ownership of your buffer, this |
| 180 // factory method creates a new BinaryValue by copying the contents of the | 180 // factory method creates a new BinaryValue by copying the contents of the |
| 181 // buffer that's passed in. | 181 // buffer that's passed in. |
| 182 static BinaryValue* CreateWithCopiedBuffer(const char* buffer, size_t size); | 182 static BinaryValue* CreateWithCopiedBuffer(const char* buffer, size_t size); |
| 183 | 183 |
| 184 size_t GetSize() const { return size_; } | 184 size_t GetSize() const { return size_; } |
| 185 | 185 |
| 186 // May return NULL. | 186 // May return NULL. |
| 187 char* GetBuffer() { return buffer_.get(); } | 187 char* GetBuffer() { return buffer_.get(); } |
| 188 const char* GetBuffer() const { return buffer_.get(); } | 188 const char* GetBuffer() const { return buffer_.get(); } |
| 189 | 189 |
| 190 // Overridden from Value: | 190 // Overridden from Value: |
| 191 virtual BinaryValue* DeepCopy() const OVERRIDE; | 191 virtual BinaryValue* DeepCopy() const override; |
| 192 virtual bool Equals(const Value* other) const OVERRIDE; | 192 virtual bool Equals(const Value* other) const override; |
| 193 | 193 |
| 194 private: | 194 private: |
| 195 scoped_ptr<char[]> buffer_; | 195 scoped_ptr<char[]> buffer_; |
| 196 size_t size_; | 196 size_t size_; |
| 197 | 197 |
| 198 DISALLOW_COPY_AND_ASSIGN(BinaryValue); | 198 DISALLOW_COPY_AND_ASSIGN(BinaryValue); |
| 199 }; | 199 }; |
| 200 | 200 |
| 201 // DictionaryValue provides a key-value dictionary with (optional) "path" | 201 // DictionaryValue provides a key-value dictionary with (optional) "path" |
| 202 // parsing for recursive access; see the comment at the top of the file. Keys | 202 // parsing for recursive access; see the comment at the top of the file. Keys |
| 203 // are |std::string|s and should be UTF-8 encoded. | 203 // are |std::string|s and should be UTF-8 encoded. |
| 204 class BASE_EXPORT DictionaryValue : public Value { | 204 class BASE_EXPORT DictionaryValue : public Value { |
| 205 public: | 205 public: |
| 206 DictionaryValue(); | 206 DictionaryValue(); |
| 207 virtual ~DictionaryValue(); | 207 virtual ~DictionaryValue(); |
| 208 | 208 |
| 209 // Overridden from Value: | 209 // Overridden from Value: |
| 210 virtual bool GetAsDictionary(DictionaryValue** out_value) OVERRIDE; | 210 virtual bool GetAsDictionary(DictionaryValue** out_value) override; |
| 211 virtual bool GetAsDictionary( | 211 virtual bool GetAsDictionary( |
| 212 const DictionaryValue** out_value) const OVERRIDE; | 212 const DictionaryValue** out_value) const override; |
| 213 | 213 |
| 214 // Returns true if the current dictionary has a value for the given key. | 214 // Returns true if the current dictionary has a value for the given key. |
| 215 bool HasKey(const std::string& key) const; | 215 bool HasKey(const std::string& key) const; |
| 216 | 216 |
| 217 // Returns the number of Values in this dictionary. | 217 // Returns the number of Values in this dictionary. |
| 218 size_t size() const { return dictionary_.size(); } | 218 size_t size() const { return dictionary_.size(); } |
| 219 | 219 |
| 220 // Returns whether the dictionary is empty. | 220 // Returns whether the dictionary is empty. |
| 221 bool empty() const { return dictionary_.empty(); } | 221 bool empty() const { return dictionary_.empty(); } |
| 222 | 222 |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 | 355 |
| 356 const std::string& key() const { return it_->first; } | 356 const std::string& key() const { return it_->first; } |
| 357 const Value& value() const { return *it_->second; } | 357 const Value& value() const { return *it_->second; } |
| 358 | 358 |
| 359 private: | 359 private: |
| 360 const DictionaryValue& target_; | 360 const DictionaryValue& target_; |
| 361 ValueMap::const_iterator it_; | 361 ValueMap::const_iterator it_; |
| 362 }; | 362 }; |
| 363 | 363 |
| 364 // Overridden from Value: | 364 // Overridden from Value: |
| 365 virtual DictionaryValue* DeepCopy() const OVERRIDE; | 365 virtual DictionaryValue* DeepCopy() const override; |
| 366 virtual bool Equals(const Value* other) const OVERRIDE; | 366 virtual bool Equals(const Value* other) const override; |
| 367 | 367 |
| 368 private: | 368 private: |
| 369 ValueMap dictionary_; | 369 ValueMap dictionary_; |
| 370 | 370 |
| 371 DISALLOW_COPY_AND_ASSIGN(DictionaryValue); | 371 DISALLOW_COPY_AND_ASSIGN(DictionaryValue); |
| 372 }; | 372 }; |
| 373 | 373 |
| 374 // This type of Value represents a list of other Value values. | 374 // This type of Value represents a list of other Value values. |
| 375 class BASE_EXPORT ListValue : public Value { | 375 class BASE_EXPORT ListValue : public Value { |
| 376 public: | 376 public: |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 virtual void Swap(ListValue* other); | 469 virtual void Swap(ListValue* other); |
| 470 | 470 |
| 471 // Iteration. | 471 // Iteration. |
| 472 iterator begin() { return list_.begin(); } | 472 iterator begin() { return list_.begin(); } |
| 473 iterator end() { return list_.end(); } | 473 iterator end() { return list_.end(); } |
| 474 | 474 |
| 475 const_iterator begin() const { return list_.begin(); } | 475 const_iterator begin() const { return list_.begin(); } |
| 476 const_iterator end() const { return list_.end(); } | 476 const_iterator end() const { return list_.end(); } |
| 477 | 477 |
| 478 // Overridden from Value: | 478 // Overridden from Value: |
| 479 virtual bool GetAsList(ListValue** out_value) OVERRIDE; | 479 virtual bool GetAsList(ListValue** out_value) override; |
| 480 virtual bool GetAsList(const ListValue** out_value) const OVERRIDE; | 480 virtual bool GetAsList(const ListValue** out_value) const override; |
| 481 virtual ListValue* DeepCopy() const OVERRIDE; | 481 virtual ListValue* DeepCopy() const override; |
| 482 virtual bool Equals(const Value* other) const OVERRIDE; | 482 virtual bool Equals(const Value* other) const override; |
| 483 | 483 |
| 484 private: | 484 private: |
| 485 ValueVector list_; | 485 ValueVector list_; |
| 486 | 486 |
| 487 DISALLOW_COPY_AND_ASSIGN(ListValue); | 487 DISALLOW_COPY_AND_ASSIGN(ListValue); |
| 488 }; | 488 }; |
| 489 | 489 |
| 490 // This interface is implemented by classes that know how to serialize and | 490 // This interface is implemented by classes that know how to serialize and |
| 491 // deserialize Value objects. | 491 // deserialize Value objects. |
| 492 class BASE_EXPORT ValueSerializer { | 492 class BASE_EXPORT ValueSerializer { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 } | 526 } |
| 527 | 527 |
| 528 BASE_EXPORT inline std::ostream& operator<<(std::ostream& out, | 528 BASE_EXPORT inline std::ostream& operator<<(std::ostream& out, |
| 529 const ListValue& value) { | 529 const ListValue& value) { |
| 530 return out << static_cast<const Value&>(value); | 530 return out << static_cast<const Value&>(value); |
| 531 } | 531 } |
| 532 | 532 |
| 533 } // namespace base | 533 } // namespace base |
| 534 | 534 |
| 535 #endif // BASE_VALUES_H_ | 535 #endif // BASE_VALUES_H_ |
| OLD | NEW |