1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_idbcursortype_h__
8 #define mozilla_dom_idbcursortype_h__
10 #include "IndexedDatabase.h"
11 #include "mozilla/dom/indexedDB/Key.h"
16 class ObjectStoreCursorResponse
;
17 class ObjectStoreKeyCursorResponse
;
18 class IndexCursorResponse
;
19 class IndexKeyCursorResponse
;
20 } // namespace indexedDB
22 enum struct IDBCursorType
{
29 template <IDBCursorType CursorType
>
30 struct CursorTypeTraits
;
36 class IDBIndexKeyCursor
;
37 class IDBObjectStoreCursor
;
38 class IDBObjectStoreKeyCursor
;
41 struct CursorTypeTraits
<IDBCursorType::Index
> {
42 using Type
= IDBIndexCursor
;
43 using ResponseType
= indexedDB::IndexCursorResponse
;
44 static constexpr bool IsObjectStoreCursor
= false;
45 static constexpr bool IsKeyOnlyCursor
= false;
49 struct CursorTypeTraits
<IDBCursorType::IndexKey
> {
50 using Type
= IDBIndexKeyCursor
;
51 using ResponseType
= indexedDB::IndexKeyCursorResponse
;
52 static constexpr bool IsObjectStoreCursor
= false;
53 static constexpr bool IsKeyOnlyCursor
= true;
57 struct CursorTypeTraits
<IDBCursorType::ObjectStore
> {
58 using Type
= IDBObjectStoreCursor
;
59 using ResponseType
= indexedDB::ObjectStoreCursorResponse
;
60 static constexpr bool IsObjectStoreCursor
= true;
61 static constexpr bool IsKeyOnlyCursor
= false;
65 struct CursorTypeTraits
<IDBCursorType::ObjectStoreKey
> {
66 using Type
= IDBObjectStoreKeyCursor
;
67 using ResponseType
= indexedDB::ObjectStoreKeyCursorResponse
;
68 static constexpr bool IsObjectStoreCursor
= true;
69 static constexpr bool IsKeyOnlyCursor
= true;
72 template <IDBCursorType CursorType
>
73 using CursorSourceType
=
74 std::conditional_t
<CursorTypeTraits
<CursorType
>::IsObjectStoreCursor
,
75 IDBObjectStore
, IDBIndex
>;
77 using Key
= indexedDB::Key
;
78 using StructuredCloneReadInfoChild
= indexedDB::StructuredCloneReadInfoChild
;
80 struct CommonCursorDataBase
{
81 CommonCursorDataBase() = delete;
83 explicit CommonCursorDataBase(Key aKey
);
85 Key mKey
; ///< The current key, i.e. the key representing the cursor's
87 ///< (https://w3c.github.io/IndexedDB/#cursor-position).
90 template <IDBCursorType CursorType
>
93 struct ObjectStoreCursorDataBase
: CommonCursorDataBase
{
94 using CommonCursorDataBase::CommonCursorDataBase
;
96 const Key
& GetSortKey(const bool aIsLocaleAware
) const {
97 MOZ_ASSERT(!aIsLocaleAware
);
98 return GetObjectStoreKey();
100 const Key
& GetObjectStoreKey() const { return mKey
; }
101 static constexpr const char* GetObjectStoreKeyForLogging() { return "NA"; }
104 struct IndexCursorDataBase
: CommonCursorDataBase
{
105 IndexCursorDataBase(Key aKey
, Key aLocaleAwareKey
, Key aObjectStoreKey
);
107 const Key
& GetSortKey(const bool aIsLocaleAware
) const {
108 return aIsLocaleAware
? mLocaleAwareKey
: mKey
;
110 const Key
& GetObjectStoreKey() const { return mObjectStoreKey
; }
111 const char* GetObjectStoreKeyForLogging() const {
112 return GetObjectStoreKey().GetBuffer().get();
115 Key mLocaleAwareKey
; ///< If the index's mLocale is set, this is mKey
116 ///< converted to mLocale. Otherwise, it is unset.
117 Key mObjectStoreKey
; ///< The key representing the cursor's object store
119 ///< (https://w3c.github.io/IndexedDB/#cursor-object-store-position).
122 struct ValueCursorDataBase
{
123 explicit ValueCursorDataBase(StructuredCloneReadInfoChild
&& aCloneInfo
);
125 StructuredCloneReadInfoChild mCloneInfo
;
129 struct CursorData
<IDBCursorType::ObjectStoreKey
> : ObjectStoreCursorDataBase
{
130 using ObjectStoreCursorDataBase::ObjectStoreCursorDataBase
;
134 struct CursorData
<IDBCursorType::ObjectStore
> : ObjectStoreCursorDataBase
,
135 ValueCursorDataBase
{
136 CursorData(Key aKey
, StructuredCloneReadInfoChild
&& aCloneInfo
);
140 struct CursorData
<IDBCursorType::IndexKey
> : IndexCursorDataBase
{
141 using IndexCursorDataBase::IndexCursorDataBase
;
145 struct CursorData
<IDBCursorType::Index
> : IndexCursorDataBase
,
146 ValueCursorDataBase
{
147 CursorData(Key aKey
, Key aLocaleAwareKey
, Key aObjectStoreKey
,
148 StructuredCloneReadInfoChild
&& aCloneInfo
);
152 } // namespace mozilla