nsNameSpaceMap.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  2. *
  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
  5. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  6. #ifndef nsNameSpaceMap_h__
  7. #define nsNameSpaceMap_h__
  8. #include "nsCOMPtr.h"
  9. #include "nsString.h"
  10. #include "nsIAtom.h"
  11. class nsNameSpaceMap
  12. {
  13. public:
  14. class Entry {
  15. public:
  16. Entry(const nsCSubstring& aURI, nsIAtom* aPrefix)
  17. : mURI(aURI), mPrefix(aPrefix), mNext(nullptr) {
  18. MOZ_COUNT_CTOR(nsNameSpaceMap::Entry); }
  19. ~Entry() { MOZ_COUNT_DTOR(nsNameSpaceMap::Entry); }
  20. nsCString mURI;
  21. nsCOMPtr<nsIAtom> mPrefix;
  22. Entry* mNext;
  23. };
  24. nsNameSpaceMap();
  25. ~nsNameSpaceMap();
  26. nsresult
  27. Put(const nsAString& aURI, nsIAtom* aPrefix);
  28. nsresult
  29. Put(const nsCSubstring& aURI, nsIAtom* aPrefix);
  30. class const_iterator {
  31. protected:
  32. friend class nsNameSpaceMap;
  33. explicit const_iterator(const Entry* aCurrent)
  34. : mCurrent(aCurrent) {}
  35. const Entry* mCurrent;
  36. public:
  37. const_iterator()
  38. : mCurrent(nullptr) {}
  39. const_iterator(const const_iterator& iter)
  40. : mCurrent(iter.mCurrent) {}
  41. const_iterator&
  42. operator=(const const_iterator& iter) {
  43. mCurrent = iter.mCurrent;
  44. return *this; }
  45. const_iterator&
  46. operator++() {
  47. mCurrent = mCurrent->mNext;
  48. return *this; }
  49. const_iterator
  50. operator++(int) {
  51. const_iterator tmp(*this);
  52. mCurrent = mCurrent->mNext;
  53. return tmp; }
  54. const Entry* operator->() const { return mCurrent; }
  55. const Entry& operator*() const { return *mCurrent; }
  56. bool
  57. operator==(const const_iterator& iter) const {
  58. return mCurrent == iter.mCurrent; }
  59. bool
  60. operator!=(const const_iterator& iter) const {
  61. return ! iter.operator==(*this); }
  62. };
  63. const_iterator first() const {
  64. return const_iterator(mEntries); }
  65. const_iterator last() const {
  66. return const_iterator(nullptr); }
  67. const_iterator GetNameSpaceOf(const nsCSubstring& aURI) const;
  68. protected:
  69. Entry* mEntries;
  70. };
  71. #endif // nsNameSpaceMap_h__