Chromium Code Reviews| Index: base/values.h |
| diff --git a/base/values.h b/base/values.h |
| index 258a9603a614e1a514724434652bd7595b11e7ea..4b7999c7122a91ca4f318586b8b04f2f3a31521c 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 |
| @@ -119,33 +134,29 @@ class BASE_EXPORT Value { |
| Value(const Value& that); |
| Value& operator=(const Value& that); |
| + // TODO(brettw) move to public when FundamentalValue is gone. |
| + Value(bool in_bool); |
| + Value(int in_int); |
| + Value(double in_double); |
| + |
| private: |
| 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 { |
|
vabr (Chromium)
2016/12/07 14:31:11
As a result of moving this union up to base::Value
|
| - bool boolean_value_; |
| - int integer_value_; |
| - double double_value_; |
| - }; |
| }; |
| class BASE_EXPORT StringValue : public Value { |