Bug 1472338: part 2) Change `clipboard.readText()` to read from the clipboard asynchr...
[gecko.git] / dom / indexedDB / IDBCursorType.h
blobc75918c10eadba1bda1792756e7aca11bf734992
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"
13 namespace mozilla {
14 namespace dom {
15 namespace indexedDB {
16 class ObjectStoreCursorResponse;
17 class ObjectStoreKeyCursorResponse;
18 class IndexCursorResponse;
19 class IndexKeyCursorResponse;
20 } // namespace indexedDB
22 enum struct IDBCursorType {
23 ObjectStore,
24 ObjectStoreKey,
25 Index,
26 IndexKey,
29 template <IDBCursorType CursorType>
30 struct CursorTypeTraits;
32 class IDBIndex;
33 class IDBObjectStore;
35 class IDBIndexCursor;
36 class IDBIndexKeyCursor;
37 class IDBObjectStoreCursor;
38 class IDBObjectStoreKeyCursor;
40 template <>
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;
48 template <>
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;
56 template <>
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;
64 template <>
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
86 ///< position
87 ///< (https://w3c.github.io/IndexedDB/#cursor-position).
90 template <IDBCursorType CursorType>
91 struct CursorData;
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
118 ///< position
119 ///< (https://w3c.github.io/IndexedDB/#cursor-object-store-position).
122 struct ValueCursorDataBase {
123 explicit ValueCursorDataBase(StructuredCloneReadInfoChild&& aCloneInfo);
125 StructuredCloneReadInfoChild mCloneInfo;
128 template <>
129 struct CursorData<IDBCursorType::ObjectStoreKey> : ObjectStoreCursorDataBase {
130 using ObjectStoreCursorDataBase::ObjectStoreCursorDataBase;
133 template <>
134 struct CursorData<IDBCursorType::ObjectStore> : ObjectStoreCursorDataBase,
135 ValueCursorDataBase {
136 CursorData(Key aKey, StructuredCloneReadInfoChild&& aCloneInfo);
139 template <>
140 struct CursorData<IDBCursorType::IndexKey> : IndexCursorDataBase {
141 using IndexCursorDataBase::IndexCursorDataBase;
144 template <>
145 struct CursorData<IDBCursorType::Index> : IndexCursorDataBase,
146 ValueCursorDataBase {
147 CursorData(Key aKey, Key aLocaleAwareKey, Key aObjectStoreKey,
148 StructuredCloneReadInfoChild&& aCloneInfo);
151 } // namespace dom
152 } // namespace mozilla
154 #endif