• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2010 Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * 1.  Redistributions of source code must retain the above copyright
9  *     notice, this list of conditions and the following disclaimer.
10  * 2.  Redistributions in binary form must reproduce the above copyright
11  *     notice, this list of conditions and the following disclaimer in the
12  *     documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
15  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
18  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
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
23  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 
26 #ifndef IDBAny_h
27 #define IDBAny_h
28 
29 #if ENABLE(INDEXED_DATABASE)
30 
31 #include <wtf/PassRefPtr.h>
32 #include <wtf/RefCounted.h>
33 #include <wtf/RefPtr.h>
34 
35 namespace WebCore {
36 
37 class IDBCursor;
38 class IDBCursorWithValue;
39 class IDBDatabase;
40 class IDBFactory;
41 class IDBIndex;
42 class IDBKey;
43 class IDBObjectStore;
44 class IDBTransaction;
45 class SerializedScriptValue;
46 
47 class IDBAny : public RefCounted<IDBAny> {
48 public:
49     static PassRefPtr<IDBAny> createInvalid();
50     static PassRefPtr<IDBAny> createNull();
51     template<typename T>
create(T * idbObject)52     static PassRefPtr<IDBAny> create(T* idbObject)
53     {
54         RefPtr<IDBAny> any = IDBAny::createInvalid();
55         any->set(idbObject);
56         return any.release();
57     }
58     template<typename T>
create(PassRefPtr<T> idbObject)59     static PassRefPtr<IDBAny> create(PassRefPtr<T> idbObject)
60     {
61         RefPtr<IDBAny> any = IDBAny::createInvalid();
62         any->set(idbObject);
63         return any.release();
64     }
65     ~IDBAny();
66 
67     enum Type {
68         UndefinedType = 0,
69         NullType,
70         IDBCursorType,
71         IDBCursorWithValueType,
72         IDBDatabaseType,
73         IDBFactoryType,
74         IDBIndexType,
75         IDBKeyType,
76         IDBObjectStoreType,
77         IDBTransactionType,
78         SerializedScriptValueType
79     };
80 
type()81     Type type() const { return m_type; }
82     // Use type() to figure out which one of these you're allowed to call.
83     PassRefPtr<IDBCursor> idbCursor();
84     PassRefPtr<IDBCursorWithValue> idbCursorWithValue();
85     PassRefPtr<IDBDatabase> idbDatabase();
86     PassRefPtr<IDBFactory> idbFactory();
87     PassRefPtr<IDBIndex> idbIndex();
88     PassRefPtr<IDBKey> idbKey();
89     PassRefPtr<IDBObjectStore> idbObjectStore();
90     PassRefPtr<IDBTransaction> idbTransaction();
91     PassRefPtr<SerializedScriptValue> serializedScriptValue();
92 
93     // Set can only be called once.
94     void setNull();
95     void set(PassRefPtr<IDBCursor>);
96     void set(PassRefPtr<IDBCursorWithValue>);
97     void set(PassRefPtr<IDBDatabase>);
98     void set(PassRefPtr<IDBFactory>);
99     void set(PassRefPtr<IDBIndex>);
100     void set(PassRefPtr<IDBKey>);
101     void set(PassRefPtr<IDBObjectStore>);
102     void set(PassRefPtr<IDBTransaction>);
103     void set(PassRefPtr<SerializedScriptValue>);
104 
105 private:
106     IDBAny();
107 
108     Type m_type;
109 
110     // Only one of the following should ever be in use at any given time.
111     RefPtr<IDBCursor> m_idbCursor;
112     RefPtr<IDBCursorWithValue> m_idbCursorWithValue;
113     RefPtr<IDBDatabase> m_idbDatabase;
114     RefPtr<IDBFactory> m_idbFactory;
115     RefPtr<IDBIndex> m_idbIndex;
116     RefPtr<IDBKey> m_idbKey;
117     RefPtr<IDBObjectStore> m_idbObjectStore;
118     RefPtr<IDBTransaction> m_idbTransaction;
119     RefPtr<SerializedScriptValue> m_serializedScriptValue;
120 };
121 
122 } // namespace WebCore
123 
124 #endif // ENABLE(INDEXED_DATABASE)
125 
126 #endif // IDBAny_h
127