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

Unified Diff: base/values.cc

Issue 18200: Flesh out ListValue class. (Closed)
Patch Set: Created 11 years, 11 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
« no previous file with comments | « base/values.h ('k') | base/values_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/values.cc
diff --git a/base/values.cc b/base/values.cc
index 75b8e4f7d955b4e7ae5f4220438eef2b448e6572..cf98c0b0b75b19de81a5c50db573a78fcf7dd459 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;
« no previous file with comments | « base/values.h ('k') | base/values_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698