| 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 setting and other persistable data. It includes the ability to | 6 // storing setting and other persistable data. It includes the ability to |
| 7 // specify (recursive) lists and dictionaries, so it's fairly expressive. | 7 // specify (recursive) lists and dictionaries, so it's fairly expressive. |
| 8 // However, the API is optimized for the common case, namely storing a | 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 | 9 // hierarchical tree of simple values. Given a DictionaryValue root, you can |
| 10 // easily do things like: | 10 // easily do things like: |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #define BASE_VALUES_H_ | 22 #define BASE_VALUES_H_ |
| 23 | 23 |
| 24 #include <iterator> | 24 #include <iterator> |
| 25 #include <map> | 25 #include <map> |
| 26 #include <string> | 26 #include <string> |
| 27 #include <vector> | 27 #include <vector> |
| 28 | 28 |
| 29 #include "base/base_export.h" | 29 #include "base/base_export.h" |
| 30 #include "base/basictypes.h" | 30 #include "base/basictypes.h" |
| 31 #include "base/compiler_specific.h" | 31 #include "base/compiler_specific.h" |
| 32 #include "base/memory/scoped_ptr.h" |
| 32 #include "base/string16.h" | 33 #include "base/string16.h" |
| 33 | 34 |
| 34 // This file declares "using base::Value", etc. at the bottom, so that | 35 // 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 // 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 // new code, please always use base::Value, etc. or add your own |
| 37 // "using" declaration. | 38 // "using" declaration. |
| 38 // http://crbug.com/88666 | 39 // http://crbug.com/88666 |
| 39 namespace base { | 40 namespace base { |
| 40 | 41 |
| 41 class BinaryValue; | 42 class BinaryValue; |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 virtual bool GetAsString(string16* out_value) const OVERRIDE; | 162 virtual bool GetAsString(string16* out_value) const OVERRIDE; |
| 162 virtual StringValue* DeepCopy() const OVERRIDE; | 163 virtual StringValue* DeepCopy() const OVERRIDE; |
| 163 virtual bool Equals(const Value* other) const OVERRIDE; | 164 virtual bool Equals(const Value* other) const OVERRIDE; |
| 164 | 165 |
| 165 private: | 166 private: |
| 166 std::string value_; | 167 std::string value_; |
| 167 }; | 168 }; |
| 168 | 169 |
| 169 class BASE_EXPORT BinaryValue: public Value { | 170 class BASE_EXPORT BinaryValue: public Value { |
| 170 public: | 171 public: |
| 172 // Creates a BinaryValue with a null buffer and size of 0. |
| 173 BinaryValue(); |
| 174 |
| 175 // Creates a BinaryValue, taking ownership of the bytes pointed to by |
| 176 // |buffer|. |
| 177 BinaryValue(scoped_array<char> buffer, size_t size); |
| 178 |
| 171 virtual ~BinaryValue(); | 179 virtual ~BinaryValue(); |
| 172 | 180 |
| 173 // Creates a Value to represent a binary buffer. The new object takes | |
| 174 // ownership of the pointer passed in, if successful. | |
| 175 // Returns NULL if buffer is NULL. | |
| 176 static BinaryValue* Create(char* buffer, size_t size); | |
| 177 | |
| 178 // For situations where you want to keep ownership of your buffer, this | 181 // For situations where you want to keep ownership of your buffer, this |
| 179 // factory method creates a new BinaryValue by copying the contents of the | 182 // factory method creates a new BinaryValue by copying the contents of the |
| 180 // buffer that's passed in. | 183 // buffer that's passed in. |
| 181 // Returns NULL if buffer is NULL. | |
| 182 static BinaryValue* CreateWithCopiedBuffer(const char* buffer, size_t size); | 184 static BinaryValue* CreateWithCopiedBuffer(const char* buffer, size_t size); |
| 183 | 185 |
| 184 size_t GetSize() const { return size_; } | 186 size_t GetSize() const { return size_; } |
| 185 char* GetBuffer() { return buffer_; } | 187 |
| 186 const char* GetBuffer() const { return buffer_; } | 188 // May return NULL. |
| 189 char* GetBuffer() { return buffer_.get(); } |
| 190 const char* GetBuffer() const { return buffer_.get(); } |
| 187 | 191 |
| 188 // Overridden from Value: | 192 // Overridden from Value: |
| 189 virtual BinaryValue* DeepCopy() const OVERRIDE; | 193 virtual BinaryValue* DeepCopy() const OVERRIDE; |
| 190 virtual bool Equals(const Value* other) const OVERRIDE; | 194 virtual bool Equals(const Value* other) const OVERRIDE; |
| 191 | 195 |
| 192 private: | 196 private: |
| 193 // Constructor is private so that only objects with valid buffer pointers | 197 scoped_array<char> buffer_; |
| 194 // and size values can be created. | |
| 195 BinaryValue(char* buffer, size_t size); | |
| 196 | |
| 197 char* buffer_; | |
| 198 size_t size_; | 198 size_t size_; |
| 199 | 199 |
| 200 DISALLOW_COPY_AND_ASSIGN(BinaryValue); | 200 DISALLOW_COPY_AND_ASSIGN(BinaryValue); |
| 201 }; | 201 }; |
| 202 | 202 |
| 203 // DictionaryValue provides a key-value dictionary with (optional) "path" | 203 // DictionaryValue provides a key-value dictionary with (optional) "path" |
| 204 // parsing for recursive access; see the comment at the top of the file. Keys | 204 // parsing for recursive access; see the comment at the top of the file. Keys |
| 205 // are |std::string|s and should be UTF-8 encoded. | 205 // are |std::string|s and should be UTF-8 encoded. |
| 206 class BASE_EXPORT DictionaryValue : public Value { | 206 class BASE_EXPORT DictionaryValue : public Value { |
| 207 public: | 207 public: |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 | 522 |
| 523 } // namespace base | 523 } // namespace base |
| 524 | 524 |
| 525 // http://crbug.com/88666 | 525 // http://crbug.com/88666 |
| 526 using base::DictionaryValue; | 526 using base::DictionaryValue; |
| 527 using base::ListValue; | 527 using base::ListValue; |
| 528 using base::StringValue; | 528 using base::StringValue; |
| 529 using base::Value; | 529 using base::Value; |
| 530 | 530 |
| 531 #endif // BASE_VALUES_H_ | 531 #endif // BASE_VALUES_H_ |
| OLD | NEW |