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 12 matching lines...) Expand all Loading... |
23 #pragma once | 23 #pragma once |
24 | 24 |
25 #include <iterator> | 25 #include <iterator> |
26 #include <map> | 26 #include <map> |
27 #include <string> | 27 #include <string> |
28 #include <vector> | 28 #include <vector> |
29 | 29 |
30 #include "base/base_export.h" | 30 #include "base/base_export.h" |
31 #include "base/basictypes.h" | 31 #include "base/basictypes.h" |
32 #include "base/compiler_specific.h" | 32 #include "base/compiler_specific.h" |
33 #include "base/memory/scoped_ptr.h" | |
34 #include "base/string16.h" | 33 #include "base/string16.h" |
35 | 34 |
36 // 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 |
37 // current code can use these classes without the base namespace. In | 36 // current code can use these classes without the base namespace. In |
38 // 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 |
39 // "using" declaration. | 38 // "using" declaration. |
40 // http://crbug.com/88666 | 39 // http://crbug.com/88666 |
41 namespace base { | 40 namespace base { |
42 | 41 |
43 class BinaryValue; | 42 class BinaryValue; |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 virtual bool Equals(const Value* other) const OVERRIDE; | 170 virtual bool Equals(const Value* other) const OVERRIDE; |
172 | 171 |
173 private: | 172 private: |
174 std::string value_; | 173 std::string value_; |
175 | 174 |
176 DISALLOW_COPY_AND_ASSIGN(StringValue); | 175 DISALLOW_COPY_AND_ASSIGN(StringValue); |
177 }; | 176 }; |
178 | 177 |
179 class BASE_EXPORT BinaryValue: public Value { | 178 class BASE_EXPORT BinaryValue: public Value { |
180 public: | 179 public: |
181 // Creates a BinaryValue with a null buffer and size of 0. | 180 virtual ~BinaryValue(); |
182 BinaryValue(); | |
183 | 181 |
184 // Creates a BinaryValue, taking ownership of the bytes pointed to by | 182 // Creates a Value to represent a binary buffer. The new object takes |
185 // |buffer|. | 183 // ownership of the pointer passed in, if successful. |
186 BinaryValue(scoped_ptr<char> buffer, size_t size); | 184 // Returns NULL if buffer is NULL. |
187 | 185 static BinaryValue* Create(char* buffer, size_t size); |
188 virtual ~BinaryValue(); | |
189 | 186 |
190 // For situations where you want to keep ownership of your buffer, this | 187 // For situations where you want to keep ownership of your buffer, this |
191 // factory method creates a new BinaryValue by copying the contents of the | 188 // factory method creates a new BinaryValue by copying the contents of the |
192 // buffer that's passed in. | 189 // buffer that's passed in. |
| 190 // Returns NULL if buffer is NULL. |
193 static BinaryValue* CreateWithCopiedBuffer(const char* buffer, size_t size); | 191 static BinaryValue* CreateWithCopiedBuffer(const char* buffer, size_t size); |
194 | 192 |
195 size_t GetSize() const { return size_; } | 193 size_t GetSize() const { return size_; } |
196 | 194 char* GetBuffer() { return buffer_; } |
197 // May return NULL. | 195 const char* GetBuffer() const { return buffer_; } |
198 char* GetBuffer() { return buffer_.get(); } | |
199 const char* GetBuffer() const { return buffer_.get(); } | |
200 | 196 |
201 // Overridden from Value: | 197 // Overridden from Value: |
202 virtual BinaryValue* DeepCopy() const OVERRIDE; | 198 virtual BinaryValue* DeepCopy() const OVERRIDE; |
203 virtual bool Equals(const Value* other) const OVERRIDE; | 199 virtual bool Equals(const Value* other) const OVERRIDE; |
204 | 200 |
205 private: | 201 private: |
206 scoped_ptr<char> buffer_; | 202 // Constructor is private so that only objects with valid buffer pointers |
| 203 // and size values can be created. |
| 204 BinaryValue(char* buffer, size_t size); |
| 205 |
| 206 char* buffer_; |
207 size_t size_; | 207 size_t size_; |
208 | 208 |
209 DISALLOW_COPY_AND_ASSIGN(BinaryValue); | 209 DISALLOW_COPY_AND_ASSIGN(BinaryValue); |
210 }; | 210 }; |
211 | 211 |
212 // DictionaryValue provides a key-value dictionary with (optional) "path" | 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 | 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. | 214 // are |std::string|s and should be UTF-8 encoded. |
215 class BASE_EXPORT DictionaryValue : public Value { | 215 class BASE_EXPORT DictionaryValue : public Value { |
216 public: | 216 public: |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 | 489 |
490 } // namespace base | 490 } // namespace base |
491 | 491 |
492 // http://crbug.com/88666 | 492 // http://crbug.com/88666 |
493 using base::DictionaryValue; | 493 using base::DictionaryValue; |
494 using base::ListValue; | 494 using base::ListValue; |
495 using base::StringValue; | 495 using base::StringValue; |
496 using base::Value; | 496 using base::Value; |
497 | 497 |
498 #endif // BASE_VALUES_H_ | 498 #endif // BASE_VALUES_H_ |
OLD | NEW |