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 #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 Loading... |
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(const BinaryValue** 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 Loading... |
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(const BinaryValue** out_value) const { |
| 327 if (out_value) |
| 328 *out_value = this; |
| 329 return true; |
| 330 } |
| 331 |
322 BinaryValue* BinaryValue::DeepCopy() const { | 332 BinaryValue* BinaryValue::DeepCopy() const { |
323 return CreateWithCopiedBuffer(buffer_.get(), size_); | 333 return CreateWithCopiedBuffer(buffer_.get(), size_); |
324 } | 334 } |
325 | 335 |
326 bool BinaryValue::Equals(const Value* other) const { | 336 bool BinaryValue::Equals(const Value* other) const { |
327 if (other->GetType() != GetType()) | 337 if (other->GetType() != GetType()) |
328 return false; | 338 return false; |
329 const BinaryValue* other_binary = static_cast<const BinaryValue*>(other); | 339 const BinaryValue* other_binary = static_cast<const BinaryValue*>(other); |
330 if (other_binary->size_ != size_) | 340 if (other_binary->size_ != size_) |
331 return false; | 341 return false; |
(...skipping 803 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1135 | 1145 |
1136 std::ostream& operator<<(std::ostream& out, const Value& value) { | 1146 std::ostream& operator<<(std::ostream& out, const Value& value) { |
1137 std::string json; | 1147 std::string json; |
1138 JSONWriter::WriteWithOptions(&value, | 1148 JSONWriter::WriteWithOptions(&value, |
1139 JSONWriter::OPTIONS_PRETTY_PRINT, | 1149 JSONWriter::OPTIONS_PRETTY_PRINT, |
1140 &json); | 1150 &json); |
1141 return out << json; | 1151 return out << json; |
1142 } | 1152 } |
1143 | 1153 |
1144 } // namespace base | 1154 } // namespace base |
OLD | NEW |