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
12 #include "mozilla/Attributes.h"
14 #include "mozIStorageBindingParamsArray.h"
19 class StorageBaseStatementInternal
;
21 class BindingParamsArray final
: public mozIStorageBindingParamsArray
{
22 typedef nsTArray
<nsCOMPtr
<mozIStorageBindingParams
> > array_type
;
24 ~BindingParamsArray() {}
27 NS_DECL_THREADSAFE_ISUPPORTS
28 NS_DECL_MOZISTORAGEBINDINGPARAMSARRAY
30 explicit BindingParamsArray(StorageBaseStatementInternal
* aOwningStatement
);
32 typedef array_type::size_type size_type
;
35 * Locks the array and prevents further modification to it (such as adding
36 * more elements to it).
41 * @return the pointer to the owning BindingParamsArray.
43 const StorageBaseStatementInternal
* getOwner() const;
46 * @return the number of elemets the array contains.
48 size_type
length() const { return mArray
.Length(); }
52 iterator(BindingParamsArray
* aArray
, uint32_t aIndex
)
53 : mArray(aArray
), mIndex(aIndex
) {}
55 iterator
& operator++(int) {
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();
72 BindingParamsArray
* mArray
;
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);
86 * Obtains an iterator pointing to the end of the array.
88 inline iterator
end() {
90 "Obtaining an iterator to the end when we are not locked!");
91 return iterator(this, length());
95 nsCOMPtr
<StorageBaseStatementInternal
> mOwningStatement
;
99 friend class iterator
;
102 } // namespace storage
103 } // namespace mozilla
105 #endif // mozStorageBindingParamsArray_h