2009-06-17 19:12:51 +00: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 11:12:37 +00: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 19:12:51 +00:00
|
|
|
|
2010-06-01 12:38:00 +00:00
|
|
|
#ifndef mozStorageBindingParamsArray_h
|
|
|
|
#define mozStorageBindingParamsArray_h
|
2009-06-17 19:12:51 +00:00
|
|
|
|
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsTArray.h"
|
2012-06-13 03:35:10 +00:00
|
|
|
#include "mozilla/Attributes.h"
|
2009-06-17 19:12:51 +00:00
|
|
|
|
|
|
|
#include "mozIStorageBindingParamsArray.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace storage {
|
|
|
|
|
2010-03-24 07:32:40 +00:00
|
|
|
class StorageBaseStatementInternal;
|
2009-06-17 19:12:51 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
class BindingParamsArray final : public mozIStorageBindingParamsArray
|
2009-06-17 19:12:51 +00:00
|
|
|
{
|
2010-11-09 02:48:59 +00:00
|
|
|
typedef nsTArray< nsCOMPtr<mozIStorageBindingParams> > array_type;
|
|
|
|
|
2014-06-23 22:40:03 +00:00
|
|
|
~BindingParamsArray() {}
|
|
|
|
|
2009-06-17 19:12:51 +00:00
|
|
|
public:
|
2013-07-19 02:24:15 +00:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2009-06-17 19:12:51 +00:00
|
|
|
NS_DECL_MOZISTORAGEBINDINGPARAMSARRAY
|
|
|
|
|
2014-08-07 23:47:28 +00:00
|
|
|
explicit BindingParamsArray(StorageBaseStatementInternal *aOwningStatement);
|
2009-06-17 19:12:51 +00:00
|
|
|
|
2010-11-09 02:48:59 +00:00
|
|
|
typedef array_type::size_type size_type;
|
2009-07-28 17:21:03 +00:00
|
|
|
|
2009-06-17 19:12:51 +00:00
|
|
|
/**
|
|
|
|
* Locks the array and prevents further modification to it (such as adding
|
|
|
|
* more elements to it).
|
|
|
|
*/
|
|
|
|
void lock();
|
|
|
|
|
|
|
|
/**
|
2009-07-28 17:21:03 +00:00
|
|
|
* @return the pointer to the owning BindingParamsArray.
|
2009-06-17 19:12:51 +00:00
|
|
|
*/
|
2010-03-24 07:32:40 +00:00
|
|
|
const StorageBaseStatementInternal *getOwner() const;
|
2009-06-17 19:12:51 +00:00
|
|
|
|
2009-07-28 17:21:03 +00:00
|
|
|
/**
|
|
|
|
* @return the number of elemets the array contains.
|
|
|
|
*/
|
2016-01-06 01:08:45 +00:00
|
|
|
size_type length() const { return mArray.Length(); }
|
2009-07-28 17:21:03 +00:00
|
|
|
|
2009-06-17 19:12:51 +00:00
|
|
|
class iterator {
|
|
|
|
public:
|
|
|
|
iterator(BindingParamsArray *aArray,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t aIndex)
|
2009-06-17 19:12:51 +00:00
|
|
|
: 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 07:32:40 +00:00
|
|
|
mozIStorageBindingParams *operator*()
|
2009-06-17 19:12:51 +00:00
|
|
|
{
|
2009-07-28 17:21:03 +00:00
|
|
|
NS_ASSERTION(mIndex < mArray->length(),
|
2009-06-17 19:12:51 +00:00
|
|
|
"Dereferenceing an invalid value!");
|
|
|
|
return mArray->mArray[mIndex].get();
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
void operator--() { }
|
|
|
|
BindingParamsArray *mArray;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t mIndex;
|
2009-06-17 19:12:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Obtains an iterator pointing to the beginning of the array.
|
|
|
|
*/
|
|
|
|
inline iterator begin()
|
|
|
|
{
|
2009-07-28 17:21:03 +00:00
|
|
|
NS_ASSERTION(length() != 0,
|
|
|
|
"Obtaining an iterator to the beginning with no elements!");
|
2009-06-17 19:12:51 +00:00
|
|
|
return iterator(this, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Obtains an iterator pointing to the end of the array.
|
|
|
|
*/
|
|
|
|
inline iterator end()
|
|
|
|
{
|
2009-07-28 17:21:03 +00:00
|
|
|
NS_ASSERTION(mLocked,
|
|
|
|
"Obtaining an iterator to the end when we are not locked!");
|
|
|
|
return iterator(this, length());
|
2009-06-17 19:12:51 +00:00
|
|
|
}
|
|
|
|
private:
|
2010-03-24 07:32:40 +00:00
|
|
|
nsCOMPtr<StorageBaseStatementInternal> mOwningStatement;
|
2010-11-09 02:48:59 +00:00
|
|
|
array_type mArray;
|
2009-06-17 19:12:51 +00:00
|
|
|
bool mLocked;
|
|
|
|
|
|
|
|
friend class iterator;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace storage
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2010-06-01 12:38:00 +00:00
|
|
|
#endif // mozStorageBindingParamsArray_h
|