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#include "config.h"
27#include "IDBAny.h"
28
29#if ENABLE(INDEXED_DATABASE)
30
31#include "IDBCursorWithValue.h"
32#include "IDBDatabase.h"
33#include "IDBFactory.h"
34#include "IDBIndex.h"
35#include "IDBObjectStore.h"
36#include "SerializedScriptValue.h"
37
38namespace WebCore {
39
40PassRefPtr<IDBAny> IDBAny::createInvalid()
41{
42    return adoptRef(new IDBAny());
43}
44
45PassRefPtr<IDBAny> IDBAny::createNull()
46{
47    RefPtr<IDBAny> idbAny = adoptRef(new IDBAny());
48    idbAny->setNull();
49    return idbAny.release();
50}
51
52IDBAny::IDBAny()
53    : m_type(UndefinedType)
54{
55}
56
57IDBAny::~IDBAny()
58{
59}
60
61PassRefPtr<IDBCursor> IDBAny::idbCursor()
62{
63    ASSERT(m_type == IDBCursorType);
64    return m_idbCursor;
65}
66
67
68PassRefPtr<IDBCursorWithValue> IDBAny::idbCursorWithValue()
69{
70    ASSERT(m_type == IDBCursorWithValueType);
71    return m_idbCursorWithValue;
72}
73
74PassRefPtr<IDBDatabase> IDBAny::idbDatabase()
75{
76    ASSERT(m_type == IDBDatabaseType);
77    return m_idbDatabase;
78}
79
80PassRefPtr<IDBFactory> IDBAny::idbFactory()
81{
82    ASSERT(m_type == IDBFactoryType);
83    return m_idbFactory;
84}
85
86PassRefPtr<IDBIndex> IDBAny::idbIndex()
87{
88    ASSERT(m_type == IDBIndexType);
89    return m_idbIndex;
90}
91
92PassRefPtr<IDBKey> IDBAny::idbKey()
93{
94    ASSERT(m_type == IDBKeyType);
95    return m_idbKey;
96}
97
98PassRefPtr<IDBObjectStore> IDBAny::idbObjectStore()
99{
100    ASSERT(m_type == IDBObjectStoreType);
101    return m_idbObjectStore;
102}
103
104PassRefPtr<IDBTransaction> IDBAny::idbTransaction()
105{
106    ASSERT(m_type == IDBTransactionType);
107    return m_idbTransaction;
108}
109
110PassRefPtr<SerializedScriptValue> IDBAny::serializedScriptValue()
111{
112    ASSERT(m_type == SerializedScriptValueType);
113    return m_serializedScriptValue;
114}
115
116void IDBAny::setNull()
117{
118    ASSERT(m_type == UndefinedType);
119    m_type = NullType;
120}
121
122void IDBAny::set(PassRefPtr<IDBCursorWithValue> value)
123{
124    ASSERT(m_type == UndefinedType);
125    m_type = IDBCursorWithValueType;
126    m_idbCursorWithValue = value;
127}
128
129void IDBAny::set(PassRefPtr<IDBCursor> value)
130{
131    ASSERT(m_type == UndefinedType);
132    m_type = IDBCursorType;
133    m_idbCursor = value;
134}
135
136void IDBAny::set(PassRefPtr<IDBDatabase> value)
137{
138    ASSERT(m_type == UndefinedType);
139    m_type = IDBDatabaseType;
140    m_idbDatabase = value;
141}
142
143void IDBAny::set(PassRefPtr<IDBFactory> value)
144{
145    ASSERT(m_type == UndefinedType);
146    m_type = IDBFactoryType;
147    m_idbFactory = value;
148}
149
150void IDBAny::set(PassRefPtr<IDBIndex> value)
151{
152    ASSERT(m_type == UndefinedType);
153    m_type = IDBIndexType;
154    m_idbIndex = value;
155}
156
157void IDBAny::set(PassRefPtr<IDBKey> value)
158{
159    ASSERT(m_type == UndefinedType);
160    m_type = IDBKeyType;
161    m_idbKey = value;
162}
163
164void IDBAny::set(PassRefPtr<IDBTransaction> value)
165{
166    ASSERT(m_type == UndefinedType);
167    m_type = IDBTransactionType;
168    m_idbTransaction = value;
169}
170
171void IDBAny::set(PassRefPtr<IDBObjectStore> value)
172{
173    ASSERT(m_type == UndefinedType);
174    m_type = IDBObjectStoreType;
175    m_idbObjectStore = value;
176}
177
178void IDBAny::set(PassRefPtr<SerializedScriptValue> value)
179{
180    ASSERT(m_type == UndefinedType);
181    m_type = SerializedScriptValueType;
182    m_serializedScriptValue = value;
183}
184
185} // namespace WebCore
186
187#endif
188