diff options
Diffstat (limited to 'chromium/base/values.cc')
-rw-r--r-- | chromium/base/values.cc | 65 |
1 files changed, 54 insertions, 11 deletions
diff --git a/chromium/base/values.cc b/chromium/base/values.cc index 5d45ec36c55..4093eba67aa 100644 --- a/chromium/base/values.cc +++ b/chromium/base/values.cc @@ -7,9 +7,9 @@ #include <string.h> #include <algorithm> +#include <cmath> #include <ostream> -#include "base/float_util.h" #include "base/json/json_writer.h" #include "base/logging.h" #include "base/move.h" @@ -85,8 +85,12 @@ Value::~Value() { } // static -Value* Value::CreateNullValue() { - return new Value(TYPE_NULL); +scoped_ptr<Value> Value::CreateNullValue() { + return make_scoped_ptr(new Value(TYPE_NULL)); +} + +bool Value::GetAsBinary(const BinaryValue** out_value) const { + return false; } bool Value::GetAsBoolean(bool* out_value) const { @@ -133,7 +137,11 @@ Value* Value::DeepCopy() const { // This method should only be getting called for null Values--all subclasses // need to provide their own implementation;. DCHECK(IsType(TYPE_NULL)); - return CreateNullValue(); + return CreateNullValue().release(); +} + +scoped_ptr<Value> Value::CreateDeepCopy() const { + return make_scoped_ptr(DeepCopy()); } bool Value::Equals(const Value* other) const { @@ -171,7 +179,7 @@ FundamentalValue::FundamentalValue(int in_value) FundamentalValue::FundamentalValue(double in_value) : Value(TYPE_DOUBLE), double_value_(in_value) { - if (!IsFinite(double_value_)) { + if (!std::isfinite(double_value_)) { NOTREACHED() << "Non-finite (i.e. NaN or positive/negative infinity) " << "values cannot be represented in JSON"; double_value_ = 0.0; @@ -319,6 +327,12 @@ BinaryValue* BinaryValue::CreateWithCopiedBuffer(const char* buffer, return new BinaryValue(scoped_buffer_copy.Pass(), size); } +bool BinaryValue::GetAsBinary(const BinaryValue** out_value) const { + if (out_value) + *out_value = this; + return true; +} + BinaryValue* BinaryValue::DeepCopy() const { return CreateWithCopiedBuffer(buffer_.get(), size_); } @@ -371,7 +385,7 @@ void DictionaryValue::Clear() { dictionary_.clear(); } -void DictionaryValue::Set(const std::string& path, Value* in_value) { +void DictionaryValue::Set(const std::string& path, scoped_ptr<Value> in_value) { DCHECK(IsStringUTF8(path)); DCHECK(in_value); @@ -392,7 +406,11 @@ void DictionaryValue::Set(const std::string& path, Value* in_value) { current_path.erase(0, delimiter_position + 1); } - current_dictionary->SetWithoutPathExpansion(current_path, in_value); + current_dictionary->SetWithoutPathExpansion(current_path, in_value.Pass()); +} + +void DictionaryValue::Set(const std::string& path, Value* in_value) { + Set(path, make_scoped_ptr(in_value)); } void DictionaryValue::SetBoolean(const std::string& path, bool in_value) { @@ -418,18 +436,24 @@ void DictionaryValue::SetString(const std::string& path, } void DictionaryValue::SetWithoutPathExpansion(const std::string& key, - Value* in_value) { + scoped_ptr<Value> in_value) { + Value* bare_ptr = in_value.release(); // If there's an existing value here, we need to delete it, because // we own all our children. std::pair<ValueMap::iterator, bool> ins_res = - dictionary_.insert(std::make_pair(key, in_value)); + dictionary_.insert(std::make_pair(key, bare_ptr)); if (!ins_res.second) { - DCHECK_NE(ins_res.first->second, in_value); // This would be bogus + DCHECK_NE(ins_res.first->second, bare_ptr); // This would be bogus delete ins_res.first->second; - ins_res.first->second = in_value; + ins_res.first->second = bare_ptr; } } +void DictionaryValue::SetWithoutPathExpansion(const std::string& key, + Value* in_value) { + SetWithoutPathExpansion(key, make_scoped_ptr(in_value)); +} + void DictionaryValue::SetBooleanWithoutPathExpansion( const std::string& path, bool in_value) { SetWithoutPathExpansion(path, new FundamentalValue(in_value)); @@ -809,6 +833,10 @@ DictionaryValue* DictionaryValue::DeepCopy() const { return result; } +scoped_ptr<DictionaryValue> DictionaryValue::CreateDeepCopy() const { + return make_scoped_ptr(DeepCopy()); +} + bool DictionaryValue::Equals(const Value* other) const { if (other->GetType() != GetType()) return false; @@ -863,6 +891,10 @@ bool ListValue::Set(size_t index, Value* in_value) { return true; } +bool ListValue::Set(size_t index, scoped_ptr<Value> in_value) { + return Set(index, in_value.release()); +} + bool ListValue::Get(size_t index, const Value** out_value) const { if (index >= list_.size()) return false; @@ -1012,6 +1044,10 @@ ListValue::iterator ListValue::Erase(iterator iter, return list_.erase(iter); } +void ListValue::Append(scoped_ptr<Value> in_value) { + Append(in_value.release()); +} + void ListValue::Append(Value* in_value) { DCHECK(in_value); list_.push_back(in_value); @@ -1101,6 +1137,10 @@ ListValue* ListValue::DeepCopy() const { return result; } +scoped_ptr<ListValue> ListValue::CreateDeepCopy() const { + return make_scoped_ptr(DeepCopy()); +} + bool ListValue::Equals(const Value* other) const { if (other->GetType() != GetType()) return false; @@ -1123,6 +1163,9 @@ bool ListValue::Equals(const Value* other) const { ValueSerializer::~ValueSerializer() { } +ValueDeserializer::~ValueDeserializer() { +} + std::ostream& operator<<(std::ostream& out, const Value& value) { std::string json; JSONWriter::WriteWithOptions(&value, |