1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/storage/src/mozStorageBindingParamsArray.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,114 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- 1.5 + * vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ : 1.6 + * This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef mozStorageBindingParamsArray_h 1.11 +#define mozStorageBindingParamsArray_h 1.12 + 1.13 +#include "nsAutoPtr.h" 1.14 +#include "nsTArray.h" 1.15 +#include "mozilla/Attributes.h" 1.16 + 1.17 +#include "mozIStorageBindingParamsArray.h" 1.18 + 1.19 +namespace mozilla { 1.20 +namespace storage { 1.21 + 1.22 +class StorageBaseStatementInternal; 1.23 + 1.24 +class BindingParamsArray MOZ_FINAL : public mozIStorageBindingParamsArray 1.25 +{ 1.26 + typedef nsTArray< nsCOMPtr<mozIStorageBindingParams> > array_type; 1.27 + 1.28 +public: 1.29 + NS_DECL_THREADSAFE_ISUPPORTS 1.30 + NS_DECL_MOZISTORAGEBINDINGPARAMSARRAY 1.31 + 1.32 + BindingParamsArray(StorageBaseStatementInternal *aOwningStatement); 1.33 + 1.34 + typedef array_type::size_type size_type; 1.35 + 1.36 + /** 1.37 + * Locks the array and prevents further modification to it (such as adding 1.38 + * more elements to it). 1.39 + */ 1.40 + void lock(); 1.41 + 1.42 + /** 1.43 + * @return the pointer to the owning BindingParamsArray. 1.44 + */ 1.45 + const StorageBaseStatementInternal *getOwner() const; 1.46 + 1.47 + /** 1.48 + * @return the number of elemets the array contains. 1.49 + */ 1.50 + const size_type length() const { return mArray.Length(); } 1.51 + 1.52 + class iterator { 1.53 + public: 1.54 + iterator(BindingParamsArray *aArray, 1.55 + uint32_t aIndex) 1.56 + : mArray(aArray) 1.57 + , mIndex(aIndex) 1.58 + { 1.59 + } 1.60 + 1.61 + iterator &operator++(int) 1.62 + { 1.63 + mIndex++; 1.64 + return *this; 1.65 + } 1.66 + 1.67 + bool operator==(const iterator &aOther) const 1.68 + { 1.69 + return mIndex == aOther.mIndex; 1.70 + } 1.71 + bool operator!=(const iterator &aOther) const 1.72 + { 1.73 + return !(*this == aOther); 1.74 + } 1.75 + mozIStorageBindingParams *operator*() 1.76 + { 1.77 + NS_ASSERTION(mIndex < mArray->length(), 1.78 + "Dereferenceing an invalid value!"); 1.79 + return mArray->mArray[mIndex].get(); 1.80 + } 1.81 + private: 1.82 + void operator--() { } 1.83 + BindingParamsArray *mArray; 1.84 + uint32_t mIndex; 1.85 + }; 1.86 + 1.87 + /** 1.88 + * Obtains an iterator pointing to the beginning of the array. 1.89 + */ 1.90 + inline iterator begin() 1.91 + { 1.92 + NS_ASSERTION(length() != 0, 1.93 + "Obtaining an iterator to the beginning with no elements!"); 1.94 + return iterator(this, 0); 1.95 + } 1.96 + 1.97 + /** 1.98 + * Obtains an iterator pointing to the end of the array. 1.99 + */ 1.100 + inline iterator end() 1.101 + { 1.102 + NS_ASSERTION(mLocked, 1.103 + "Obtaining an iterator to the end when we are not locked!"); 1.104 + return iterator(this, length()); 1.105 + } 1.106 +private: 1.107 + nsCOMPtr<StorageBaseStatementInternal> mOwningStatement; 1.108 + array_type mArray; 1.109 + bool mLocked; 1.110 + 1.111 + friend class iterator; 1.112 +}; 1.113 + 1.114 +} // namespace storage 1.115 +} // namespace mozilla 1.116 + 1.117 +#endif // mozStorageBindingParamsArray_h