2 * Copyright (C) 2011 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 "PlatformString.h"
32 #include <wtf/Forward.h>
33 #include <wtf/Threading.h>
34 #include <wtf/Vector.h>
38 class IDBKey : public ThreadSafeRefCounted<IDBKey> {
40 typedef Vector<RefPtr<IDBKey> > KeyArray;
42 static PassRefPtr<IDBKey> createInvalid()
44 RefPtr<IDBKey> idbKey(new IDBKey());
45 idbKey->m_type = InvalidType;
46 return idbKey.release();
49 static PassRefPtr<IDBKey> createNumber(double number)
51 RefPtr<IDBKey> idbKey(new IDBKey());
52 idbKey->m_type = NumberType;
53 idbKey->m_number = number;
54 return idbKey.release();
57 static PassRefPtr<IDBKey> createString(const String& string)
59 RefPtr<IDBKey> idbKey(new IDBKey());
60 idbKey->m_type = StringType;
61 idbKey->m_string = string;
62 return idbKey.release();
65 static PassRefPtr<IDBKey> createDate(double date)
67 RefPtr<IDBKey> idbKey(new IDBKey());
68 idbKey->m_type = DateType;
69 idbKey->m_date = date;
70 return idbKey.release();
73 static PassRefPtr<IDBKey> createArray(const KeyArray& array)
75 RefPtr<IDBKey> idbKey(new IDBKey());
76 idbKey->m_type = ArrayType;
77 idbKey->m_array = array;
78 return idbKey.release();
83 // In order of the least to the highest precedent in terms of sort order.
93 Type type() const { return m_type; }
94 bool valid() const { return m_type != InvalidType; }
96 const KeyArray& array() const
98 ASSERT(m_type == ArrayType);
102 const String& string() const
104 ASSERT(m_type == StringType);
110 ASSERT(m_type == DateType);
114 double number() const
116 ASSERT(m_type == NumberType);
120 int compare(const IDBKey* other) const;
121 bool isLessThan(const IDBKey* other) const;
122 bool isEqual(const IDBKey* other) const;
124 static int compareTypes(Type a, Type b)
129 using ThreadSafeRefCounted<IDBKey>::ref;
130 using ThreadSafeRefCounted<IDBKey>::deref;
144 #endif // ENABLE(INDEXED_DATABASE)