dom/quota/ArrayCluster.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/quota/ArrayCluster.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,106 @@
     1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* vim: set ts=2 et sw=2 tw=80: */
     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 file,
     1.8 + * You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#ifndef mozilla_dom_quota_arraycluster_h__
    1.11 +#define mozilla_dom_quota_arraycluster_h__
    1.12 +
    1.13 +#include "mozilla/dom/quota/QuotaCommon.h"
    1.14 +
    1.15 +#include "Client.h"
    1.16 +
    1.17 +BEGIN_QUOTA_NAMESPACE
    1.18 +
    1.19 +template <class ValueType, uint32_t Length = Client::TYPE_MAX>
    1.20 +class ArrayCluster
    1.21 +{
    1.22 +public:
    1.23 +  ArrayCluster()
    1.24 +  {
    1.25 +    mArrays.AppendElements(Length);
    1.26 +  }
    1.27 +
    1.28 +  nsTArray<ValueType>&
    1.29 +  ArrayAt(uint32_t aIndex)
    1.30 +  {
    1.31 +    MOZ_ASSERT(aIndex < Length, "Bad index!");
    1.32 +    return mArrays[aIndex];
    1.33 +  }
    1.34 +
    1.35 +  nsTArray<ValueType>&
    1.36 +  operator[](uint32_t aIndex)
    1.37 +  {
    1.38 +    return ArrayAt(aIndex);
    1.39 +  }
    1.40 +
    1.41 +  bool
    1.42 +  IsEmpty()
    1.43 +  {
    1.44 +    for (uint32_t index = 0; index < Length; index++) {
    1.45 +      if (!mArrays[index].IsEmpty()) {
    1.46 +        return false;
    1.47 +      }
    1.48 +    }
    1.49 +    return true;
    1.50 +  }
    1.51 +
    1.52 +  template <class T>
    1.53 +  void
    1.54 +  AppendElementsTo(uint32_t aIndex, nsTArray<T>& aArray)
    1.55 +  {
    1.56 +    NS_ASSERTION(aIndex < Length, "Bad index!");
    1.57 +    aArray.AppendElements(mArrays[aIndex]);
    1.58 +  }
    1.59 +
    1.60 +  template <class T>
    1.61 +  void
    1.62 +  AppendElementsTo(uint32_t aIndex, ArrayCluster<T, Length>& aArrayCluster)
    1.63 +  {
    1.64 +    NS_ASSERTION(aIndex < Length, "Bad index!");
    1.65 +    aArrayCluster[aIndex].AppendElements(mArrays[aIndex]);
    1.66 +  }
    1.67 +
    1.68 +  template <class T>
    1.69 +  void
    1.70 +  AppendElementsTo(nsTArray<T>& aArray)
    1.71 +  {
    1.72 +    for (uint32_t index = 0; index < Length; index++) {
    1.73 +      aArray.AppendElements(mArrays[index]);
    1.74 +    }
    1.75 +  }
    1.76 +
    1.77 +  template<class T>
    1.78 +  void
    1.79 +  AppendElementsTo(ArrayCluster<T, Length>& aArrayCluster)
    1.80 +  {
    1.81 +    for (uint32_t index = 0; index < Length; index++) {
    1.82 +      aArrayCluster[index].AppendElements(mArrays[index]);
    1.83 +    }
    1.84 +  }
    1.85 +
    1.86 +  template<class T>
    1.87 +  void
    1.88 +  SwapElements(ArrayCluster<T, Length>& aArrayCluster)
    1.89 +  {
    1.90 +    for (uint32_t index = 0; index < Length; index++) {
    1.91 +      mArrays[index].SwapElements(aArrayCluster.mArrays[index]);
    1.92 +    }
    1.93 +  }
    1.94 +
    1.95 +  void
    1.96 +  Clear()
    1.97 +  {
    1.98 +    for (uint32_t index = 0; index < Length; index++) {
    1.99 +      mArrays[index].Clear();
   1.100 +    }
   1.101 +  }
   1.102 +
   1.103 +private:
   1.104 +  nsAutoTArray<nsTArray<ValueType>, Length> mArrays;
   1.105 +};
   1.106 +
   1.107 +END_QUOTA_NAMESPACE
   1.108 +
   1.109 +#endif // mozilla_dom_quota_arraycluster_h__

mercurial