summaryrefslogtreecommitdiffstats
path: root/base/values.cc
diff options
context:
space:
mode:
authortfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-25 17:41:10 +0000
committertfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-25 17:41:10 +0000
commit053430d6e7e91fa67a5d371bf881534b3ba07a07 (patch)
tree0314b9fb4cab72d05a9037af3dfe1cdff1dc93d5 /base/values.cc
parent59c9f17a96e85f4589483a0133715ab373700930 (diff)
downloadchromium_src-053430d6e7e91fa67a5d371bf881534b3ba07a07.zip
chromium_src-053430d6e7e91fa67a5d371bf881534b3ba07a07.tar.gz
chromium_src-053430d6e7e91fa67a5d371bf881534b3ba07a07.tar.bz2
base: Add AsBinary() function to Value API.
This function should simplify some constructions. Instead of: if (!value->IsType(Value::TYPE_BINARY)) return false; BinaryValue* binary_value = static_cast<BinaryValue*>(value); You can do: BinaryValue* binary_value = value->AsBinary(); if (!binary_value) return false; BUG=None TEST=base_unittests --gtest_filter=Values* R=evan@chromium.org Review URL: http://codereview.chromium.org/7748017 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@98266 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/values.cc')
-rw-r--r--base/values.cc20
1 files changed, 14 insertions, 6 deletions
diff --git a/base/values.cc b/base/values.cc
index 1798695..ad53469 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 = static_cast<ListValue*>(node);
+ ListValue* list = node->AsList();
ListValue* copy = new ListValue;
for (ListValue::const_iterator it = list->begin(); it != list->end();
++it) {
@@ -97,6 +97,10 @@ StringValue* Value::CreateStringValue(const string16& in_value) {
return new StringValue(in_value);
}
+BinaryValue* Value::AsBinary() {
+ return NULL;
+}
+
ListValue* Value::AsList() {
return NULL;
}
@@ -301,6 +305,10 @@ 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_);
}
@@ -489,11 +497,11 @@ bool DictionaryValue::GetBinary(const std::string& path,
BinaryValue** out_value) const {
Value* value;
bool result = Get(path, &value);
- if (!result || !value->IsType(TYPE_BINARY))
+ if (!result || !value->AsBinary())
return false;
if (out_value)
- *out_value = static_cast<BinaryValue*>(value);
+ *out_value = value->AsBinary();
return true;
}
@@ -519,7 +527,7 @@ bool DictionaryValue::GetList(const std::string& path,
return false;
if (out_value)
- *out_value = static_cast<ListValue*>(value);
+ *out_value = value->AsList();
return true;
}
@@ -597,7 +605,7 @@ bool DictionaryValue::GetListWithoutPathExpansion(const std::string& key,
return false;
if (out_value)
- *out_value = static_cast<ListValue*>(value);
+ *out_value = value->AsList();
return true;
}
@@ -810,7 +818,7 @@ bool ListValue::GetList(size_t index, ListValue** out_value) const {
return false;
if (out_value)
- *out_value = static_cast<ListValue*>(value);
+ *out_value = value->AsList();
return true;
}