OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // This file specifies a recursive data storage class called Value intended for | 5 // This file specifies a recursive data storage class called Value intended for |
6 // storing settings and other persistable data. | 6 // storing settings and other persistable data. |
7 // | 7 // |
8 // A Value represents something that can be stored in JSON or passed to/from | 8 // A Value represents something that can be stored in JSON or passed to/from |
9 // JavaScript. As such, it is NOT a generalized variant type, since only the | 9 // JavaScript. As such, it is NOT a generalized variant type, since only the |
10 // types supported by JavaScript/JSON are supported. | 10 // types supported by JavaScript/JSON are supported. |
(...skipping 24 matching lines...) Expand all Loading... |
35 | 35 |
36 class DictionaryValue; | 36 class DictionaryValue; |
37 class FundamentalValue; | 37 class FundamentalValue; |
38 class ListValue; | 38 class ListValue; |
39 class StringValue; | 39 class StringValue; |
40 class Value; | 40 class Value; |
41 | 41 |
42 typedef std::vector<Value*> ValueVector; | 42 typedef std::vector<Value*> ValueVector; |
43 typedef std::map<std::string, Value*> ValueMap; | 43 typedef std::map<std::string, Value*> ValueMap; |
44 | 44 |
45 // The Value class is the base class for Values. A Value can be instantiated | 45 // The Value class is the base class for Values. |
46 // via the Create*Value() factory methods, or by directly creating instances of | |
47 // the subclasses. | |
48 // | 46 // |
49 // See the file-level comment above for more information. | 47 // See the file-level comment above for more information. |
50 class BASE_EXPORT Value { | 48 class BASE_EXPORT Value { |
51 public: | 49 public: |
52 enum Type { | 50 enum Type { |
53 TYPE_NULL = 0, | 51 TYPE_NULL = 0, |
54 TYPE_BOOLEAN, | 52 TYPE_BOOLEAN, |
55 TYPE_INTEGER, | 53 TYPE_INTEGER, |
56 TYPE_DOUBLE, | 54 TYPE_DOUBLE, |
57 TYPE_STRING, | 55 TYPE_STRING, |
58 TYPE_BINARY, | 56 TYPE_BINARY, |
59 TYPE_DICTIONARY, | 57 TYPE_DICTIONARY, |
60 TYPE_LIST | 58 TYPE_LIST |
61 // Note: Do not add more types. See the file-level comment above for why. | 59 // Note: Do not add more types. See the file-level comment above for why. |
62 }; | 60 }; |
63 | 61 |
64 virtual ~Value(); | 62 virtual ~Value(); |
65 | 63 |
66 static Value* CreateNullValue(); | 64 static Value* CreateNullValue(); |
67 // DEPRECATED: Do not use the following 5 functions. Instead, use | 65 // DEPRECATED: Do not use the following 5 functions. Instead, use |
68 // new FundamentalValue or new StringValue. | 66 // new FundamentalValue or new StringValue. |
69 static FundamentalValue* CreateBooleanValue(bool in_value); | 67 static FundamentalValue* CreateBooleanValue(bool in_value); |
70 static FundamentalValue* CreateIntegerValue(int in_value); | 68 static FundamentalValue* CreateIntegerValue(int in_value); |
71 static FundamentalValue* CreateDoubleValue(double in_value); | 69 static FundamentalValue* CreateDoubleValue(double in_value); |
72 static StringValue* CreateStringValue(const std::string& in_value); | |
73 static StringValue* CreateStringValue(const string16& in_value); | |
74 | 70 |
75 // Returns the type of the value stored by the current Value object. | 71 // Returns the type of the value stored by the current Value object. |
76 // Each type will be implemented by only one subclass of Value, so it's | 72 // Each type will be implemented by only one subclass of Value, so it's |
77 // safe to use the Type to determine whether you can cast from | 73 // safe to use the Type to determine whether you can cast from |
78 // Value* to (Implementing Class)*. Also, a Value object never changes | 74 // Value* to (Implementing Class)*. Also, a Value object never changes |
79 // its type after construction. | 75 // its type after construction. |
80 Type GetType() const { return type_; } | 76 Type GetType() const { return type_; } |
81 | 77 |
82 // Returns true if the current object represents a given type. | 78 // Returns true if the current object represents a given type. |
83 bool IsType(Type type) const { return type == type_; } | 79 bool IsType(Type type) const { return type == type_; } |
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 } | 529 } |
534 | 530 |
535 BASE_EXPORT inline std::ostream& operator<<(std::ostream& out, | 531 BASE_EXPORT inline std::ostream& operator<<(std::ostream& out, |
536 const ListValue& value) { | 532 const ListValue& value) { |
537 return out << static_cast<const Value&>(value); | 533 return out << static_cast<const Value&>(value); |
538 } | 534 } |
539 | 535 |
540 } // namespace base | 536 } // namespace base |
541 | 537 |
542 #endif // BASE_VALUES_H_ | 538 #endif // BASE_VALUES_H_ |
OLD | NEW |