Bug 1318565 - Allow extensions with permission to read from tainted Canvas r=bz
[gecko.git] / storage / mozStorageBindingParamsArray.h
blob4626ab55f5c4cbc159018f9051176693303dce6d
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 "nsAutoPtr.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
23 typedef nsTArray< nsCOMPtr<mozIStorageBindingParams> > array_type;
25 ~BindingParamsArray() {}
27 public:
28 NS_DECL_THREADSAFE_ISUPPORTS
29 NS_DECL_MOZISTORAGEBINDINGPARAMSARRAY
31 explicit BindingParamsArray(StorageBaseStatementInternal *aOwningStatement);
33 typedef array_type::size_type size_type;
35 /**
36 * Locks the array and prevents further modification to it (such as adding
37 * more elements to it).
39 void lock();
41 /**
42 * @return the pointer to the owning BindingParamsArray.
44 const StorageBaseStatementInternal *getOwner() const;
46 /**
47 * @return the number of elemets the array contains.
49 size_type length() const { return mArray.Length(); }
51 class iterator {
52 public:
53 iterator(BindingParamsArray *aArray,
54 uint32_t aIndex)
55 : mArray(aArray)
56 , mIndex(aIndex)
60 iterator &operator++(int)
62 mIndex++;
63 return *this;
66 bool operator==(const iterator &aOther) const
68 return mIndex == aOther.mIndex;
70 bool operator!=(const iterator &aOther) const
72 return !(*this == aOther);
74 mozIStorageBindingParams *operator*()
76 NS_ASSERTION(mIndex < mArray->length(),
77 "Dereferenceing an invalid value!");
78 return mArray->mArray[mIndex].get();
80 private:
81 void operator--() { }
82 BindingParamsArray *mArray;
83 uint32_t mIndex;
86 /**
87 * Obtains an iterator pointing to the beginning of the array.
89 inline iterator begin()
91 NS_ASSERTION(length() != 0,
92 "Obtaining an iterator to the beginning with no elements!");
93 return iterator(this, 0);
96 /**
97 * Obtains an iterator pointing to the end of the array.
99 inline iterator end()
101 NS_ASSERTION(mLocked,
102 "Obtaining an iterator to the end when we are not locked!");
103 return iterator(this, length());
105 private:
106 nsCOMPtr<StorageBaseStatementInternal> mOwningStatement;
107 array_type mArray;
108 bool mLocked;
110 friend class iterator;
113 } // namespace storage
114 } // namespace mozilla
116 #endif // mozStorageBindingParamsArray_h