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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 TYPE_BINARY, | 58 TYPE_BINARY, |
59 TYPE_DICTIONARY, | 59 TYPE_DICTIONARY, |
60 TYPE_LIST | 60 TYPE_LIST |
61 // Note: Do not add more types. See the file-level comment above for why. | 61 // Note: Do not add more types. See the file-level comment above for why. |
62 }; | 62 }; |
63 | 63 |
64 virtual ~Value(); | 64 virtual ~Value(); |
65 | 65 |
66 static std::unique_ptr<Value> CreateNullValue(); | 66 static std::unique_ptr<Value> CreateNullValue(); |
67 | 67 |
| 68 // Returns the name for a given |type|. |
| 69 static const char* GetTypeName(Type type); |
| 70 |
68 // 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. |
69 // 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 |
70 // 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 |
71 // Value* to (Implementing Class)*. Also, a Value object never changes | 74 // Value* to (Implementing Class)*. Also, a Value object never changes |
72 // its type after construction. | 75 // its type after construction. |
73 Type GetType() const { return type_; } | 76 Type GetType() const { return type_; } |
74 | 77 |
75 // Returns true if the current object represents a given type. | 78 // Returns true if the current object represents a given type. |
76 bool IsType(Type type) const { return type == type_; } | 79 bool IsType(Type type) const { return type == type_; } |
77 | 80 |
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
560 } | 563 } |
561 | 564 |
562 BASE_EXPORT inline std::ostream& operator<<(std::ostream& out, | 565 BASE_EXPORT inline std::ostream& operator<<(std::ostream& out, |
563 const ListValue& value) { | 566 const ListValue& value) { |
564 return out << static_cast<const Value&>(value); | 567 return out << static_cast<const Value&>(value); |
565 } | 568 } |
566 | 569 |
567 } // namespace base | 570 } // namespace base |
568 | 571 |
569 #endif // BASE_VALUES_H_ | 572 #endif // BASE_VALUES_H_ |
OLD | NEW |