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

Side by Side Diff: base/values.cc

Issue 851673003: Cleanup: Some simplifications in json_schema_compiler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@fix_dart_tests
Patch Set: Add unit test for GetAsBinary. 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
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 #include "base/values.h" 5 #include "base/values.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <ostream> 10 #include <ostream>
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 } // namespace 82 } // namespace
83 83
84 Value::~Value() { 84 Value::~Value() {
85 } 85 }
86 86
87 // static 87 // static
88 Value* Value::CreateNullValue() { 88 Value* Value::CreateNullValue() {
89 return new Value(TYPE_NULL); 89 return new Value(TYPE_NULL);
90 } 90 }
91 91
92 bool Value::GetAsBinary(std::string* out_value) const {
93 return false;
94 }
95
92 bool Value::GetAsBoolean(bool* out_value) const { 96 bool Value::GetAsBoolean(bool* out_value) const {
93 return false; 97 return false;
94 } 98 }
95 99
96 bool Value::GetAsInteger(int* out_value) const { 100 bool Value::GetAsInteger(int* out_value) const {
97 return false; 101 return false;
98 } 102 }
99 103
100 bool Value::GetAsDouble(double* out_value) const { 104 bool Value::GetAsDouble(double* out_value) const {
101 return false; 105 return false;
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 316
313 // static 317 // static
314 BinaryValue* BinaryValue::CreateWithCopiedBuffer(const char* buffer, 318 BinaryValue* BinaryValue::CreateWithCopiedBuffer(const char* buffer,
315 size_t size) { 319 size_t size) {
316 char* buffer_copy = new char[size]; 320 char* buffer_copy = new char[size];
317 memcpy(buffer_copy, buffer, size); 321 memcpy(buffer_copy, buffer, size);
318 scoped_ptr<char[]> scoped_buffer_copy(buffer_copy); 322 scoped_ptr<char[]> scoped_buffer_copy(buffer_copy);
319 return new BinaryValue(scoped_buffer_copy.Pass(), size); 323 return new BinaryValue(scoped_buffer_copy.Pass(), size);
320 } 324 }
321 325
326 bool BinaryValue::GetAsBinary(std::string* out_value) const {
327 out_value->assign(buffer_.get(), size_);
328 return true;
329 }
330
322 BinaryValue* BinaryValue::DeepCopy() const { 331 BinaryValue* BinaryValue::DeepCopy() const {
323 return CreateWithCopiedBuffer(buffer_.get(), size_); 332 return CreateWithCopiedBuffer(buffer_.get(), size_);
324 } 333 }
325 334
326 bool BinaryValue::Equals(const Value* other) const { 335 bool BinaryValue::Equals(const Value* other) const {
327 if (other->GetType() != GetType()) 336 if (other->GetType() != GetType())
328 return false; 337 return false;
329 const BinaryValue* other_binary = static_cast<const BinaryValue*>(other); 338 const BinaryValue* other_binary = static_cast<const BinaryValue*>(other);
330 if (other_binary->size_ != size_) 339 if (other_binary->size_ != size_)
331 return false; 340 return false;
(...skipping 803 matching lines...) Expand 10 before | Expand all | Expand 10 after
1135 1144
1136 std::ostream& operator<<(std::ostream& out, const Value& value) { 1145 std::ostream& operator<<(std::ostream& out, const Value& value) {
1137 std::string json; 1146 std::string json;
1138 JSONWriter::WriteWithOptions(&value, 1147 JSONWriter::WriteWithOptions(&value,
1139 JSONWriter::OPTIONS_PRETTY_PRINT, 1148 JSONWriter::OPTIONS_PRETTY_PRINT,
1140 &json); 1149 &json);
1141 return out << json; 1150 return out << json;
1142 } 1151 }
1143 1152
1144 } // namespace base 1153 } // namespace base
OLDNEW
« base/values.h ('K') | « base/values.h ('k') | base/values_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698