Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(150)

Side by Side Diff: base/values.h

Issue 820673004: json_schema_compiler: Use std::vector<char> for binary values. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@simplify_json_schema
Patch Set: Fix merge error. Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | base/values.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 15 matching lines...) Expand all
26 #include <vector> 26 #include <vector>
27 27
28 #include "base/base_export.h" 28 #include "base/base_export.h"
29 #include "base/basictypes.h" 29 #include "base/basictypes.h"
30 #include "base/compiler_specific.h" 30 #include "base/compiler_specific.h"
31 #include "base/memory/scoped_ptr.h" 31 #include "base/memory/scoped_ptr.h"
32 #include "base/strings/string16.h" 32 #include "base/strings/string16.h"
33 33
34 namespace base { 34 namespace base {
35 35
36 class BinaryValue;
36 class DictionaryValue; 37 class DictionaryValue;
37 class FundamentalValue; 38 class FundamentalValue;
38 class ListValue; 39 class ListValue;
39 class StringValue; 40 class StringValue;
40 class Value; 41 class Value;
41 42
42 typedef std::vector<Value*> ValueVector; 43 typedef std::vector<Value*> ValueVector;
43 typedef std::map<std::string, Value*> ValueMap; 44 typedef std::map<std::string, Value*> ValueMap;
44 45
45 // The Value class is the base class for Values. A Value can be instantiated 46 // The Value class is the base class for Values. A Value can be instantiated
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 // These methods allow the convenient retrieval of the contents of the Value. 79 // These methods allow the convenient retrieval of the contents of the Value.
79 // If the current object can be converted into the given type, the value is 80 // If the current object can be converted into the given type, the value is
80 // returned through the |out_value| parameter and true is returned; 81 // returned through the |out_value| parameter and true is returned;
81 // otherwise, false is returned and |out_value| is unchanged. 82 // otherwise, false is returned and |out_value| is unchanged.
82 virtual bool GetAsBoolean(bool* out_value) const; 83 virtual bool GetAsBoolean(bool* out_value) const;
83 virtual bool GetAsInteger(int* out_value) const; 84 virtual bool GetAsInteger(int* out_value) const;
84 virtual bool GetAsDouble(double* out_value) const; 85 virtual bool GetAsDouble(double* out_value) const;
85 virtual bool GetAsString(std::string* out_value) const; 86 virtual bool GetAsString(std::string* out_value) const;
86 virtual bool GetAsString(string16* out_value) const; 87 virtual bool GetAsString(string16* out_value) const;
87 virtual bool GetAsString(const StringValue** out_value) const; 88 virtual bool GetAsString(const StringValue** out_value) const;
89 virtual bool GetAsBinary(const BinaryValue** out_value) const;
88 virtual bool GetAsList(ListValue** out_value); 90 virtual bool GetAsList(ListValue** out_value);
89 virtual bool GetAsList(const ListValue** out_value) const; 91 virtual bool GetAsList(const ListValue** out_value) const;
90 virtual bool GetAsDictionary(DictionaryValue** out_value); 92 virtual bool GetAsDictionary(DictionaryValue** out_value);
91 virtual bool GetAsDictionary(const DictionaryValue** out_value) const; 93 virtual bool GetAsDictionary(const DictionaryValue** out_value) const;
92 // Note: Do not add more types. See the file-level comment above for why. 94 // Note: Do not add more types. See the file-level comment above for why.
93 95
94 // This creates a deep copy of the entire Value tree, and returns a pointer 96 // This creates a deep copy of the entire Value tree, and returns a pointer
95 // to the copy. The caller gets ownership of the copy, of course. 97 // to the copy. The caller gets ownership of the copy, of course.
96 // 98 //
97 // Subclasses return their own type directly in their overrides; 99 // Subclasses return their own type directly in their overrides;
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 // buffer that's passed in. 183 // buffer that's passed in.
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 187
186 // May return NULL. 188 // May return NULL.
187 char* GetBuffer() { return buffer_.get(); } 189 char* GetBuffer() { return buffer_.get(); }
188 const char* GetBuffer() const { return buffer_.get(); } 190 const char* GetBuffer() const { return buffer_.get(); }
189 191
190 // Overridden from Value: 192 // Overridden from Value:
193 bool GetAsBinary(const BinaryValue** out_value) const override;
191 BinaryValue* DeepCopy() const override; 194 BinaryValue* DeepCopy() const override;
192 bool Equals(const Value* other) const override; 195 bool Equals(const Value* other) const override;
193 196
194 private: 197 private:
195 scoped_ptr<char[]> buffer_; 198 scoped_ptr<char[]> buffer_;
196 size_t size_; 199 size_t size_;
197 200
198 DISALLOW_COPY_AND_ASSIGN(BinaryValue); 201 DISALLOW_COPY_AND_ASSIGN(BinaryValue);
199 }; 202 };
200 203
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 } 531 }
529 532
530 BASE_EXPORT inline std::ostream& operator<<(std::ostream& out, 533 BASE_EXPORT inline std::ostream& operator<<(std::ostream& out,
531 const ListValue& value) { 534 const ListValue& value) {
532 return out << static_cast<const Value&>(value); 535 return out << static_cast<const Value&>(value);
533 } 536 }
534 537
535 } // namespace base 538 } // namespace base
536 539
537 #endif // BASE_VALUES_H_ 540 #endif // BASE_VALUES_H_
OLDNEW
« no previous file with comments | « no previous file | base/values.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698