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 IDBKeyRange_h 27#define IDBKeyRange_h 28 29#if ENABLE(INDEXED_DATABASE) 30 31#include "Dictionary.h" 32#include "IDBKey.h" 33#include "ScriptWrappable.h" 34#include <wtf/PassRefPtr.h> 35#include <wtf/RefCounted.h> 36 37namespace WebCore { 38 39typedef int ExceptionCode; 40 41class IDBKeyRange : public ScriptWrappable, public RefCounted<IDBKeyRange> { 42public: 43 enum LowerBoundType { 44 LowerBoundOpen, 45 LowerBoundClosed 46 }; 47 enum UpperBoundType { 48 UpperBoundOpen, 49 UpperBoundClosed 50 }; 51 52 static PassRefPtr<IDBKeyRange> create(PassRefPtr<IDBKey> lower, PassRefPtr<IDBKey> upper, LowerBoundType lowerType, UpperBoundType upperType) 53 { 54 return adoptRef(new IDBKeyRange(lower, upper, lowerType, upperType)); 55 } 56 static PassRefPtr<IDBKeyRange> create(PassRefPtr<IDBKey> prpKey); 57 ~IDBKeyRange() { } 58 59 PassRefPtr<IDBKey> lower() const { return m_lower; } 60 PassRefPtr<IDBKey> upper() const { return m_upper; } 61 62 ScriptValue lowerValue(ScriptExecutionContext*) const; 63 ScriptValue upperValue(ScriptExecutionContext*) const; 64 bool lowerOpen() const { return m_lowerType == LowerBoundOpen; } 65 bool upperOpen() const { return m_upperType == UpperBoundOpen; } 66 67 static PassRefPtr<IDBKeyRange> only(PassRefPtr<IDBKey> value, ExceptionCode&); 68 static PassRefPtr<IDBKeyRange> only(ScriptExecutionContext*, const ScriptValue& key, ExceptionCode&); 69 70 static PassRefPtr<IDBKeyRange> lowerBound(ScriptExecutionContext* context, const ScriptValue& bound, ExceptionCode& ec) { return lowerBound(context, bound, false, ec); } 71 static PassRefPtr<IDBKeyRange> lowerBound(ScriptExecutionContext*, const ScriptValue& bound, bool open, ExceptionCode&); 72 73 static PassRefPtr<IDBKeyRange> upperBound(ScriptExecutionContext* context, const ScriptValue& bound, ExceptionCode& ec) { return upperBound(context, bound, false, ec); } 74 static PassRefPtr<IDBKeyRange> upperBound(ScriptExecutionContext*, const ScriptValue& bound, bool open, ExceptionCode&); 75 76 static PassRefPtr<IDBKeyRange> bound(ScriptExecutionContext* context, const ScriptValue& lower, const ScriptValue& upper, ExceptionCode& ec) { return bound(context, lower, upper, false, false, ec); } 77 static PassRefPtr<IDBKeyRange> bound(ScriptExecutionContext* context, const ScriptValue& lower, const ScriptValue& upper, bool lowerOpen, ExceptionCode& ec) { return bound(context, lower, upper, lowerOpen, false, ec); } 78 static PassRefPtr<IDBKeyRange> bound(ScriptExecutionContext*, const ScriptValue& lower, const ScriptValue& upper, bool lowerOpen, bool upperOpen, ExceptionCode&); 79 80 bool isOnlyKey() const; 81 82private: 83 IDBKeyRange(PassRefPtr<IDBKey> lower, PassRefPtr<IDBKey> upper, LowerBoundType lowerType, UpperBoundType upperType); 84 85 RefPtr<IDBKey> m_lower; 86 RefPtr<IDBKey> m_upper; 87 LowerBoundType m_lowerType; 88 UpperBoundType m_upperType; 89}; 90 91} // namespace WebCore 92 93#endif 94 95#endif // IDBKeyRange_h 96