diff options
author | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-25 14:03:30 +0000 |
---|---|---|
committer | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-25 14:03:30 +0000 |
commit | a7f1806937d541ab67e37dcc7451783679599384 (patch) | |
tree | ed879290929ef74833ca5e0af979c46a29297456 /base/values.h | |
parent | 36d11e440238728c7854490485cc00c674a6e420 (diff) | |
download | chromium_src-a7f1806937d541ab67e37dcc7451783679599384.zip chromium_src-a7f1806937d541ab67e37dcc7451783679599384.tar.gz chromium_src-a7f1806937d541ab67e37dcc7451783679599384.tar.bz2 |
base: Add AsList() function to Value API.
This function should simplify some constructions.
Instead of:
if (!value->IsType(Value::TYPE_LIST))
return false;
ListValue* list_value = static_cast<ListValue*>(value);
You can do:
ListValue* list_value = value->AsList();
if (!list_value)
return false;
BUG=None
TEST=base_unittests --gtest_filter=Values*
R=evan@chromium.org,tony@chromium.org
Review URL: http://codereview.chromium.org/7714004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@98223 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/values.h')
-rw-r--r-- | base/values.h | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/base/values.h b/base/values.h index a30791b..2f41215 100644 --- a/base/values.h +++ b/base/values.h @@ -87,6 +87,8 @@ class BASE_EXPORT Value { // Returns true if the current object represents a given type. bool IsType(Type type) const { return type == type_; } + 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 @@ -431,6 +433,7 @@ 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; |