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" | |
33 #include "base/string16.h" | 34 #include "base/string16.h" |
34 | 35 |
35 // This file declares "using base::Value", etc. at the bottom, so that | 36 // 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 // 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 // new code, please always use base::Value, etc. or add your own |
38 // "using" declaration. | 39 // "using" declaration. |
39 // http://crbug.com/88666 | 40 // http://crbug.com/88666 |
40 namespace base { | 41 namespace base { |
41 | 42 |
42 class BinaryValue; | 43 class BinaryValue; |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
170 virtual bool Equals(const Value* other) const OVERRIDE; | 171 virtual bool Equals(const Value* other) const OVERRIDE; |
171 | 172 |
172 private: | 173 private: |
173 std::string value_; | 174 std::string value_; |
174 | 175 |
175 DISALLOW_COPY_AND_ASSIGN(StringValue); | 176 DISALLOW_COPY_AND_ASSIGN(StringValue); |
176 }; | 177 }; |
177 | 178 |
178 class BASE_EXPORT BinaryValue: public Value { | 179 class BASE_EXPORT BinaryValue: public Value { |
179 public: | 180 public: |
180 virtual ~BinaryValue(); | 181 // Creates a BinaryValue with a NULL buffer and size of 0. |
181 | 182 BinaryValue(); |
182 // Creates a Value to represent a binary buffer. The new object takes | 183 BinaryValue(scoped_ptr<char> buffer, size_t size); |
asargent_no_longer_on_chrome
2012/05/18 22:49:49
nit: it might be worth adding a comment above this
mitchellwrosen
2012/05/18 23:04:29
Done.
| |
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 | 184 |
187 // For situations where you want to keep ownership of your buffer, this | 185 // 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 | 186 // factory method creates a new BinaryValue by copying the contents of the |
189 // buffer that's passed in. | 187 // buffer that's passed in. |
190 // Returns NULL if buffer is NULL. | |
191 static BinaryValue* CreateWithCopiedBuffer(const char* buffer, size_t size); | 188 static BinaryValue* CreateWithCopiedBuffer(const char* buffer, size_t size); |
192 | 189 |
193 size_t GetSize() const { return size_; } | 190 size_t GetSize() const { return size_; } |
194 char* GetBuffer() { return buffer_; } | 191 |
195 const char* GetBuffer() const { return buffer_; } | 192 // May return NULL. |
193 char* GetBuffer() { return buffer_.get(); } | |
194 const char* GetBuffer() const { return buffer_.get(); } | |
196 | 195 |
197 // Overridden from Value: | 196 // Overridden from Value: |
198 virtual BinaryValue* DeepCopy() const OVERRIDE; | 197 virtual BinaryValue* DeepCopy() const OVERRIDE; |
199 virtual bool Equals(const Value* other) const OVERRIDE; | 198 virtual bool Equals(const Value* other) const OVERRIDE; |
200 | 199 |
201 private: | 200 private: |
202 // Constructor is private so that only objects with valid buffer pointers | 201 scoped_ptr<char> buffer_; |
203 // and size values can be created. | |
204 BinaryValue(char* buffer, size_t size); | |
205 | |
206 char* buffer_; | |
207 size_t size_; | 202 size_t size_; |
208 | 203 |
209 DISALLOW_COPY_AND_ASSIGN(BinaryValue); | 204 DISALLOW_COPY_AND_ASSIGN(BinaryValue); |
210 }; | 205 }; |
211 | 206 |
212 // DictionaryValue provides a key-value dictionary with (optional) "path" | 207 // DictionaryValue provides a key-value dictionary with (optional) "path" |
213 // parsing for recursive access; see the comment at the top of the file. Keys | 208 // 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. | 209 // are |std::string|s and should be UTF-8 encoded. |
215 class BASE_EXPORT DictionaryValue : public Value { | 210 class BASE_EXPORT DictionaryValue : public Value { |
216 public: | 211 public: |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
489 | 484 |
490 } // namespace base | 485 } // namespace base |
491 | 486 |
492 // http://crbug.com/88666 | 487 // http://crbug.com/88666 |
493 using base::DictionaryValue; | 488 using base::DictionaryValue; |
494 using base::ListValue; | 489 using base::ListValue; |
495 using base::StringValue; | 490 using base::StringValue; |
496 using base::Value; | 491 using base::Value; |
497 | 492 |
498 #endif // BASE_VALUES_H_ | 493 #endif // BASE_VALUES_H_ |
OLD | NEW |