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 7 #ifndef nsNameSpaceMap_h__ 8 #define nsNameSpaceMap_h__ 9 10 #include "nsCOMPtr.h" 11 #include "nsString.h" 12 #include "nsAtom.h" 13 14 class nsNameSpaceMap { 15 public: 16 class Entry { 17 public: Entry(const nsACString & aURI,nsAtom * aPrefix)18 Entry(const nsACString& aURI, nsAtom* aPrefix) 19 : mURI(aURI), mPrefix(aPrefix), mNext(nullptr) { 20 MOZ_COUNT_CTOR(nsNameSpaceMap::Entry); 21 } 22 ~Entry()23 ~Entry() { MOZ_COUNT_DTOR(nsNameSpaceMap::Entry); } 24 25 nsCString mURI; 26 RefPtr<nsAtom> mPrefix; 27 28 Entry* mNext; 29 }; 30 31 nsNameSpaceMap(); 32 ~nsNameSpaceMap(); 33 34 nsresult Put(const nsAString& aURI, nsAtom* aPrefix); 35 36 nsresult Put(const nsACString& aURI, nsAtom* aPrefix); 37 38 class const_iterator { 39 protected: 40 friend class nsNameSpaceMap; 41 const_iterator(const Entry * aCurrent)42 explicit const_iterator(const Entry* aCurrent) : mCurrent(aCurrent) {} 43 44 const Entry* mCurrent; 45 46 public: const_iterator()47 const_iterator() : mCurrent(nullptr) {} 48 const_iterator(const const_iterator & iter)49 const_iterator(const const_iterator& iter) : mCurrent(iter.mCurrent) {} 50 51 const_iterator& operator=(const const_iterator& iter) { 52 mCurrent = iter.mCurrent; 53 return *this; 54 } 55 56 const_iterator& operator++() { 57 mCurrent = mCurrent->mNext; 58 return *this; 59 } 60 61 const_iterator operator++(int) { 62 const_iterator tmp(*this); 63 mCurrent = mCurrent->mNext; 64 return tmp; 65 } 66 67 const Entry* operator->() const { return mCurrent; } 68 69 const Entry& operator*() const { return *mCurrent; } 70 71 bool operator==(const const_iterator& iter) const { 72 return mCurrent == iter.mCurrent; 73 } 74 75 bool operator!=(const const_iterator& iter) const { 76 return !iter.operator==(*this); 77 } 78 }; 79 first()80 const_iterator first() const { return const_iterator(mEntries); } 81 last()82 const_iterator last() const { return const_iterator(nullptr); } 83 84 const_iterator GetNameSpaceOf(const nsACString& aURI) const; 85 86 protected: 87 Entry* mEntries; 88 }; 89 90 #endif // nsNameSpaceMap_h__ 91