Chromium Code Reviews| Index: base/values.h |
| diff --git a/base/values.h b/base/values.h |
| index 14a02e4077ea3ea7cad83a9ee1275360c033fbc1..1f4f20fdacdc5e1da3f9685554d67421eea7b3f5 100644 |
| --- a/base/values.h |
| +++ b/base/values.h |
| @@ -61,6 +61,8 @@ class BASE_EXPORT Value { |
| // Note: Do not add more types. See the file-level comment above for why. |
| }; |
| + Value(); // A null value. |
| + |
| virtual ~Value(); |
| static std::unique_ptr<Value> CreateNullValue(); |
| @@ -73,10 +75,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 |
| @@ -117,35 +132,35 @@ class BASE_EXPORT Value { |
| // These aren't safe for end-users, but they are useful for subclasses. |
| explicit Value(Type type); |
| Value(const Value& that); |
| + Value(Value&& that); |
| Value& operator=(const Value& that); |
| + Value& operator=(Value&& that); |
| + |
| + // TODO(brettw) move to public when FundamentalValue is gone. |
| + Value(bool in_bool); |
| + Value(int in_int); |
| + Value(double in_double); |
|
jdoerrie
2016/12/08 10:13:08
These constructors probably should be explicit.
vabr (Chromium)
2016/12/08 10:49:48
Done.
|
| private: |
| + void InternalCopyFrom(const Value& that); |
| + |
| Type type_; |
| + |
| + union { |
| + bool bool_value_; |
| + int int_value_; |
| + double double_value_; |
| + }; |
| }; |
| // FundamentalValue represents the simple fundamental types of values. |
| +// TODO(brettw) remove when callers are updated to use raw Value. |
| class BASE_EXPORT FundamentalValue : public Value { |
| public: |
| explicit FundamentalValue(bool in_value); |
| explicit FundamentalValue(int in_value); |
| explicit FundamentalValue(double in_value); |
| ~FundamentalValue() override; |
| - |
| - // 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; |
| - |
| - private: |
| - union { |
| - bool boolean_value_; |
| - int integer_value_; |
| - double double_value_; |
| - }; |
| }; |
| class BASE_EXPORT StringValue : public Value { |