tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

mozStorageBindingParamsArray.h (2727B)


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