Bug 1850713: remove duplicated setting of early hint preloader id in `ScriptLoader...
[gecko.git] / storage / mozStorageBindingParamsArray.h
blob58d5a52ab6ae2aa7eaccfa95129f744ad5852590
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ :
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 mozStorageBindingParamsArray_h
8 #define mozStorageBindingParamsArray_h
10 #include "nsCOMPtr.h"
11 #include "nsTArray.h"
12 #include "mozilla/Attributes.h"
14 #include "mozIStorageBindingParamsArray.h"
16 namespace mozilla {
17 namespace storage {
19 class StorageBaseStatementInternal;
21 class BindingParamsArray final : public mozIStorageBindingParamsArray {
22 typedef nsTArray<nsCOMPtr<mozIStorageBindingParams> > array_type;
24 ~BindingParamsArray() {}
26 public:
27 NS_DECL_THREADSAFE_ISUPPORTS
28 NS_DECL_MOZISTORAGEBINDINGPARAMSARRAY
30 explicit BindingParamsArray(StorageBaseStatementInternal* aOwningStatement);
32 typedef array_type::size_type size_type;
34 /**
35 * Locks the array and prevents further modification to it (such as adding
36 * more elements to it).
38 void lock();
40 /**
41 * @return the pointer to the owning BindingParamsArray.
43 const StorageBaseStatementInternal* getOwner() const;
45 /**
46 * @return the number of elemets the array contains.
48 size_type length() const { return mArray.Length(); }
50 class iterator {
51 public:
52 iterator(BindingParamsArray* aArray, uint32_t aIndex)
53 : mArray(aArray), mIndex(aIndex) {}
55 iterator& operator++(int) {
56 mIndex++;
57 return *this;
60 bool operator==(const iterator& aOther) const {
61 return mIndex == aOther.mIndex;
63 bool operator!=(const iterator& aOther) const { return !(*this == aOther); }
64 mozIStorageBindingParams* operator*() {
65 NS_ASSERTION(mIndex < mArray->length(),
66 "Dereferenceing an invalid value!");
67 return mArray->mArray[mIndex].get();
70 private:
71 void operator--() {}
72 BindingParamsArray* mArray;
73 uint32_t mIndex;
76 /**
77 * Obtains an iterator pointing to the beginning of the array.
79 inline iterator begin() {
80 NS_ASSERTION(length() != 0,
81 "Obtaining an iterator to the beginning with no elements!");
82 return iterator(this, 0);
85 /**
86 * Obtains an iterator pointing to the end of the array.
88 inline iterator end() {
89 NS_ASSERTION(mLocked,
90 "Obtaining an iterator to the end when we are not locked!");
91 return iterator(this, length());
94 private:
95 nsCOMPtr<StorageBaseStatementInternal> mOwningStatement;
96 array_type mArray;
97 bool mLocked;
99 friend class iterator;
102 } // namespace storage
103 } // namespace mozilla
105 #endif // mozStorageBindingParamsArray_h