summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorvabr@chromium.org <vabr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-03 08:43:37 +0000
committervabr@chromium.org <vabr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-03 08:43:37 +0000
commit5d30f92bf4e9f055d44ea0db2327b036ae41eef6 (patch)
treee4237d83ef224e420140e6411ac84f60216555d1 /base
parent4ccaee6820cb8ac79581141a4f2463a2abb38442 (diff)
downloadchromium_src-5d30f92bf4e9f055d44ea0db2327b036ae41eef6.zip
chromium_src-5d30f92bf4e9f055d44ea0db2327b036ae41eef6.tar.gz
chromium_src-5d30f92bf4e9f055d44ea0db2327b036ae41eef6.tar.bz2
Correct const accessors in base/values.(h|cc), Part II (ListValue)
For problem description and other info please see the BUG page. This is for ListValue. BUG=138946 TEST=N/A (no fix & no new feature) TBR=jar,zelidrag,scottbyer,mpcomplete,darin,achuith,sky,estade,atwilson,grt,thakis,jamesr,hans,sadrul,pastarmovj Review URL: https://chromiumcodereview.appspot.com/10837044 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@149819 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/debug/trace_event_unittest.cc47
-rw-r--r--base/json/json_value_converter.h6
-rw-r--r--base/json/json_writer.cc2
-rw-r--r--base/values.cc55
-rw-r--r--base/values.h12
5 files changed, 76 insertions, 46 deletions
diff --git a/base/debug/trace_event_unittest.cc b/base/debug/trace_event_unittest.cc
index f839d27..5d32f2f 100644
--- a/base/debug/trace_event_unittest.cc
+++ b/base/debug/trace_event_unittest.cc
@@ -220,10 +220,10 @@ bool TraceEventTestFixture::FindNonMatchingValue(const char* key,
return FindMatchingTraceEntry(key_values);
}
-bool IsStringInDict(const char* string_to_match, DictionaryValue* dict) {
+bool IsStringInDict(const char* string_to_match, const DictionaryValue* dict) {
for (DictionaryValue::key_iterator ikey = dict->begin_keys();
ikey != dict->end_keys(); ++ikey) {
- Value* child = NULL;
+ const Value* child = NULL;
if (!dict->GetWithoutPathExpansion(*ikey, &child))
continue;
@@ -237,7 +237,7 @@ bool IsStringInDict(const char* string_to_match, DictionaryValue* dict) {
}
// Recurse to test arguments
- DictionaryValue* args_dict = NULL;
+ const DictionaryValue* args_dict = NULL;
dict->GetDictionary("args", &args_dict);
if (args_dict)
return IsStringInDict(string_to_match, args_dict);
@@ -245,13 +245,14 @@ bool IsStringInDict(const char* string_to_match, DictionaryValue* dict) {
return false;
}
-DictionaryValue* FindTraceEntry(const ListValue& trace_parsed,
- const char* string_to_match,
- DictionaryValue* match_after_this_item = NULL) {
+const DictionaryValue* FindTraceEntry(
+ const ListValue& trace_parsed,
+ const char* string_to_match,
+ const DictionaryValue* match_after_this_item = NULL) {
// Scan all items
size_t trace_parsed_count = trace_parsed.GetSize();
for (size_t i = 0; i < trace_parsed_count; i++) {
- Value* value = NULL;
+ const Value* value = NULL;
trace_parsed.Get(i, &value);
if (match_after_this_item) {
if (value == match_after_this_item)
@@ -260,7 +261,7 @@ DictionaryValue* FindTraceEntry(const ListValue& trace_parsed,
}
if (!value || value->GetType() != Value::TYPE_DICTIONARY)
continue;
- DictionaryValue* dict = static_cast<DictionaryValue*>(value);
+ const DictionaryValue* dict = static_cast<const DictionaryValue*>(value);
if (IsStringInDict(string_to_match, dict))
return dict;
@@ -268,17 +269,17 @@ DictionaryValue* FindTraceEntry(const ListValue& trace_parsed,
return NULL;
}
-std::vector<DictionaryValue*> FindTraceEntries(
+std::vector<const DictionaryValue*> FindTraceEntries(
const ListValue& trace_parsed,
const char* string_to_match) {
- std::vector<DictionaryValue*> hits;
+ std::vector<const DictionaryValue*> hits;
size_t trace_parsed_count = trace_parsed.GetSize();
for (size_t i = 0; i < trace_parsed_count; i++) {
- Value* value = NULL;
+ const Value* value = NULL;
trace_parsed.Get(i, &value);
if (!value || value->GetType() != Value::TYPE_DICTIONARY)
continue;
- DictionaryValue* dict = static_cast<DictionaryValue*>(value);
+ const DictionaryValue* dict = static_cast<const DictionaryValue*>(value);
if (IsStringInDict(string_to_match, dict))
hits.push_back(dict);
@@ -365,7 +366,7 @@ void TraceWithAllMacroVariants(WaitableEvent* task_complete_event) {
}
void ValidateAllTraceMacrosCreatedData(const ListValue& trace_parsed) {
- DictionaryValue* item = NULL;
+ const DictionaryValue* item = NULL;
#define EXPECT_FIND_(string) \
EXPECT_TRUE((item = FindTraceEntry(trace_parsed, string)));
@@ -598,11 +599,11 @@ void ValidateInstantEventPresentOnEveryThread(const ListValue& trace_parsed,
size_t trace_parsed_count = trace_parsed.GetSize();
for (size_t i = 0; i < trace_parsed_count; i++) {
- Value* value = NULL;
+ const Value* value = NULL;
trace_parsed.Get(i, &value);
if (!value || value->GetType() != Value::TYPE_DICTIONARY)
continue;
- DictionaryValue* dict = static_cast<DictionaryValue*>(value);
+ const DictionaryValue* dict = static_cast<const DictionaryValue*>(value);
std::string name;
dict->GetString("name", &name);
if (name != "multi thread event")
@@ -1149,12 +1150,12 @@ TEST_F(TraceEventTestFixture, ThreadNames) {
std::string tmp;
int tmp_int;
- DictionaryValue* item;
+ const DictionaryValue* item;
// Make sure we get thread name metadata.
// Note, the test suite may have created a ton of threads.
// So, we'll have thread names for threads we didn't create.
- std::vector<DictionaryValue*> items =
+ std::vector<const DictionaryValue*> items =
FindTraceEntries(trace_parsed_, "thread_name");
for (int i = 0; i < static_cast<int>(items.size()); i++) {
item = items[i];
@@ -1201,11 +1202,11 @@ TEST_F(TraceEventTestFixture, ThreadNameChanges) {
TraceLog::GetInstance()->SetEnabled(false);
- std::vector<DictionaryValue*> items =
+ std::vector<const DictionaryValue*> items =
FindTraceEntries(trace_parsed_, "thread_name");
EXPECT_EQ(1u, items.size());
ASSERT_GT(items.size(), 0u);
- DictionaryValue* item = items[0];
+ const DictionaryValue* item = items[0];
ASSERT_TRUE(item);
int tid;
EXPECT_TRUE(item->GetInteger("tid", &tid));
@@ -1250,7 +1251,7 @@ TEST_F(TraceEventTestFixture, AtExit) {
ASSERT_FALSE(TraceLog::GetInstance());
// Now that singleton is destroyed, check what trace events were recorded
- DictionaryValue* item = NULL;
+ const DictionaryValue* item = NULL;
ListValue& trace_parsed = trace_parsed_;
EXPECT_FIND_("is recorded 1");
EXPECT_FIND_("is recorded 2");
@@ -1330,9 +1331,9 @@ TEST_F(TraceEventTestFixture, DeepCopy) {
EXPECT_FALSE(FindTraceEntry(trace_parsed_, name2.c_str()));
EXPECT_FALSE(FindTraceEntry(trace_parsed_, name3.c_str()));
- DictionaryValue* entry1 = FindTraceEntry(trace_parsed_, kOriginalName1);
- DictionaryValue* entry2 = FindTraceEntry(trace_parsed_, kOriginalName2);
- DictionaryValue* entry3 = FindTraceEntry(trace_parsed_, kOriginalName3);
+ const DictionaryValue* entry1 = FindTraceEntry(trace_parsed_, kOriginalName1);
+ const DictionaryValue* entry2 = FindTraceEntry(trace_parsed_, kOriginalName2);
+ const DictionaryValue* entry3 = FindTraceEntry(trace_parsed_, kOriginalName3);
ASSERT_TRUE(entry1);
ASSERT_TRUE(entry2);
ASSERT_TRUE(entry3);
diff --git a/base/json/json_value_converter.h b/base/json/json_value_converter.h
index 9d3036a..69da0d8 100644
--- a/base/json/json_value_converter.h
+++ b/base/json/json_value_converter.h
@@ -273,7 +273,7 @@ class RepeatedValueConverter : public ValueConverter<ScopedVector<Element> > {
field->reserve(list->GetSize());
for (size_t i = 0; i < list->GetSize(); ++i) {
- base::Value* element = NULL;
+ const base::Value* element = NULL;
if (!list->Get(i, &element))
continue;
@@ -307,7 +307,7 @@ class RepeatedMessageConverter
field->reserve(list->GetSize());
for (size_t i = 0; i < list->GetSize(); ++i) {
- base::Value* element = NULL;
+ const base::Value* element = NULL;
if (!list->Get(i, &element))
continue;
@@ -344,7 +344,7 @@ class RepeatedCustomValueConverter
field->reserve(list->GetSize());
for (size_t i = 0; i < list->GetSize(); ++i) {
- base::Value* element = NULL;
+ const base::Value* element = NULL;
if (!list->Get(i, &element))
continue;
diff --git a/base/json/json_writer.cc b/base/json/json_writer.cc
index 9ca4813..e8cf9ac 100644
--- a/base/json/json_writer.cc
+++ b/base/json/json_writer.cc
@@ -139,7 +139,7 @@ void JSONWriter::BuildJSONString(const Value* const node, int depth) {
const ListValue* list = static_cast<const ListValue*>(node);
for (size_t i = 0; i < list->GetSize(); ++i) {
- Value* value = NULL;
+ const Value* value = NULL;
bool result = list->Get(i, &value);
DCHECK(result);
diff --git a/base/values.cc b/base/values.cc
index 08fab89..1ccc9ec 100644
--- a/base/values.cc
+++ b/base/values.cc
@@ -820,7 +820,7 @@ bool ListValue::Set(size_t index, Value* in_value) {
return true;
}
-bool ListValue::Get(size_t index, Value** out_value) const {
+bool ListValue::Get(size_t index, const Value** out_value) const {
if (index >= list_.size())
return false;
@@ -830,8 +830,14 @@ bool ListValue::Get(size_t index, Value** out_value) const {
return true;
}
+bool ListValue::Get(size_t index, Value** out_value) {
+ return static_cast<const ListValue&>(*this).Get(
+ index,
+ const_cast<const Value**>(out_value));
+}
+
bool ListValue::GetBoolean(size_t index, bool* bool_value) const {
- Value* value;
+ const Value* value;
if (!Get(index, &value))
return false;
@@ -839,7 +845,7 @@ bool ListValue::GetBoolean(size_t index, bool* bool_value) const {
}
bool ListValue::GetInteger(size_t index, int* out_value) const {
- Value* value;
+ const Value* value;
if (!Get(index, &value))
return false;
@@ -847,7 +853,7 @@ bool ListValue::GetInteger(size_t index, int* out_value) const {
}
bool ListValue::GetDouble(size_t index, double* out_value) const {
- Value* value;
+ const Value* value;
if (!Get(index, &value))
return false;
@@ -855,7 +861,7 @@ bool ListValue::GetDouble(size_t index, double* out_value) const {
}
bool ListValue::GetString(size_t index, std::string* out_value) const {
- Value* value;
+ const Value* value;
if (!Get(index, &value))
return false;
@@ -863,49 +869,68 @@ bool ListValue::GetString(size_t index, std::string* out_value) const {
}
bool ListValue::GetString(size_t index, string16* out_value) const {
- Value* 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 ListValue::GetBinary(size_t index, const BinaryValue** out_value) const {
+ 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);
+ *out_value = static_cast<const BinaryValue*>(value);
return true;
}
-bool ListValue::GetDictionary(size_t index, DictionaryValue** out_value) const {
- Value* value;
+bool ListValue::GetBinary(size_t index, BinaryValue** out_value) {
+ return static_cast<const ListValue&>(*this).GetBinary(
+ index,
+ const_cast<const BinaryValue**>(out_value));
+}
+
+bool ListValue::GetDictionary(size_t index,
+ const DictionaryValue** out_value) const {
+ const Value* value;
bool result = Get(index, &value);
if (!result || !value->IsType(TYPE_DICTIONARY))
return false;
if (out_value)
- *out_value = static_cast<DictionaryValue*>(value);
+ *out_value = static_cast<const DictionaryValue*>(value);
return true;
}
-bool ListValue::GetList(size_t index, ListValue** out_value) const {
- Value* value;
+bool ListValue::GetDictionary(size_t index, DictionaryValue** out_value) {
+ return static_cast<const ListValue&>(*this).GetDictionary(
+ index,
+ const_cast<const DictionaryValue**>(out_value));
+}
+
+bool ListValue::GetList(size_t index, const ListValue** out_value) const {
+ 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);
+ *out_value = static_cast<const ListValue*>(value);
return true;
}
+bool ListValue::GetList(size_t index, ListValue** out_value) {
+ return static_cast<const ListValue&>(*this).GetList(
+ index,
+ const_cast<const ListValue**>(out_value));
+}
+
bool ListValue::Remove(size_t index, Value** out_value) {
if (index >= list_.size())
return false;
diff --git a/base/values.h b/base/values.h
index 223e0f8..c583407 100644
--- a/base/values.h
+++ b/base/values.h
@@ -414,7 +414,8 @@ class BASE_EXPORT ListValue : public Value {
// Gets the Value at the given index. Modifies |out_value| (and returns true)
// only if the index falls within the current list range.
// Note that the list always owns the Value passed out via |out_value|.
- bool Get(size_t index, Value** out_value) const;
+ bool Get(size_t index, const Value** out_value) const;
+ bool Get(size_t index, Value** out_value);
// Convenience forms of Get(). Modifies |out_value| (and returns true)
// only if the index is valid and the Value at that index can be returned
@@ -424,9 +425,12 @@ class BASE_EXPORT ListValue : public Value {
bool GetDouble(size_t index, double* out_value) const;
bool GetString(size_t index, std::string* out_value) const;
bool GetString(size_t index, string16* out_value) const;
- bool GetBinary(size_t index, BinaryValue** out_value) const;
- bool GetDictionary(size_t index, DictionaryValue** out_value) const;
- bool GetList(size_t index, ListValue** out_value) const;
+ bool GetBinary(size_t index, const BinaryValue** out_value) const;
+ bool GetBinary(size_t index, BinaryValue** out_value);
+ bool GetDictionary(size_t index, const DictionaryValue** out_value) const;
+ bool GetDictionary(size_t index, DictionaryValue** out_value);
+ bool GetList(size_t index, const ListValue** out_value) const;
+ bool GetList(size_t index, ListValue** out_value);
// Removes the Value with the specified index from this list.
// If |out_value| is non-NULL, the removed Value AND ITS OWNERSHIP will be