2
* Copyright (C) 2010 Google Inc. All rights reserved.
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions
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.
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.
29
#if ENABLE(INDEXED_DATABASE)
31
#include "IDBCursorWithValue.h"
32
#include "IDBDatabase.h"
33
#include "IDBFactory.h"
35
#include "IDBKeyPath.h"
36
#include "IDBObjectStore.h"
37
#include "DOMStringList.h"
41
PassRefPtr<IDBAny> IDBAny::createInvalid()
43
return adoptRef(new IDBAny());
46
PassRefPtr<IDBAny> IDBAny::createNull()
48
RefPtr<IDBAny> idbAny = adoptRef(new IDBAny());
50
return idbAny.release();
53
PassRefPtr<IDBAny> IDBAny::createString(const String& value)
55
RefPtr<IDBAny> idbAny = adoptRef(new IDBAny());
57
return idbAny.release();
61
: m_type(UndefinedType)
69
PassRefPtr<DOMStringList> IDBAny::domStringList()
71
ASSERT(m_type == DOMStringListType);
72
return m_domStringList;
75
PassRefPtr<IDBCursor> IDBAny::idbCursor()
77
ASSERT(m_type == IDBCursorType);
81
PassRefPtr<IDBCursorWithValue> IDBAny::idbCursorWithValue()
83
ASSERT(m_type == IDBCursorWithValueType);
84
return m_idbCursorWithValue;
87
PassRefPtr<IDBDatabase> IDBAny::idbDatabase()
89
ASSERT(m_type == IDBDatabaseType);
93
PassRefPtr<IDBFactory> IDBAny::idbFactory()
95
ASSERT(m_type == IDBFactoryType);
99
PassRefPtr<IDBIndex> IDBAny::idbIndex()
101
ASSERT(m_type == IDBIndexType);
105
PassRefPtr<IDBKey> IDBAny::idbKey()
107
ASSERT(m_type == IDBKeyType);
111
PassRefPtr<IDBObjectStore> IDBAny::idbObjectStore()
113
ASSERT(m_type == IDBObjectStoreType);
114
return m_idbObjectStore;
117
PassRefPtr<IDBTransaction> IDBAny::idbTransaction()
119
ASSERT(m_type == IDBTransactionType);
120
return m_idbTransaction;
123
ScriptValue IDBAny::scriptValue()
125
ASSERT(m_type == ScriptValueType);
126
return m_scriptValue;
129
const String& IDBAny::string()
131
ASSERT(m_type == StringType);
135
int64_t IDBAny::integer()
137
ASSERT(m_type == IntegerType);
141
void IDBAny::setNull()
143
ASSERT(m_type == UndefinedType);
147
void IDBAny::set(PassRefPtr<DOMStringList> value)
149
ASSERT(m_type == UndefinedType);
150
m_type = DOMStringListType;
151
m_domStringList = value;
154
void IDBAny::set(PassRefPtr<IDBCursorWithValue> value)
156
ASSERT(m_type == UndefinedType);
157
m_type = IDBCursorWithValueType;
158
m_idbCursorWithValue = value;
161
void IDBAny::set(PassRefPtr<IDBCursor> value)
163
ASSERT(m_type == UndefinedType);
164
m_type = IDBCursorType;
168
void IDBAny::set(PassRefPtr<IDBDatabase> value)
170
ASSERT(m_type == UndefinedType);
171
m_type = IDBDatabaseType;
172
m_idbDatabase = value;
175
void IDBAny::set(PassRefPtr<IDBFactory> value)
177
ASSERT(m_type == UndefinedType);
178
m_type = IDBFactoryType;
179
m_idbFactory = value;
182
void IDBAny::set(PassRefPtr<IDBIndex> value)
184
ASSERT(m_type == UndefinedType);
185
m_type = IDBIndexType;
189
void IDBAny::set(PassRefPtr<IDBKey> value)
191
ASSERT(m_type == UndefinedType);
196
void IDBAny::set(PassRefPtr<IDBTransaction> value)
198
ASSERT(m_type == UndefinedType);
199
m_type = IDBTransactionType;
200
m_idbTransaction = value;
203
void IDBAny::set(PassRefPtr<IDBObjectStore> value)
205
ASSERT(m_type == UndefinedType);
206
m_type = IDBObjectStoreType;
207
m_idbObjectStore = value;
210
void IDBAny::set(const ScriptValue& value)
212
ASSERT(m_type == UndefinedType);
213
m_type = ScriptValueType;
214
m_scriptValue = value;
217
void IDBAny::set(const IDBKeyPath& value)
219
ASSERT(m_type == UndefinedType);
220
switch (value.type()) {
221
case IDBKeyPath::NullType:
224
case IDBKeyPath::StringType:
226
m_string = value.string();
228
case IDBKeyPath::ArrayType:
229
RefPtr<DOMStringList> keyPaths = DOMStringList::create();
230
for (Vector<String>::const_iterator it = value.array().begin(); it != value.array().end(); ++it)
231
keyPaths->append(*it);
232
m_type = DOMStringListType;
233
m_domStringList = keyPaths.release();
238
void IDBAny::set(const String& value)
240
ASSERT(m_type == UndefinedType);
245
void IDBAny::set(int64_t value)
247
ASSERT(m_type == UndefinedType);
248
m_type = IntegerType;
252
} // namespace WebCore