Home | History | Annotate | Download | only in indexeddb
      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 IDBAny_h
     27 #define IDBAny_h
     28 
     29 #include "bindings/v8/ScriptValue.h"
     30 #include "bindings/v8/ScriptWrappable.h"
     31 #include "modules/indexeddb/IDBKeyPath.h"
     32 #include "wtf/PassRefPtr.h"
     33 #include "wtf/RefCounted.h"
     34 #include "wtf/RefPtr.h"
     35 #include "wtf/text/WTFString.h"
     36 
     37 namespace WebCore {
     38 
     39 class DOMStringList;
     40 class IDBCursor;
     41 class IDBCursorWithValue;
     42 class IDBDatabase;
     43 class IDBFactory;
     44 class IDBIndex;
     45 class IDBKeyPath;
     46 class IDBObjectStore;
     47 class IDBTransaction;
     48 
     49 class IDBAny : public RefCounted<IDBAny> {
     50 public:
     51     static PassRefPtr<IDBAny> createInvalid();
     52     static PassRefPtr<IDBAny> createNull();
     53     static PassRefPtr<IDBAny> createString(const String&);
     54     template<typename T>
     55     static PassRefPtr<IDBAny> create(T* idbObject)
     56     {
     57         return adoptRef(new IDBAny(idbObject));
     58     }
     59     template<typename T>
     60     static PassRefPtr<IDBAny> create(const T& idbObject)
     61     {
     62         return adoptRef(new IDBAny(idbObject));
     63     }
     64     template<typename T>
     65     static PassRefPtr<IDBAny> create(PassRefPtr<T> idbObject)
     66     {
     67         return adoptRef(new IDBAny(idbObject));
     68     }
     69     static PassRefPtr<IDBAny> create(int64_t value)
     70     {
     71         return adoptRef(new IDBAny(value));
     72     }
     73     ~IDBAny();
     74 
     75     enum Type {
     76         UndefinedType = 0,
     77         NullType,
     78         DOMStringListType,
     79         IDBCursorType,
     80         IDBCursorWithValueType,
     81         IDBDatabaseType,
     82         IDBFactoryType,
     83         IDBIndexType,
     84         IDBObjectStoreType,
     85         IDBTransactionType,
     86         ScriptValueType,
     87         IntegerType,
     88         StringType,
     89         KeyPathType,
     90     };
     91 
     92     Type type() const { return m_type; }
     93     // Use type() to figure out which one of these you're allowed to call.
     94     PassRefPtr<DOMStringList> domStringList();
     95     PassRefPtr<IDBCursor> idbCursor();
     96     PassRefPtr<IDBCursorWithValue> idbCursorWithValue();
     97     PassRefPtr<IDBDatabase> idbDatabase();
     98     PassRefPtr<IDBFactory> idbFactory();
     99     PassRefPtr<IDBIndex> idbIndex();
    100     PassRefPtr<IDBObjectStore> idbObjectStore();
    101     PassRefPtr<IDBTransaction> idbTransaction();
    102     const ScriptValue& scriptValue();
    103     int64_t integer();
    104     const String& string();
    105     const IDBKeyPath& keyPath() { return m_idbKeyPath; };
    106 
    107 private:
    108     explicit IDBAny(Type);
    109     explicit IDBAny(PassRefPtr<DOMStringList>);
    110     explicit IDBAny(PassRefPtr<IDBCursor>);
    111     explicit IDBAny(PassRefPtr<IDBDatabase>);
    112     explicit IDBAny(PassRefPtr<IDBFactory>);
    113     explicit IDBAny(PassRefPtr<IDBIndex>);
    114     explicit IDBAny(PassRefPtr<IDBObjectStore>);
    115     explicit IDBAny(PassRefPtr<IDBTransaction>);
    116     explicit IDBAny(const IDBKeyPath&);
    117     explicit IDBAny(const String&);
    118     explicit IDBAny(const ScriptValue&);
    119     explicit IDBAny(int64_t);
    120 
    121     const Type m_type;
    122 
    123     // Only one of the following should ever be in use at any given time.
    124     const RefPtr<DOMStringList> m_domStringList;
    125     const RefPtr<IDBCursor> m_idbCursor;
    126     const RefPtr<IDBDatabase> m_idbDatabase;
    127     const RefPtr<IDBFactory> m_idbFactory;
    128     const RefPtr<IDBIndex> m_idbIndex;
    129     const RefPtr<IDBObjectStore> m_idbObjectStore;
    130     const RefPtr<IDBTransaction> m_idbTransaction;
    131     const IDBKeyPath m_idbKeyPath;
    132     const ScriptValue m_scriptValue;
    133     const String m_string;
    134     const int64_t m_integer;
    135 };
    136 
    137 } // namespace WebCore
    138 
    139 #endif // IDBAny_h
    140