OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 10 matching lines...) Expand all Loading... |
21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 */ | 24 */ |
25 | 25 |
26 #ifndef IDBAny_h | 26 #ifndef IDBAny_h |
27 #define IDBAny_h | 27 #define IDBAny_h |
28 | 28 |
29 #if ENABLE(INDEXED_DATABASE) | 29 #if ENABLE(INDEXED_DATABASE) |
30 | 30 |
31 #include "ScriptValue.h" | |
32 #include <wtf/PassRefPtr.h> | 31 #include <wtf/PassRefPtr.h> |
33 #include <wtf/RefCounted.h> | 32 #include <wtf/RefCounted.h> |
34 #include <wtf/RefPtr.h> | 33 #include <wtf/RefPtr.h> |
35 #include <wtf/text/WTFString.h> | 34 #include <wtf/text/WTFString.h> |
36 | 35 |
37 namespace WebCore { | 36 namespace WebCore { |
38 | 37 |
39 class DOMStringList; | 38 class DOMStringList; |
40 class IDBCursor; | 39 class IDBCursor; |
41 class IDBCursorWithValue; | 40 class IDBCursorWithValue; |
42 class IDBDatabase; | 41 class IDBDatabase; |
43 class IDBFactory; | 42 class IDBFactory; |
44 class IDBIndex; | 43 class IDBIndex; |
45 class IDBKey; | 44 class IDBKey; |
46 class IDBKeyPath; | 45 class IDBKeyPath; |
47 class IDBObjectStore; | 46 class IDBObjectStore; |
48 class IDBTransaction; | 47 class IDBTransaction; |
| 48 class SerializedScriptValue; |
49 | 49 |
50 class IDBAny : public RefCounted<IDBAny> { | 50 class IDBAny : public RefCounted<IDBAny> { |
51 public: | 51 public: |
52 static PassRefPtr<IDBAny> createInvalid(); | 52 static PassRefPtr<IDBAny> createInvalid(); |
53 static PassRefPtr<IDBAny> createNull(); | 53 static PassRefPtr<IDBAny> createNull(); |
54 static PassRefPtr<IDBAny> createString(const String&); | 54 static PassRefPtr<IDBAny> createString(const String&); |
55 template<typename T> | 55 template<typename T> |
56 static PassRefPtr<IDBAny> create(T* idbObject) | 56 static PassRefPtr<IDBAny> create(T* idbObject) |
57 { | 57 { |
58 RefPtr<IDBAny> any = IDBAny::createInvalid(); | 58 RefPtr<IDBAny> any = IDBAny::createInvalid(); |
59 any->set(idbObject); | 59 any->set(idbObject); |
60 return any.release(); | 60 return any.release(); |
61 } | 61 } |
62 template<typename T> | 62 static PassRefPtr<IDBAny> create(const IDBKeyPath& keyPath) |
63 static PassRefPtr<IDBAny> create(const T& idbObject) | |
64 { | 63 { |
65 RefPtr<IDBAny> any = IDBAny::createInvalid(); | 64 RefPtr<IDBAny> any = IDBAny::createInvalid(); |
66 any->set(idbObject); | 65 any->set(keyPath); |
67 return any.release(); | 66 return any.release(); |
68 } | 67 } |
69 template<typename T> | 68 template<typename T> |
70 static PassRefPtr<IDBAny> create(PassRefPtr<T> idbObject) | 69 static PassRefPtr<IDBAny> create(PassRefPtr<T> idbObject) |
71 { | 70 { |
72 RefPtr<IDBAny> any = IDBAny::createInvalid(); | 71 RefPtr<IDBAny> any = IDBAny::createInvalid(); |
73 any->set(idbObject); | 72 any->set(idbObject); |
74 return any.release(); | 73 return any.release(); |
75 } | 74 } |
76 static PassRefPtr<IDBAny> create(int64_t value) | |
77 { | |
78 RefPtr<IDBAny> any = IDBAny::createInvalid(); | |
79 any->set(value); | |
80 return any.release(); | |
81 } | |
82 ~IDBAny(); | 75 ~IDBAny(); |
83 | 76 |
84 enum Type { | 77 enum Type { |
85 UndefinedType = 0, | 78 UndefinedType = 0, |
86 NullType, | 79 NullType, |
87 DOMStringListType, | 80 DOMStringListType, |
88 IDBCursorType, | 81 IDBCursorType, |
89 IDBCursorWithValueType, | 82 IDBCursorWithValueType, |
90 IDBDatabaseType, | 83 IDBDatabaseType, |
91 IDBFactoryType, | 84 IDBFactoryType, |
92 IDBIndexType, | 85 IDBIndexType, |
93 IDBKeyType, | 86 IDBKeyType, |
94 IDBObjectStoreType, | 87 IDBObjectStoreType, |
95 IDBTransactionType, | 88 IDBTransactionType, |
96 ScriptValueType, | 89 SerializedScriptValueType, |
97 IntegerType, | |
98 StringType, | 90 StringType, |
99 }; | 91 }; |
100 | 92 |
101 Type type() const { return m_type; } | 93 Type type() const { return m_type; } |
102 // Use type() to figure out which one of these you're allowed to call. | 94 // Use type() to figure out which one of these you're allowed to call. |
103 PassRefPtr<DOMStringList> domStringList(); | 95 PassRefPtr<DOMStringList> domStringList(); |
104 PassRefPtr<IDBCursor> idbCursor(); | 96 PassRefPtr<IDBCursor> idbCursor(); |
105 PassRefPtr<IDBCursorWithValue> idbCursorWithValue(); | 97 PassRefPtr<IDBCursorWithValue> idbCursorWithValue(); |
106 PassRefPtr<IDBDatabase> idbDatabase(); | 98 PassRefPtr<IDBDatabase> idbDatabase(); |
107 PassRefPtr<IDBFactory> idbFactory(); | 99 PassRefPtr<IDBFactory> idbFactory(); |
108 PassRefPtr<IDBIndex> idbIndex(); | 100 PassRefPtr<IDBIndex> idbIndex(); |
109 PassRefPtr<IDBKey> idbKey(); | 101 PassRefPtr<IDBKey> idbKey(); |
110 PassRefPtr<IDBObjectStore> idbObjectStore(); | 102 PassRefPtr<IDBObjectStore> idbObjectStore(); |
111 PassRefPtr<IDBTransaction> idbTransaction(); | 103 PassRefPtr<IDBTransaction> idbTransaction(); |
112 ScriptValue scriptValue(); | 104 PassRefPtr<SerializedScriptValue> serializedScriptValue(); |
113 int64_t integer(); | |
114 const String& string(); | 105 const String& string(); |
115 | 106 |
116 // Set can only be called once. | 107 // Set can only be called once. |
117 void setNull(); | 108 void setNull(); |
118 void set(PassRefPtr<DOMStringList>); | 109 void set(PassRefPtr<DOMStringList>); |
119 void set(PassRefPtr<IDBCursor>); | 110 void set(PassRefPtr<IDBCursor>); |
120 void set(PassRefPtr<IDBCursorWithValue>); | 111 void set(PassRefPtr<IDBCursorWithValue>); |
121 void set(PassRefPtr<IDBDatabase>); | 112 void set(PassRefPtr<IDBDatabase>); |
122 void set(PassRefPtr<IDBFactory>); | 113 void set(PassRefPtr<IDBFactory>); |
123 void set(PassRefPtr<IDBIndex>); | 114 void set(PassRefPtr<IDBIndex>); |
124 void set(PassRefPtr<IDBKey>); | 115 void set(PassRefPtr<IDBKey>); |
125 void set(PassRefPtr<IDBObjectStore>); | 116 void set(PassRefPtr<IDBObjectStore>); |
126 void set(PassRefPtr<IDBTransaction>); | 117 void set(PassRefPtr<IDBTransaction>); |
| 118 void set(PassRefPtr<SerializedScriptValue>); |
127 void set(const IDBKeyPath&); | 119 void set(const IDBKeyPath&); |
128 void set(const String&); | 120 void set(const String&); |
129 void set(const ScriptValue&); | |
130 void set(int64_t); | |
131 | 121 |
132 private: | 122 private: |
133 IDBAny(); | 123 IDBAny(); |
134 | 124 |
135 Type m_type; | 125 Type m_type; |
136 | 126 |
137 // Only one of the following should ever be in use at any given time. | 127 // Only one of the following should ever be in use at any given time. |
138 RefPtr<DOMStringList> m_domStringList; | 128 RefPtr<DOMStringList> m_domStringList; |
139 RefPtr<IDBCursor> m_idbCursor; | 129 RefPtr<IDBCursor> m_idbCursor; |
140 RefPtr<IDBCursorWithValue> m_idbCursorWithValue; | 130 RefPtr<IDBCursorWithValue> m_idbCursorWithValue; |
141 RefPtr<IDBDatabase> m_idbDatabase; | 131 RefPtr<IDBDatabase> m_idbDatabase; |
142 RefPtr<IDBFactory> m_idbFactory; | 132 RefPtr<IDBFactory> m_idbFactory; |
143 RefPtr<IDBIndex> m_idbIndex; | 133 RefPtr<IDBIndex> m_idbIndex; |
144 RefPtr<IDBKey> m_idbKey; | 134 RefPtr<IDBKey> m_idbKey; |
145 RefPtr<IDBObjectStore> m_idbObjectStore; | 135 RefPtr<IDBObjectStore> m_idbObjectStore; |
146 RefPtr<IDBTransaction> m_idbTransaction; | 136 RefPtr<IDBTransaction> m_idbTransaction; |
147 ScriptValue m_scriptValue; | 137 RefPtr<SerializedScriptValue> m_serializedScriptValue; |
148 String m_string; | 138 String m_string; |
149 int64_t m_integer; | |
150 }; | 139 }; |
151 | 140 |
152 } // namespace WebCore | 141 } // namespace WebCore |
153 | 142 |
154 #endif // ENABLE(INDEXED_DATABASE) | 143 #endif // ENABLE(INDEXED_DATABASE) |
155 | 144 |
156 #endif // IDBAny_h | 145 #endif // IDBAny_h |
OLD | NEW |