Bumping manifests a=b2g-bump
[gecko.git] / dom / quota / ArrayCluster.h
blob7c72fb5dc1dbb9269d01ccf3a6fcb6148bc0ca69
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=2 et sw=2 tw=80: */
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 file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_quota_arraycluster_h__
8 #define mozilla_dom_quota_arraycluster_h__
10 #include "mozilla/dom/quota/QuotaCommon.h"
12 #include "Client.h"
14 BEGIN_QUOTA_NAMESPACE
16 template <class ValueType, uint32_t Length = Client::TYPE_MAX>
17 class ArrayCluster
19 public:
20 ArrayCluster()
22 mArrays.AppendElements(Length);
25 nsTArray<ValueType>&
26 ArrayAt(uint32_t aIndex)
28 MOZ_ASSERT(aIndex < Length, "Bad index!");
29 return mArrays[aIndex];
32 nsTArray<ValueType>&
33 operator[](uint32_t aIndex)
35 return ArrayAt(aIndex);
38 bool
39 IsEmpty()
41 for (uint32_t index = 0; index < Length; index++) {
42 if (!mArrays[index].IsEmpty()) {
43 return false;
46 return true;
49 template <class T>
50 void
51 AppendElementsTo(uint32_t aIndex, nsTArray<T>& aArray)
53 NS_ASSERTION(aIndex < Length, "Bad index!");
54 aArray.AppendElements(mArrays[aIndex]);
57 template <class T>
58 void
59 AppendElementsTo(uint32_t aIndex, ArrayCluster<T, Length>& aArrayCluster)
61 NS_ASSERTION(aIndex < Length, "Bad index!");
62 aArrayCluster[aIndex].AppendElements(mArrays[aIndex]);
65 template <class T>
66 void
67 AppendElementsTo(nsTArray<T>& aArray)
69 for (uint32_t index = 0; index < Length; index++) {
70 aArray.AppendElements(mArrays[index]);
74 template<class T>
75 void
76 AppendElementsTo(ArrayCluster<T, Length>& aArrayCluster)
78 for (uint32_t index = 0; index < Length; index++) {
79 aArrayCluster[index].AppendElements(mArrays[index]);
83 template<class T>
84 void
85 SwapElements(ArrayCluster<T, Length>& aArrayCluster)
87 for (uint32_t index = 0; index < Length; index++) {
88 mArrays[index].SwapElements(aArrayCluster.mArrays[index]);
92 void
93 Clear()
95 for (uint32_t index = 0; index < Length; index++) {
96 mArrays[index].Clear();
100 private:
101 nsAutoTArray<nsTArray<ValueType>, Length> mArrays;
104 END_QUOTA_NAMESPACE
106 #endif // mozilla_dom_quota_arraycluster_h__