diff options
author | akalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-18 02:16:59 +0000 |
---|---|---|
committer | akalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-18 02:16:59 +0000 |
commit | 16f47e08060635631f1ad2cbb30906beb1caffc3 (patch) | |
tree | f2e07ada71f47383cb8355091b0a92e090c8656e /base/values.h | |
parent | 9fb09e0cb9a33db85884f3f81e406d12ad9f2b70 (diff) | |
download | chromium_src-16f47e08060635631f1ad2cbb30906beb1caffc3.zip chromium_src-16f47e08060635631f1ad2cbb30906beb1caffc3.tar.gz chromium_src-16f47e08060635631f1ad2cbb30906beb1caffc3.tar.bz2 |
Made return types of various Value::DeepCopy() implementations more specific
Since C++ supports covariant return types, a subclass of Value can return its
own pointer type for Value::DeepCopy().
Also made signatures of Value::Create*Value() more specific.
Removed now-unnecessary casts.
Added test for covariant return types.
BUG=None
TEST=Compile
Review URL: http://codereview.chromium.org/6324004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@71617 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/values.h')
-rw-r--r-- | base/values.h | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/base/values.h b/base/values.h index d69a685..135a30f 100644 --- a/base/values.h +++ b/base/values.h @@ -63,11 +63,11 @@ class Value { // kinds of values without thinking about which class implements them. // These can always be expected to return a valid Value*. static Value* CreateNullValue(); - static Value* CreateBooleanValue(bool in_value); - static Value* CreateIntegerValue(int in_value); - static Value* CreateRealValue(double in_value); - static Value* CreateStringValue(const std::string& in_value); - static Value* CreateStringValue(const string16& in_value); + static FundamentalValue* CreateBooleanValue(bool in_value); + static FundamentalValue* CreateIntegerValue(int in_value); + static FundamentalValue* CreateRealValue(double in_value); + static StringValue* CreateStringValue(const std::string& in_value); + static StringValue* CreateStringValue(const string16& in_value); // This one can return NULL if the input isn't valid. If the return value // is non-null, the new object has taken ownership of the buffer pointer. @@ -96,6 +96,9 @@ class Value { // This creates a deep copy of the entire Value tree, and returns a pointer // to the copy. The caller gets ownership of the copy, of course. + // + // Subclasses return their own type directly in their overrides; + // this works because C++ supports covariant return types. virtual Value* DeepCopy() const; // Compares if two Value objects have equal contents. @@ -130,7 +133,7 @@ class FundamentalValue : public Value { virtual bool GetAsBoolean(bool* out_value) const; virtual bool GetAsInteger(int* out_value) const; virtual bool GetAsReal(double* out_value) const; - virtual Value* DeepCopy() const; + virtual FundamentalValue* DeepCopy() const; virtual bool Equals(const Value* other) const; private: @@ -156,7 +159,7 @@ class StringValue : public Value { // Subclassed methods virtual bool GetAsString(std::string* out_value) const; virtual bool GetAsString(string16* out_value) const; - virtual Value* DeepCopy() const; + virtual StringValue* DeepCopy() const; virtual bool Equals(const Value* other) const; private: @@ -185,7 +188,7 @@ class BinaryValue: public Value { const char* GetBuffer() const { return buffer_; } // Overridden from Value: - virtual Value* DeepCopy() const; + virtual BinaryValue* DeepCopy() const; virtual bool Equals(const Value* other) const; private: @@ -330,7 +333,7 @@ class DictionaryValue : public Value { key_iterator end_keys() const { return key_iterator(dictionary_.end()); } // Overridden from Value: - virtual Value* DeepCopy() const; + virtual DictionaryValue* DeepCopy() const; virtual bool Equals(const Value* other) const; private: @@ -417,7 +420,7 @@ class ListValue : public Value { // Overridden from Value: virtual bool GetAsList(ListValue** out_value); - virtual Value* DeepCopy() const; + virtual ListValue* DeepCopy() const; virtual bool Equals(const Value* other) const; private: |