michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set ts=2 et sw=2 tw=80: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_dom_quota_arraycluster_h__ michael@0: #define mozilla_dom_quota_arraycluster_h__ michael@0: michael@0: #include "mozilla/dom/quota/QuotaCommon.h" michael@0: michael@0: #include "Client.h" michael@0: michael@0: BEGIN_QUOTA_NAMESPACE michael@0: michael@0: template michael@0: class ArrayCluster michael@0: { michael@0: public: michael@0: ArrayCluster() michael@0: { michael@0: mArrays.AppendElements(Length); michael@0: } michael@0: michael@0: nsTArray& michael@0: ArrayAt(uint32_t aIndex) michael@0: { michael@0: MOZ_ASSERT(aIndex < Length, "Bad index!"); michael@0: return mArrays[aIndex]; michael@0: } michael@0: michael@0: nsTArray& michael@0: operator[](uint32_t aIndex) michael@0: { michael@0: return ArrayAt(aIndex); michael@0: } michael@0: michael@0: bool michael@0: IsEmpty() michael@0: { michael@0: for (uint32_t index = 0; index < Length; index++) { michael@0: if (!mArrays[index].IsEmpty()) { michael@0: return false; michael@0: } michael@0: } michael@0: return true; michael@0: } michael@0: michael@0: template michael@0: void michael@0: AppendElementsTo(uint32_t aIndex, nsTArray& aArray) michael@0: { michael@0: NS_ASSERTION(aIndex < Length, "Bad index!"); michael@0: aArray.AppendElements(mArrays[aIndex]); michael@0: } michael@0: michael@0: template michael@0: void michael@0: AppendElementsTo(uint32_t aIndex, ArrayCluster& aArrayCluster) michael@0: { michael@0: NS_ASSERTION(aIndex < Length, "Bad index!"); michael@0: aArrayCluster[aIndex].AppendElements(mArrays[aIndex]); michael@0: } michael@0: michael@0: template michael@0: void michael@0: AppendElementsTo(nsTArray& aArray) michael@0: { michael@0: for (uint32_t index = 0; index < Length; index++) { michael@0: aArray.AppendElements(mArrays[index]); michael@0: } michael@0: } michael@0: michael@0: template michael@0: void michael@0: AppendElementsTo(ArrayCluster& aArrayCluster) michael@0: { michael@0: for (uint32_t index = 0; index < Length; index++) { michael@0: aArrayCluster[index].AppendElements(mArrays[index]); michael@0: } michael@0: } michael@0: michael@0: template michael@0: void michael@0: SwapElements(ArrayCluster& aArrayCluster) michael@0: { michael@0: for (uint32_t index = 0; index < Length; index++) { michael@0: mArrays[index].SwapElements(aArrayCluster.mArrays[index]); michael@0: } michael@0: } michael@0: michael@0: void michael@0: Clear() michael@0: { michael@0: for (uint32_t index = 0; index < Length; index++) { michael@0: mArrays[index].Clear(); michael@0: } michael@0: } michael@0: michael@0: private: michael@0: nsAutoTArray, Length> mArrays; michael@0: }; michael@0: michael@0: END_QUOTA_NAMESPACE michael@0: michael@0: #endif // mozilla_dom_quota_arraycluster_h__