summaryrefslogtreecommitdiffstats
path: root/base/values.h
diff options
context:
space:
mode:
authorpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-25 20:47:52 +0000
committerpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-25 20:47:52 +0000
commit4dad9ad838f6671fbd67e1c5292525e739e31983 (patch)
tree4d79fc17f12752cc221e0e40d16951677da71f92 /base/values.h
parent2b3f0f59a6761a41e22007c2c3096e8e18517e08 (diff)
downloadchromium_src-4dad9ad838f6671fbd67e1c5292525e739e31983.zip
chromium_src-4dad9ad838f6671fbd67e1c5292525e739e31983.tar.gz
chromium_src-4dad9ad838f6671fbd67e1c5292525e739e31983.tar.bz2
Many changes to DictionaryValues:
* Add support for keys with "." in them via new XXXWithoutPathExpansion() APIs. * Use these APIs with all key iterator usage. * SetXXX() calls cannot fail, so change them from bool to void. * Change GetSize() to size() since it's cheap, and add empty(). Other: * Use standard for loop format in more places (e.g. instead of while loops when they're really doing a for loop). * Shorten a few bits of code. BUG=567 TEST=none Review URL: http://codereview.chromium.org/441008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@33109 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/values.h')
-rw-r--r--base/values.h53
1 files changed, 39 insertions, 14 deletions
diff --git a/base/values.h b/base/values.h
index b3c380c..49ce287 100644
--- a/base/values.h
+++ b/base/values.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -207,7 +207,10 @@ class DictionaryValue : public Value {
bool HasKey(const std::wstring& key) const;
// Returns the number of Values in this dictionary.
- size_t GetSize() const { return dictionary_.size(); }
+ size_t size() const { return dictionary_.size(); }
+
+ // Returns whether the dictionary is empty.
+ bool empty() const { return dictionary_.empty(); }
// Clears any current contents of this dictionary.
void Clear();
@@ -220,16 +223,20 @@ class DictionaryValue : public Value {
// a DictionaryValue, a new DictionaryValue will be created and attached
// to the path in that location.
// Note that the dictionary takes ownership of the value referenced by
- // |in_value|.
- bool Set(const std::wstring& path, Value* in_value);
+ // |in_value|, and therefore |in_value| must be non-NULL.
+ void Set(const std::wstring& path, Value* in_value);
// Convenience forms of Set(). These methods will replace any existing
// value at that path, even if it has a different type.
- bool SetBoolean(const std::wstring& path, bool in_value);
- bool SetInteger(const std::wstring& path, int in_value);
- bool SetReal(const std::wstring& path, double in_value);
- bool SetString(const std::wstring& path, const std::string& in_value);
- bool SetString(const std::wstring& path, const std::wstring& in_value);
+ void SetBoolean(const std::wstring& path, bool in_value);
+ void SetInteger(const std::wstring& path, int in_value);
+ void SetReal(const std::wstring& path, double in_value);
+ void SetString(const std::wstring& path, const std::string& in_value);
+ void SetString(const std::wstring& path, const std::wstring& in_value);
+
+ // Like Set(), but without special treatment of '.'. This allows e.g. URLs to
+ // be used as paths.
+ void SetWithoutPathExpansion(const std::wstring& key, Value* in_value);
// Gets the Value associated with the given path starting from this object.
// A path has the form "<key>" or "<key>.<key>.[...]", where "." indexes
@@ -253,6 +260,21 @@ class DictionaryValue : public Value {
DictionaryValue** out_value) const;
bool GetList(const std::wstring& path, ListValue** out_value) const;
+ // Like Get(), but without special treatment of '.'. This allows e.g. URLs to
+ // be used as paths.
+ bool GetWithoutPathExpansion(const std::wstring& key,
+ Value** out_value) const;
+ bool GetIntegerWithoutPathExpansion(const std::wstring& path,
+ int* out_value) const;
+ bool GetStringWithoutPathExpansion(const std::wstring& path,
+ std::string* out_value) const;
+ bool GetStringWithoutPathExpansion(const std::wstring& path,
+ std::wstring* out_value) const;
+ bool GetDictionaryWithoutPathExpansion(const std::wstring& path,
+ DictionaryValue** out_value) const;
+ bool GetListWithoutPathExpansion(const std::wstring& path,
+ ListValue** out_value) const;
+
// Removes the Value with the specified path from this dictionary (or one
// of its child dictionaries, if the path is more than just a local key).
// If |out_value| is non-NULL, the removed Value AND ITS OWNERSHIP will be
@@ -261,8 +283,16 @@ class DictionaryValue : public Value {
// it will return false and the DictionaryValue object will be unchanged.
bool Remove(const std::wstring& path, Value** out_value);
+ // Like Remove(), but without special treatment of '.'. This allows e.g. URLs
+ // to be used as paths.
+ bool RemoveWithoutPathExpansion(const std::wstring& key, Value** out_value);
+
// This class provides an iterator for the keys in the dictionary.
// It can't be used to modify the dictionary.
+ //
+ // YOU SHOULD ALWAYS USE THE XXXWithoutPathExpansion() APIs WITH THESE, NOT
+ // THE NORMAL XXX() APIs. This makes sure things will work correctly if any
+ // keys have '.'s in them.
class key_iterator
: private std::iterator<std::input_iterator_tag, const std::wstring> {
public:
@@ -280,11 +310,6 @@ class DictionaryValue : public Value {
key_iterator end_keys() const { return key_iterator(dictionary_.end()); }
private:
- // Associates the value |in_value| with the |key|. This method should be
- // used instead of "dictionary_[key] = foo" so that any previous value can
- // be properly deleted.
- void SetInCurrentNode(const std::wstring& key, Value* in_value);
-
ValueMap dictionary_;
DISALLOW_COPY_AND_ASSIGN(DictionaryValue);