2009-06-17 23:12:51 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
* vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ :
|
2012-05-21 15:12:37 +04:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2009-06-17 23:12:51 +04:00
|
|
|
|
2010-06-01 16:38:00 +04:00
|
|
|
#ifndef mozStorageBindingParamsArray_h
|
|
|
|
#define mozStorageBindingParamsArray_h
|
2009-06-17 23:12:51 +04:00
|
|
|
|
2020-11-23 19:21:38 +03:00
|
|
|
#include "nsCOMPtr.h"
|
2009-06-17 23:12:51 +04:00
|
|
|
#include "nsTArray.h"
|
2012-06-13 07:35:10 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2009-06-17 23:12:51 +04:00
|
|
|
|
|
|
|
#include "mozIStorageBindingParamsArray.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace storage {
|
|
|
|
|
2010-03-24 10:32:40 +03:00
|
|
|
class StorageBaseStatementInternal;
|
2009-06-17 23:12:51 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class BindingParamsArray final : public mozIStorageBindingParamsArray {
|
2010-11-09 05:48:59 +03:00
|
|
|
typedef nsTArray<nsCOMPtr<mozIStorageBindingParams> > array_type;
|
|
|
|
|
2014-06-24 02:40:03 +04:00
|
|
|
~BindingParamsArray() {}
|
|
|
|
|
2009-06-17 23:12:51 +04:00
|
|
|
public:
|
2013-07-19 06:24:15 +04:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2009-06-17 23:12:51 +04:00
|
|
|
NS_DECL_MOZISTORAGEBINDINGPARAMSARRAY
|
|
|
|
|
2014-08-08 03:47:28 +04:00
|
|
|
explicit BindingParamsArray(StorageBaseStatementInternal* aOwningStatement);
|
2009-06-17 23:12:51 +04:00
|
|
|
|
2010-11-09 05:48:59 +03:00
|
|
|
typedef array_type::size_type size_type;
|
2009-07-28 21:21:03 +04:00
|
|
|
|
2009-06-17 23:12:51 +04:00
|
|
|
/**
|
|
|
|
* Locks the array and prevents further modification to it (such as adding
|
|
|
|
* more elements to it).
|
|
|
|
*/
|
|
|
|
void lock();
|
|
|
|
|
|
|
|
/**
|
2009-07-28 21:21:03 +04:00
|
|
|
* @return the pointer to the owning BindingParamsArray.
|
2009-06-17 23:12:51 +04:00
|
|
|
*/
|
2010-03-24 10:32:40 +03:00
|
|
|
const StorageBaseStatementInternal* getOwner() const;
|
2009-06-17 23:12:51 +04:00
|
|
|
|
2009-07-28 21:21:03 +04:00
|
|
|
/**
|
|
|
|
* @return the number of elemets the array contains.
|
|
|
|
*/
|
2016-01-06 04:08:45 +03:00
|
|
|
size_type length() const { return mArray.Length(); }
|
2009-07-28 21:21:03 +04:00
|
|
|
|
2009-06-17 23:12:51 +04:00
|
|
|
class iterator {
|
|
|
|
public:
|
|
|
|
iterator(BindingParamsArray* aArray, uint32_t aIndex)
|
|
|
|
: mArray(aArray), mIndex(aIndex) {}
|
|
|
|
|
|
|
|
iterator& operator++(int) {
|
|
|
|
mIndex++;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator==(const iterator& aOther) const {
|
|
|
|
return mIndex == aOther.mIndex;
|
|
|
|
}
|
|
|
|
bool operator!=(const iterator& aOther) const { return !(*this == aOther); }
|
2010-03-24 10:32:40 +03:00
|
|
|
mozIStorageBindingParams* operator*() {
|
2009-07-28 21:21:03 +04:00
|
|
|
NS_ASSERTION(mIndex < mArray->length(),
|
2009-06-17 23:12:51 +04:00
|
|
|
"Dereferenceing an invalid value!");
|
|
|
|
return mArray->mArray[mIndex].get();
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2009-06-17 23:12:51 +04:00
|
|
|
private:
|
|
|
|
void operator--() {}
|
|
|
|
BindingParamsArray* mArray;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mIndex;
|
2009-06-17 23:12:51 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Obtains an iterator pointing to the beginning of the array.
|
|
|
|
*/
|
|
|
|
inline iterator begin() {
|
2009-07-28 21:21:03 +04:00
|
|
|
NS_ASSERTION(length() != 0,
|
|
|
|
"Obtaining an iterator to the beginning with no elements!");
|
2009-06-17 23:12:51 +04:00
|
|
|
return iterator(this, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Obtains an iterator pointing to the end of the array.
|
|
|
|
*/
|
|
|
|
inline iterator end() {
|
2009-07-28 21:21:03 +04:00
|
|
|
NS_ASSERTION(mLocked,
|
|
|
|
"Obtaining an iterator to the end when we are not locked!");
|
|
|
|
return iterator(this, length());
|
2009-06-17 23:12:51 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2009-06-17 23:12:51 +04:00
|
|
|
private:
|
2010-03-24 10:32:40 +03:00
|
|
|
nsCOMPtr<StorageBaseStatementInternal> mOwningStatement;
|
2010-11-09 05:48:59 +03:00
|
|
|
array_type mArray;
|
2009-06-17 23:12:51 +04:00
|
|
|
bool mLocked;
|
|
|
|
|
|
|
|
friend class iterator;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace storage
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2010-06-01 16:38:00 +04:00
|
|
|
#endif // mozStorageBindingParamsArray_h
|