/src/mozilla-central/storage/mozStorageBindingParamsArray.h
Line | Count | Source (jump to first uncovered line) |
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/. */ |
6 | | |
7 | | #ifndef mozStorageBindingParamsArray_h |
8 | | #define mozStorageBindingParamsArray_h |
9 | | |
10 | | #include "nsAutoPtr.h" |
11 | | #include "nsTArray.h" |
12 | | #include "mozilla/Attributes.h" |
13 | | |
14 | | #include "mozIStorageBindingParamsArray.h" |
15 | | |
16 | | namespace mozilla { |
17 | | namespace storage { |
18 | | |
19 | | class StorageBaseStatementInternal; |
20 | | |
21 | | class BindingParamsArray final : public mozIStorageBindingParamsArray |
22 | | { |
23 | | typedef nsTArray< nsCOMPtr<mozIStorageBindingParams> > array_type; |
24 | | |
25 | 0 | ~BindingParamsArray() {} |
26 | | |
27 | | public: |
28 | | NS_DECL_THREADSAFE_ISUPPORTS |
29 | | NS_DECL_MOZISTORAGEBINDINGPARAMSARRAY |
30 | | |
31 | | explicit BindingParamsArray(StorageBaseStatementInternal *aOwningStatement); |
32 | | |
33 | | typedef array_type::size_type size_type; |
34 | | |
35 | | /** |
36 | | * Locks the array and prevents further modification to it (such as adding |
37 | | * more elements to it). |
38 | | */ |
39 | | void lock(); |
40 | | |
41 | | /** |
42 | | * @return the pointer to the owning BindingParamsArray. |
43 | | */ |
44 | | const StorageBaseStatementInternal *getOwner() const; |
45 | | |
46 | | /** |
47 | | * @return the number of elemets the array contains. |
48 | | */ |
49 | 0 | size_type length() const { return mArray.Length(); } |
50 | | |
51 | | class iterator { |
52 | | public: |
53 | | iterator(BindingParamsArray *aArray, |
54 | | uint32_t aIndex) |
55 | | : mArray(aArray) |
56 | | , mIndex(aIndex) |
57 | 0 | { |
58 | 0 | } |
59 | | |
60 | | iterator &operator++(int) |
61 | 0 | { |
62 | 0 | mIndex++; |
63 | 0 | return *this; |
64 | 0 | } |
65 | | |
66 | | bool operator==(const iterator &aOther) const |
67 | 0 | { |
68 | 0 | return mIndex == aOther.mIndex; |
69 | 0 | } |
70 | | bool operator!=(const iterator &aOther) const |
71 | 0 | { |
72 | 0 | return !(*this == aOther); |
73 | 0 | } |
74 | | mozIStorageBindingParams *operator*() |
75 | 0 | { |
76 | 0 | NS_ASSERTION(mIndex < mArray->length(), |
77 | 0 | "Dereferenceing an invalid value!"); |
78 | 0 | return mArray->mArray[mIndex].get(); |
79 | 0 | } |
80 | | private: |
81 | 0 | void operator--() { } |
82 | | BindingParamsArray *mArray; |
83 | | uint32_t mIndex; |
84 | | }; |
85 | | |
86 | | /** |
87 | | * Obtains an iterator pointing to the beginning of the array. |
88 | | */ |
89 | | inline iterator begin() |
90 | 0 | { |
91 | 0 | NS_ASSERTION(length() != 0, |
92 | 0 | "Obtaining an iterator to the beginning with no elements!"); |
93 | 0 | return iterator(this, 0); |
94 | 0 | } |
95 | | |
96 | | /** |
97 | | * Obtains an iterator pointing to the end of the array. |
98 | | */ |
99 | | inline iterator end() |
100 | 0 | { |
101 | 0 | NS_ASSERTION(mLocked, |
102 | 0 | "Obtaining an iterator to the end when we are not locked!"); |
103 | 0 | return iterator(this, length()); |
104 | 0 | } |
105 | | private: |
106 | | nsCOMPtr<StorageBaseStatementInternal> mOwningStatement; |
107 | | array_type mArray; |
108 | | bool mLocked; |
109 | | |
110 | | friend class iterator; |
111 | | }; |
112 | | |
113 | | } // namespace storage |
114 | | } // namespace mozilla |
115 | | |
116 | | #endif // mozStorageBindingParamsArray_h |