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 <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/float_util.h" | 9 #include "base/float_util.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
291 | 291 |
292 bool StringValue::Equals(const Value* other) const { | 292 bool StringValue::Equals(const Value* other) const { |
293 if (other->GetType() != GetType()) | 293 if (other->GetType() != GetType()) |
294 return false; | 294 return false; |
295 std::string lhs, rhs; | 295 std::string lhs, rhs; |
296 return GetAsString(&lhs) && other->GetAsString(&rhs) && lhs == rhs; | 296 return GetAsString(&lhs) && other->GetAsString(&rhs) && lhs == rhs; |
297 } | 297 } |
298 | 298 |
299 ///////////////////// BinaryValue //////////////////// | 299 ///////////////////// BinaryValue //////////////////// |
300 | 300 |
301 BinaryValue::~BinaryValue() { | 301 BinaryValue::BinaryValue() |
302 DCHECK(buffer_); | 302 : Value(TYPE_BINARY), |
brettw
2012/05/18 23:20:31
Indent these initializers 2 more spaces. Same for
| |
303 if (buffer_) | 303 buffer_(NULL), |
304 delete[] buffer_; | 304 size_(0) { |
305 } | 305 } |
306 | 306 |
307 // static | 307 BinaryValue::BinaryValue(scoped_ptr<char> buffer, size_t size) |
308 BinaryValue* BinaryValue::Create(char* buffer, size_t size) { | 308 : Value(TYPE_BINARY), |
309 if (!buffer) | 309 buffer_(buffer.release()), |
310 return NULL; | 310 size_(size) { |
311 | |
312 return new BinaryValue(buffer, size); | |
313 } | 311 } |
314 | 312 |
315 // static | 313 // static |
316 BinaryValue* BinaryValue::CreateWithCopiedBuffer(const char* buffer, | 314 BinaryValue* BinaryValue::CreateWithCopiedBuffer(const char* buffer, |
317 size_t size) { | 315 size_t size) { |
318 if (!buffer) | |
319 return NULL; | |
320 | |
321 char* buffer_copy = new char[size]; | 316 char* buffer_copy = new char[size]; |
322 memcpy(buffer_copy, buffer, size); | 317 memcpy(buffer_copy, buffer, size); |
323 return new BinaryValue(buffer_copy, size); | 318 scoped_ptr<char> scoped_buffer_copy(buffer_copy); |
319 return new BinaryValue(scoped_buffer_copy.Pass(), size); | |
324 } | 320 } |
325 | 321 |
326 BinaryValue* BinaryValue::DeepCopy() const { | 322 BinaryValue* BinaryValue::DeepCopy() const { |
327 return CreateWithCopiedBuffer(buffer_, size_); | 323 return CreateWithCopiedBuffer(buffer_.get(), size_); |
328 } | 324 } |
329 | 325 |
330 bool BinaryValue::Equals(const Value* other) const { | 326 bool BinaryValue::Equals(const Value* other) const { |
331 if (other->GetType() != GetType()) | 327 if (other->GetType() != GetType()) |
332 return false; | 328 return false; |
333 const BinaryValue* other_binary = static_cast<const BinaryValue*>(other); | 329 const BinaryValue* other_binary = static_cast<const BinaryValue*>(other); |
334 if (other_binary->size_ != size_) | 330 if (other_binary->size_ != size_) |
335 return false; | 331 return false; |
336 return !memcmp(buffer_, other_binary->buffer_, size_); | 332 return !memcmp(GetBuffer(), other_binary->GetBuffer(), size_); |
337 } | |
338 | |
339 BinaryValue::BinaryValue(char* buffer, size_t size) | |
340 : Value(TYPE_BINARY), | |
341 buffer_(buffer), | |
342 size_(size) { | |
343 DCHECK(buffer_); | |
344 } | 333 } |
345 | 334 |
346 ///////////////////// DictionaryValue //////////////////// | 335 ///////////////////// DictionaryValue //////////////////// |
347 | 336 |
348 DictionaryValue::DictionaryValue() | 337 DictionaryValue::DictionaryValue() |
349 : Value(TYPE_DICTIONARY) { | 338 : Value(TYPE_DICTIONARY) { |
350 } | 339 } |
351 | 340 |
352 DictionaryValue::~DictionaryValue() { | 341 DictionaryValue::~DictionaryValue() { |
353 Clear(); | 342 Clear(); |
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
953 if (lhs_it != end() || rhs_it != other_list->end()) | 942 if (lhs_it != end() || rhs_it != other_list->end()) |
954 return false; | 943 return false; |
955 | 944 |
956 return true; | 945 return true; |
957 } | 946 } |
958 | 947 |
959 ValueSerializer::~ValueSerializer() { | 948 ValueSerializer::~ValueSerializer() { |
960 } | 949 } |
961 | 950 |
962 } // namespace base | 951 } // namespace base |
OLD | NEW |