diff options
author | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-20 21:05:32 +0000 |
---|---|---|
committer | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-20 21:05:32 +0000 |
commit | f82fb495a3ccffc3d2a9fbb215a2e1723acee954 (patch) | |
tree | 99c7d26f6fdbeef40235751cb9344c537e83df49 /base/values.cc | |
parent | d1afe0ea2e4df1543bc3f67d2f191b6c032ce119 (diff) | |
download | chromium_src-f82fb495a3ccffc3d2a9fbb215a2e1723acee954.zip chromium_src-f82fb495a3ccffc3d2a9fbb215a2e1723acee954.tar.gz chromium_src-f82fb495a3ccffc3d2a9fbb215a2e1723acee954.tar.bz2 |
Flesh out ListValue class.
Review URL: http://codereview.chromium.org/18200
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@8315 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/values.cc')
-rw-r--r-- | base/values.cc | 61 |
1 files changed, 58 insertions, 3 deletions
diff --git a/base/values.cc b/base/values.cc index 75b8e4f..cf98c0b 100644 --- a/base/values.cc +++ b/base/values.cc @@ -245,7 +245,7 @@ void DictionaryValue::Clear() { dictionary_.clear(); } -bool DictionaryValue::HasKey(const std::wstring& key) { +bool DictionaryValue::HasKey(const std::wstring& key) const { ValueMap::const_iterator current_entry = dictionary_.find(key); DCHECK((current_entry == dictionary_.end()) || current_entry->second); return current_entry != dictionary_.end(); @@ -532,8 +532,51 @@ bool ListValue::Get(size_t index, Value** out_value) const { return true; } -bool ListValue::GetDictionary(size_t index, - DictionaryValue** out_value) const { +bool ListValue::GetBoolean(size_t index, bool* bool_value) const { + Value* value; + if (!Get(index, &value)) + return false; + + return value->GetAsBoolean(bool_value); +} + +bool ListValue::GetInteger(size_t index, int* out_value) const { + Value* value; + if (!Get(index, &value)) + return false; + + return value->GetAsInteger(out_value); +} + +bool ListValue::GetReal(size_t index, double* out_value) const { + Value* value; + if (!Get(index, &value)) + return false; + + return value->GetAsReal(out_value); +} + +bool ListValue::GetString(size_t index, std::string* out_value) const { + Value* value; + if (!Get(index, &value)) + return false; + + return value->GetAsString(out_value); +} + +bool ListValue::GetBinary(size_t index, BinaryValue** out_value) const { + Value* value; + bool result = Get(index, &value); + if (!result || !value->IsType(TYPE_BINARY)) + return false; + + if (out_value) + *out_value = static_cast<BinaryValue*>(value); + + return true; +} + +bool ListValue::GetDictionary(size_t index, DictionaryValue** out_value) const { Value* value; bool result = Get(index, &value); if (!result || !value->IsType(TYPE_DICTIONARY)) @@ -545,6 +588,18 @@ bool ListValue::GetDictionary(size_t index, return true; } +bool ListValue::GetList(size_t index, ListValue** out_value) const { + Value* value; + bool result = Get(index, &value); + if (!result || !value->IsType(TYPE_LIST)) + return false; + + if (out_value) + *out_value = static_cast<ListValue*>(value); + + return true; +} + bool ListValue::Remove(size_t index, Value** out_value) { if (index >= list_.size()) return false; |