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