~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Source/WebCore/Modules/indexeddb/IDBAny.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 "IDBKeyPath.h"
 
36
#include "IDBObjectStore.h"
 
37
#include "DOMStringList.h"
 
38
 
 
39
namespace WebCore {
 
40
 
 
41
PassRefPtr<IDBAny> IDBAny::createInvalid()
 
42
{
 
43
    return adoptRef(new IDBAny());
 
44
}
 
45
 
 
46
PassRefPtr<IDBAny> IDBAny::createNull()
 
47
{
 
48
    RefPtr<IDBAny> idbAny = adoptRef(new IDBAny());
 
49
    idbAny->setNull();
 
50
    return idbAny.release();
 
51
}
 
52
 
 
53
PassRefPtr<IDBAny> IDBAny::createString(const String& value)
 
54
{
 
55
    RefPtr<IDBAny> idbAny = adoptRef(new IDBAny());
 
56
    idbAny->set(value);
 
57
    return idbAny.release();
 
58
}
 
59
 
 
60
IDBAny::IDBAny()
 
61
    : m_type(UndefinedType)
 
62
{
 
63
}
 
64
 
 
65
IDBAny::~IDBAny()
 
66
{
 
67
}
 
68
 
 
69
PassRefPtr<DOMStringList> IDBAny::domStringList()
 
70
{
 
71
    ASSERT(m_type == DOMStringListType);
 
72
    return m_domStringList;
 
73
}
 
74
 
 
75
PassRefPtr<IDBCursor> IDBAny::idbCursor()
 
76
{
 
77
    ASSERT(m_type == IDBCursorType);
 
78
    return m_idbCursor;
 
79
}
 
80
 
 
81
PassRefPtr<IDBCursorWithValue> IDBAny::idbCursorWithValue()
 
82
{
 
83
    ASSERT(m_type == IDBCursorWithValueType);
 
84
    return m_idbCursorWithValue;
 
85
}
 
86
 
 
87
PassRefPtr<IDBDatabase> IDBAny::idbDatabase()
 
88
{
 
89
    ASSERT(m_type == IDBDatabaseType);
 
90
    return m_idbDatabase;
 
91
}
 
92
 
 
93
PassRefPtr<IDBFactory> IDBAny::idbFactory()
 
94
{
 
95
    ASSERT(m_type == IDBFactoryType);
 
96
    return m_idbFactory;
 
97
}
 
98
 
 
99
PassRefPtr<IDBIndex> IDBAny::idbIndex()
 
100
{
 
101
    ASSERT(m_type == IDBIndexType);
 
102
    return m_idbIndex;
 
103
}
 
104
 
 
105
PassRefPtr<IDBKey> IDBAny::idbKey()
 
106
{
 
107
    ASSERT(m_type == IDBKeyType);
 
108
    return m_idbKey;
 
109
}
 
110
 
 
111
PassRefPtr<IDBObjectStore> IDBAny::idbObjectStore()
 
112
{
 
113
    ASSERT(m_type == IDBObjectStoreType);
 
114
    return m_idbObjectStore;
 
115
}
 
116
 
 
117
PassRefPtr<IDBTransaction> IDBAny::idbTransaction()
 
118
{
 
119
    ASSERT(m_type == IDBTransactionType);
 
120
    return m_idbTransaction;
 
121
}
 
122
 
 
123
ScriptValue IDBAny::scriptValue()
 
124
{
 
125
    ASSERT(m_type == ScriptValueType);
 
126
    return m_scriptValue;
 
127
}
 
128
 
 
129
const String& IDBAny::string()
 
130
{
 
131
    ASSERT(m_type == StringType);
 
132
    return m_string;
 
133
}
 
134
 
 
135
int64_t IDBAny::integer()
 
136
{
 
137
    ASSERT(m_type == IntegerType);
 
138
    return m_integer;
 
139
}
 
140
 
 
141
void IDBAny::setNull()
 
142
{
 
143
    ASSERT(m_type == UndefinedType);
 
144
    m_type = NullType;
 
145
}
 
146
 
 
147
void IDBAny::set(PassRefPtr<DOMStringList> value)
 
148
{
 
149
    ASSERT(m_type == UndefinedType);
 
150
    m_type = DOMStringListType;
 
151
    m_domStringList = value;
 
152
}
 
153
 
 
154
void IDBAny::set(PassRefPtr<IDBCursorWithValue> value)
 
155
{
 
156
    ASSERT(m_type == UndefinedType);
 
157
    m_type = IDBCursorWithValueType;
 
158
    m_idbCursorWithValue = value;
 
159
}
 
160
 
 
161
void IDBAny::set(PassRefPtr<IDBCursor> value)
 
162
{
 
163
    ASSERT(m_type == UndefinedType);
 
164
    m_type = IDBCursorType;
 
165
    m_idbCursor = value;
 
166
}
 
167
 
 
168
void IDBAny::set(PassRefPtr<IDBDatabase> value)
 
169
{
 
170
    ASSERT(m_type == UndefinedType);
 
171
    m_type = IDBDatabaseType;
 
172
    m_idbDatabase = value;
 
173
}
 
174
 
 
175
void IDBAny::set(PassRefPtr<IDBFactory> value)
 
176
{
 
177
    ASSERT(m_type == UndefinedType);
 
178
    m_type = IDBFactoryType;
 
179
    m_idbFactory = value;
 
180
}
 
181
 
 
182
void IDBAny::set(PassRefPtr<IDBIndex> value)
 
183
{
 
184
    ASSERT(m_type == UndefinedType);
 
185
    m_type = IDBIndexType;
 
186
    m_idbIndex = value;
 
187
}
 
188
 
 
189
void IDBAny::set(PassRefPtr<IDBKey> value)
 
190
{
 
191
    ASSERT(m_type == UndefinedType);
 
192
    m_type = IDBKeyType;
 
193
    m_idbKey = value;
 
194
}
 
195
 
 
196
void IDBAny::set(PassRefPtr<IDBTransaction> value)
 
197
{
 
198
    ASSERT(m_type == UndefinedType);
 
199
    m_type = IDBTransactionType;
 
200
    m_idbTransaction = value;
 
201
}
 
202
 
 
203
void IDBAny::set(PassRefPtr<IDBObjectStore> value)
 
204
{
 
205
    ASSERT(m_type == UndefinedType);
 
206
    m_type = IDBObjectStoreType;
 
207
    m_idbObjectStore = value;
 
208
}
 
209
 
 
210
void IDBAny::set(const ScriptValue& value)
 
211
{
 
212
    ASSERT(m_type == UndefinedType);
 
213
    m_type = ScriptValueType;
 
214
    m_scriptValue = value;
 
215
}
 
216
 
 
217
void IDBAny::set(const IDBKeyPath& value)
 
218
{
 
219
    ASSERT(m_type == UndefinedType);
 
220
    switch (value.type()) {
 
221
    case IDBKeyPath::NullType:
 
222
        m_type = NullType;
 
223
        break;
 
224
    case IDBKeyPath::StringType:
 
225
        m_type = StringType;
 
226
        m_string = value.string();
 
227
        break;
 
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();
 
234
        break;
 
235
    }
 
236
}
 
237
 
 
238
void IDBAny::set(const String& value)
 
239
{
 
240
    ASSERT(m_type == UndefinedType);
 
241
    m_type = StringType;
 
242
    m_string = value;
 
243
}
 
244
 
 
245
void IDBAny::set(int64_t value)
 
246
{
 
247
    ASSERT(m_type == UndefinedType);
 
248
    m_type = IntegerType;
 
249
    m_integer = value;
 
250
}
 
251
 
 
252
} // namespace WebCore
 
253
 
 
254
#endif