Index: base/values.h |
diff --git a/base/values.h b/base/values.h |
index 8becd3046ac0616bbb691b21ebabeed079850ef9..22d6b231cc21ad3f7868c98994c1f4015f8238ee 100644 |
--- a/base/values.h |
+++ b/base/values.h |
@@ -37,10 +37,10 @@ namespace base { |
class BinaryValue; |
class DictionaryValue; |
-class FundamentalValue; |
class ListValue; |
class StringValue; |
class Value; |
+using FundamentalValue = Value; |
// The Value class is the base class for Values. A Value can be instantiated |
// via the Create*Value() factory methods, or by directly creating instances of |
@@ -61,10 +61,21 @@ class BASE_EXPORT Value { |
// Note: Do not add more types. See the file-level comment above for why. |
}; |
- virtual ~Value(); |
- |
static std::unique_ptr<Value> CreateNullValue(); |
+ Value(const Value& that); |
+ Value(Value&& that); |
+ Value(); // A null value. |
+ explicit Value(Type type); |
+ explicit Value(bool in_bool); |
+ explicit Value(int in_int); |
+ explicit Value(double in_double); |
+ |
+ Value& operator=(const Value& that); |
+ Value& operator=(Value&& that); |
+ |
+ virtual ~Value(); |
+ |
// Returns the name for a given |type|. |
static const char* GetTypeName(Type type); |
@@ -73,10 +84,23 @@ class BASE_EXPORT Value { |
// safe to use the Type to determine whether you can cast from |
// Value* to (Implementing Class)*. Also, a Value object never changes |
// its type after construction. |
- Type GetType() const { return type_; } |
+ Type GetType() const { return type_; } // DEPRECATED, use type(). |
+ Type type() const { return type_; } |
// Returns true if the current object represents a given type. |
bool IsType(Type type) const { return type == type_; } |
+ bool is_bool() const { return type() == Type::BOOLEAN; } |
+ bool is_int() const { return type() == Type::INTEGER; } |
+ bool is_double() const { return type() == Type::DOUBLE; } |
+ bool is_string() const { return type() == Type::STRING; } |
+ bool is_blob() const { return type() == Type::BINARY; } |
+ bool is_dict() const { return type() == Type::DICTIONARY; } |
+ bool is_list() const { return type() == Type::LIST; } |
+ |
+ // These will all fatally assert if the type doesn't match. |
+ bool GetBool() const; |
+ int GetInt() const; |
+ double GetDouble() const; // Implicitly converts from int if necessary. |
// These methods allow the convenient retrieval of the contents of the Value. |
// If the current object can be converted into the given type, the value is |
@@ -99,8 +123,7 @@ class BASE_EXPORT Value { |
// Note: Do not add more types. See the file-level comment above for why. |
// 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. |
- // |
+ // 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; |
@@ -114,37 +137,14 @@ class BASE_EXPORT Value { |
// NULLs are considered equal but different from Value::CreateNullValue(). |
static bool Equals(const Value* a, const Value* b); |
- protected: |
- // These aren't safe for end-users, but they are useful for subclasses. |
- explicit Value(Type type); |
- Value(const Value& that); |
- Value& operator=(const Value& that); |
- |
private: |
- Type type_; |
-}; |
- |
-// FundamentalValue represents the simple fundamental types of values. |
-class BASE_EXPORT FundamentalValue : public Value { |
- public: |
- explicit FundamentalValue(bool in_value); |
- explicit FundamentalValue(int in_value); |
- explicit FundamentalValue(double in_value); |
- ~FundamentalValue() override; |
+ void InternalCopyFrom(const Value& that); |
- // Overridden from Value: |
- bool GetAsBoolean(bool* out_value) const override; |
- bool GetAsInteger(int* out_value) const override; |
- // Values of both type Type::INTEGER and Type::DOUBLE can be obtained as |
- // doubles. |
- bool GetAsDouble(double* out_value) const override; |
- FundamentalValue* DeepCopy() const override; |
- bool Equals(const Value* other) const override; |
+ Type type_; |
- private: |
union { |
- bool boolean_value_; |
- int integer_value_; |
+ bool bool_value_; |
+ int int_value_; |
double double_value_; |
}; |
}; |
@@ -545,11 +545,6 @@ class BASE_EXPORT ValueDeserializer { |
BASE_EXPORT std::ostream& operator<<(std::ostream& out, const Value& value); |
BASE_EXPORT inline std::ostream& operator<<(std::ostream& out, |
- const FundamentalValue& value) { |
- return out << static_cast<const Value&>(value); |
-} |
- |
-BASE_EXPORT inline std::ostream& operator<<(std::ostream& out, |
const StringValue& value) { |
return out << static_cast<const Value&>(value); |
} |