Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2544)

Unified Diff: base/values.cc

Issue 7748017: base: Add AsBinary() function to Value API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/values.cc
diff --git a/base/values.cc b/base/values.cc
index 1798695b59a86bd13482eedb6eb4a4160f4a84db..ad534696b389b537dc4333876c78f9a84247583a 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;
}
« no previous file with comments | « base/values.h ('k') | base/values_unittest.cc » ('j') | base/values_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698