diff options
author | kalman@chromium.org <kalman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-14 02:14:01 +0000 |
---|---|---|
committer | kalman@chromium.org <kalman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-14 02:14:01 +0000 |
commit | 095812b2a635835a02d7084ea993b62f94528187 (patch) | |
tree | 26de42358530ad87740b4685d3cf17d2e1d11931 /base/values.cc | |
parent | e3e94f7a50d5cc7f87a0e86fd9e3bd1b6e42af6b (diff) | |
download | chromium_src-095812b2a635835a02d7084ea993b62f94528187.zip chromium_src-095812b2a635835a02d7084ea993b62f94528187.tar.gz chromium_src-095812b2a635835a02d7084ea993b62f94528187.tar.bz2 |
Add some useful features to base::Values:
- Typed Append methods to ListValue (AppendString etc) including AppendStrings.
- Typed SetWithoutPathExpansion methods (SetStringWithoutPathExpansion etc).
The latter is important because it's a common mistake to use Set rather than
SetWithoutPathExpansion; the existence of these extra methods should help.
Review URL: https://chromiumcodereview.appspot.com/10914246
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@156716 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/values.cc')
-rw-r--r-- | base/values.cc | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/base/values.cc b/base/values.cc index 1063eff..8453bb4 100644 --- a/base/values.cc +++ b/base/values.cc @@ -443,6 +443,31 @@ void DictionaryValue::SetWithoutPathExpansion(const std::string& key, } } +void DictionaryValue::SetBooleanWithoutPathExpansion( + const std::string& path, bool in_value) { + SetWithoutPathExpansion(path, CreateBooleanValue(in_value)); +} + +void DictionaryValue::SetIntegerWithoutPathExpansion( + const std::string& path, int in_value) { + SetWithoutPathExpansion(path, CreateIntegerValue(in_value)); +} + +void DictionaryValue::SetDoubleWithoutPathExpansion( + const std::string& path, double in_value) { + SetWithoutPathExpansion(path, CreateDoubleValue(in_value)); +} + +void DictionaryValue::SetStringWithoutPathExpansion( + const std::string& path, const std::string& in_value) { + SetWithoutPathExpansion(path, CreateStringValue(in_value)); +} + +void DictionaryValue::SetStringWithoutPathExpansion( + const std::string& path, const string16& in_value) { + SetWithoutPathExpansion(path, CreateStringValue(in_value)); +} + bool DictionaryValue::Get( const std::string& path, const Value** out_value) const { DCHECK(IsStringUTF8(path)); @@ -987,6 +1012,40 @@ void ListValue::Append(Value* in_value) { list_.push_back(in_value); } +void ListValue::AppendBoolean(bool in_value) { + Append(CreateBooleanValue(in_value)); +} + +void ListValue::AppendInteger(int in_value) { + Append(CreateIntegerValue(in_value)); +} + +void ListValue::AppendDouble(double in_value) { + Append(CreateDoubleValue(in_value)); +} + +void ListValue::AppendString(const std::string& in_value) { + Append(CreateStringValue(in_value)); +} + +void ListValue::AppendString(const string16& in_value) { + Append(CreateStringValue(in_value)); +} + +void ListValue::AppendStrings(const std::vector<std::string>& in_values) { + for (std::vector<std::string>::const_iterator it = in_values.begin(); + it != in_values.end(); ++it) { + AppendString(*it); + } +} + +void ListValue::AppendStrings(const std::vector<string16>& in_values) { + for (std::vector<string16>::const_iterator it = in_values.begin(); + it != in_values.end(); ++it) { + AppendString(*it); + } +} + bool ListValue::AppendIfNotPresent(Value* in_value) { DCHECK(in_value); for (ValueVector::const_iterator i(list_.begin()); i != list_.end(); ++i) { |