diff options
Diffstat (limited to 'base')
-rw-r--r-- | base/json/json_reader_unittest.cc | 20 | ||||
-rw-r--r-- | base/values.cc | 34 | ||||
-rw-r--r-- | base/values.h | 5 | ||||
-rw-r--r-- | base/values_unittest.cc | 17 |
4 files changed, 28 insertions, 48 deletions
diff --git a/base/json/json_reader_unittest.cc b/base/json/json_reader_unittest.cc index 7623a68..a7aeaf0 100644 --- a/base/json/json_reader_unittest.cc +++ b/base/json/json_reader_unittest.cc @@ -222,8 +222,8 @@ TEST(JSONReaderTest, Reading) { // Basic array root.reset(JSONReader::Read("[true, false, null]", false)); ASSERT_TRUE(root.get()); - ListValue* list = root->AsList(); - ASSERT_TRUE(list); + ASSERT_TRUE(root->IsType(Value::TYPE_LIST)); + ListValue* list = static_cast<ListValue*>(root.get()); ASSERT_EQ(3U, list->GetSize()); // Test with trailing comma. Should be parsed the same as above. @@ -234,16 +234,16 @@ TEST(JSONReaderTest, Reading) { // Empty array root.reset(JSONReader::Read("[]", false)); ASSERT_TRUE(root.get()); - list = root->AsList(); - ASSERT_TRUE(list); + ASSERT_TRUE(root->IsType(Value::TYPE_LIST)); + list = static_cast<ListValue*>(root.get()); ASSERT_EQ(0U, list->GetSize()); // Nested arrays root.reset(JSONReader::Read("[[true], [], [false, [], [null]], null]", false)); ASSERT_TRUE(root.get()); - list = root->AsList(); - ASSERT_TRUE(list); + ASSERT_TRUE(root->IsType(Value::TYPE_LIST)); + list = static_cast<ListValue*>(root.get()); ASSERT_EQ(4U, list->GetSize()); // Lots of trailing commas. @@ -272,8 +272,8 @@ TEST(JSONReaderTest, Reading) { // Valid if we set |allow_trailing_comma| to true. root.reset(JSONReader::Read("[true,]", true)); ASSERT_TRUE(root.get()); - list = root->AsList(); - ASSERT_TRUE(list); + ASSERT_TRUE(root->IsType(Value::TYPE_LIST)); + list = static_cast<ListValue*>(root.get()); EXPECT_EQ(1U, list->GetSize()); Value* tmp_value = NULL; ASSERT_TRUE(list->Get(0, &tmp_value)); @@ -435,8 +435,8 @@ TEST(JSONReaderTest, Reading) { not_evil.append("[]]"); root.reset(JSONReader::Read(not_evil, false)); ASSERT_TRUE(root.get()); - list = root->AsList(); - ASSERT_TRUE(list); + ASSERT_TRUE(root->IsType(Value::TYPE_LIST)); + list = static_cast<ListValue*>(root.get()); ASSERT_EQ(5001U, list->GetSize()); // Test utf8 encoded input diff --git a/base/values.cc b/base/values.cc index ad53469..17aba16 100644 --- a/base/values.cc +++ b/base/values.cc @@ -18,7 +18,7 @@ Value* CopyWithoutEmptyChildren(Value* node) { DCHECK(node); switch (node->GetType()) { case Value::TYPE_LIST: { - ListValue* list = node->AsList(); + ListValue* list = static_cast<ListValue*>(node); ListValue* copy = new ListValue; for (ListValue::const_iterator it = list->begin(); it != list->end(); ++it) { @@ -97,14 +97,6 @@ StringValue* Value::CreateStringValue(const string16& in_value) { return new StringValue(in_value); } -BinaryValue* Value::AsBinary() { - return NULL; -} - -ListValue* Value::AsList() { - return NULL; -} - bool Value::GetAsBoolean(bool* out_value) const { return false; } @@ -305,10 +297,6 @@ BinaryValue* BinaryValue::CreateWithCopiedBuffer(const char* buffer, return new BinaryValue(buffer_copy, size); } -BinaryValue* BinaryValue::AsBinary() { - return this; -} - BinaryValue* BinaryValue::DeepCopy() const { return CreateWithCopiedBuffer(buffer_, size_); } @@ -497,11 +485,11 @@ bool DictionaryValue::GetBinary(const std::string& path, BinaryValue** out_value) const { Value* value; bool result = Get(path, &value); - if (!result || !value->AsBinary()) + if (!result || !value->IsType(TYPE_BINARY)) return false; if (out_value) - *out_value = value->AsBinary(); + *out_value = static_cast<BinaryValue*>(value); return true; } @@ -523,11 +511,11 @@ bool DictionaryValue::GetList(const std::string& path, ListValue** out_value) const { Value* value; bool result = Get(path, &value); - if (!result || !value->AsList()) + if (!result || !value->IsType(TYPE_LIST)) return false; if (out_value) - *out_value = value->AsList(); + *out_value = static_cast<ListValue*>(value); return true; } @@ -601,11 +589,11 @@ bool DictionaryValue::GetListWithoutPathExpansion(const std::string& key, ListValue** out_value) const { Value* value; bool result = GetWithoutPathExpansion(key, &value); - if (!result || !value->AsList()) + if (!result || !value->IsType(TYPE_LIST)) return false; if (out_value) - *out_value = value->AsList(); + *out_value = static_cast<ListValue*>(value); return true; } @@ -814,11 +802,11 @@ bool ListValue::GetDictionary(size_t index, DictionaryValue** out_value) const { bool ListValue::GetList(size_t index, ListValue** out_value) const { Value* value; bool result = Get(index, &value); - if (!result || !value->AsList()) + if (!result || !value->IsType(TYPE_LIST)) return false; if (out_value) - *out_value = value->AsList(); + *out_value = static_cast<ListValue*>(value); return true; } @@ -877,10 +865,6 @@ bool ListValue::Insert(size_t index, Value* in_value) { return true; } -ListValue* ListValue::AsList() { - return this; -} - bool ListValue::GetAsList(ListValue** out_value) { if (out_value) *out_value = this; diff --git a/base/values.h b/base/values.h index 185729d..a30791b 100644 --- a/base/values.h +++ b/base/values.h @@ -87,9 +87,6 @@ class BASE_EXPORT Value { // Returns true if the current object represents a given type. bool IsType(Type type) const { return type == type_; } - virtual BinaryValue* AsBinary(); - virtual ListValue* AsList(); - // These methods allow the convenient retrieval of settings. // If the current setting object can be converted into the given type, // the value is returned through the |out_value| parameter and true is @@ -196,7 +193,6 @@ class BASE_EXPORT BinaryValue: public Value { const char* GetBuffer() const { return buffer_; } // Overridden from Value: - virtual BinaryValue* AsBinary() OVERRIDE; virtual BinaryValue* DeepCopy() const OVERRIDE; virtual bool Equals(const Value* other) const OVERRIDE; @@ -435,7 +431,6 @@ class BASE_EXPORT ListValue : public Value { const_iterator end() const { return list_.end(); } // Overridden from Value: - virtual ListValue* AsList() OVERRIDE; virtual bool GetAsList(ListValue** out_value) OVERRIDE; virtual bool GetAsList(const ListValue** out_value) const OVERRIDE; virtual ListValue* DeepCopy() const OVERRIDE; diff --git a/base/values_unittest.cc b/base/values_unittest.cc index 0ca19d9..553e8e1 100644 --- a/base/values_unittest.cc +++ b/base/values_unittest.cc @@ -416,20 +416,21 @@ TEST(ValuesTest, DeepCopy) { ASSERT_TRUE(copy_dict->Get("binary", ©_binary)); ASSERT_TRUE(copy_binary); ASSERT_NE(copy_binary, original_binary); - BinaryValue* binary_value = copy_binary->AsBinary(); - ASSERT_TRUE(binary_value); - ASSERT_NE(original_binary->GetBuffer(), binary_value->GetBuffer()); - ASSERT_EQ(original_binary->GetSize(), binary_value->GetSize()); + ASSERT_TRUE(copy_binary->IsType(Value::TYPE_BINARY)); + ASSERT_NE(original_binary->GetBuffer(), + static_cast<BinaryValue*>(copy_binary)->GetBuffer()); + ASSERT_EQ(original_binary->GetSize(), + static_cast<BinaryValue*>(copy_binary)->GetSize()); ASSERT_EQ(0, memcmp(original_binary->GetBuffer(), - binary_value->GetBuffer(), - original_binary->GetSize())); + static_cast<BinaryValue*>(copy_binary)->GetBuffer(), + original_binary->GetSize())); Value* copy_value = NULL; ASSERT_TRUE(copy_dict->Get("list", ©_value)); ASSERT_TRUE(copy_value); ASSERT_NE(copy_value, original_list); - ListValue* copy_list = copy_value->AsList(); - ASSERT_TRUE(copy_list != NULL); + ASSERT_TRUE(copy_value->IsType(Value::TYPE_LIST)); + ListValue* copy_list = static_cast<ListValue*>(copy_value); ASSERT_EQ(2U, copy_list->GetSize()); Value* copy_list_element_0; |