michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 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 michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: #ifndef nsResourceSet_h__ michael@0: #define nsResourceSet_h__ michael@0: michael@0: #include "nsIRDFResource.h" michael@0: michael@0: class nsResourceSet michael@0: { michael@0: public: michael@0: nsResourceSet() michael@0: : mResources(nullptr), michael@0: mCount(0), michael@0: mCapacity(0) { michael@0: MOZ_COUNT_CTOR(nsResourceSet); } michael@0: michael@0: nsResourceSet(const nsResourceSet& aResourceSet); michael@0: michael@0: nsResourceSet& operator=(const nsResourceSet& aResourceSet); michael@0: michael@0: ~nsResourceSet(); michael@0: michael@0: nsresult Clear(); michael@0: nsresult Add(nsIRDFResource* aProperty); michael@0: void Remove(nsIRDFResource* aProperty); michael@0: michael@0: bool Contains(nsIRDFResource* aProperty) const; michael@0: michael@0: protected: michael@0: nsIRDFResource** mResources; michael@0: int32_t mCount; michael@0: int32_t mCapacity; michael@0: michael@0: public: michael@0: class ConstIterator { michael@0: protected: michael@0: nsIRDFResource** mCurrent; michael@0: michael@0: public: michael@0: ConstIterator() : mCurrent(nullptr) {} michael@0: michael@0: ConstIterator(const ConstIterator& aConstIterator) michael@0: : mCurrent(aConstIterator.mCurrent) {} michael@0: michael@0: ConstIterator& operator=(const ConstIterator& aConstIterator) { michael@0: mCurrent = aConstIterator.mCurrent; michael@0: return *this; } michael@0: michael@0: ConstIterator& operator++() { michael@0: ++mCurrent; michael@0: return *this; } michael@0: michael@0: ConstIterator operator++(int) { michael@0: ConstIterator result(*this); michael@0: ++mCurrent; michael@0: return result; } michael@0: michael@0: /*const*/ nsIRDFResource* operator*() const { michael@0: return *mCurrent; } michael@0: michael@0: /*const*/ nsIRDFResource* operator->() const { michael@0: return *mCurrent; } michael@0: michael@0: bool operator==(const ConstIterator& aConstIterator) const { michael@0: return mCurrent == aConstIterator.mCurrent; } michael@0: michael@0: bool operator!=(const ConstIterator& aConstIterator) const { michael@0: return mCurrent != aConstIterator.mCurrent; } michael@0: michael@0: protected: michael@0: ConstIterator(nsIRDFResource** aProperty) : mCurrent(aProperty) {} michael@0: friend class nsResourceSet; michael@0: }; michael@0: michael@0: ConstIterator First() const { return ConstIterator(mResources); } michael@0: ConstIterator Last() const { return ConstIterator(mResources + mCount); } michael@0: }; michael@0: michael@0: #endif // nsResourceSet_h__ michael@0: