nsResourceSet.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef nsResourceSet_h__
  6. #define nsResourceSet_h__
  7. #include "nsIRDFResource.h"
  8. class nsResourceSet
  9. {
  10. public:
  11. nsResourceSet()
  12. : mResources(nullptr),
  13. mCount(0),
  14. mCapacity(0) {
  15. MOZ_COUNT_CTOR(nsResourceSet); }
  16. nsResourceSet(const nsResourceSet& aResourceSet);
  17. nsResourceSet& operator=(const nsResourceSet& aResourceSet);
  18. ~nsResourceSet();
  19. nsresult Clear();
  20. nsresult Add(nsIRDFResource* aProperty);
  21. void Remove(nsIRDFResource* aProperty);
  22. bool Contains(nsIRDFResource* aProperty) const;
  23. protected:
  24. nsIRDFResource** mResources;
  25. int32_t mCount;
  26. int32_t mCapacity;
  27. public:
  28. class ConstIterator {
  29. protected:
  30. nsIRDFResource** mCurrent;
  31. public:
  32. ConstIterator() : mCurrent(nullptr) {}
  33. ConstIterator(const ConstIterator& aConstIterator)
  34. : mCurrent(aConstIterator.mCurrent) {}
  35. ConstIterator& operator=(const ConstIterator& aConstIterator) {
  36. mCurrent = aConstIterator.mCurrent;
  37. return *this; }
  38. ConstIterator& operator++() {
  39. ++mCurrent;
  40. return *this; }
  41. ConstIterator operator++(int) {
  42. ConstIterator result(*this);
  43. ++mCurrent;
  44. return result; }
  45. /*const*/ nsIRDFResource* operator*() const {
  46. return *mCurrent; }
  47. /*const*/ nsIRDFResource* operator->() const MOZ_NO_ADDREF_RELEASE_ON_RETURN {
  48. return *mCurrent; }
  49. bool operator==(const ConstIterator& aConstIterator) const {
  50. return mCurrent == aConstIterator.mCurrent; }
  51. bool operator!=(const ConstIterator& aConstIterator) const {
  52. return mCurrent != aConstIterator.mCurrent; }
  53. protected:
  54. explicit ConstIterator(nsIRDFResource** aProperty) : mCurrent(aProperty) {}
  55. friend class nsResourceSet;
  56. };
  57. ConstIterator First() const { return ConstIterator(mResources); }
  58. ConstIterator Last() const { return ConstIterator(mResources + mCount); }
  59. };
  60. #endif // nsResourceSet_h__