/src/mozilla-central/dom/xslt/base/txExpandedNameMap.h
Line | Count | Source (jump to first uncovered line) |
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 | | |
6 | | #ifndef TRANSFRMX_EXPANDEDNAMEMAP_H |
7 | | #define TRANSFRMX_EXPANDEDNAMEMAP_H |
8 | | |
9 | | #include "nsAutoPtr.h" |
10 | | #include "nsError.h" |
11 | | #include "txExpandedName.h" |
12 | | #include "nsTArray.h" |
13 | | |
14 | | class txExpandedNameMap_base { |
15 | | protected: |
16 | | /** |
17 | | * Adds an item, if an item with this key already exists an error is |
18 | | * returned |
19 | | * @param aKey key for item to add |
20 | | * @param aValue value of item to add |
21 | | * @return errorcode |
22 | | */ |
23 | | nsresult addItem(const txExpandedName& aKey, void* aValue); |
24 | | |
25 | | /** |
26 | | * Sets an item, if an item with this key already exists it is overwritten |
27 | | * with the new value |
28 | | * @param aKey key for item to set |
29 | | * @param aValue value of item to set |
30 | | * @return errorcode |
31 | | */ |
32 | | nsresult setItem(const txExpandedName& aKey, void* aValue, |
33 | | void** aOldValue); |
34 | | |
35 | | /** |
36 | | * Gets an item |
37 | | * @param aKey key for item to get |
38 | | * @return item with specified key, or null if no such item exists |
39 | | */ |
40 | | void* getItem(const txExpandedName& aKey) const; |
41 | | |
42 | | /** |
43 | | * Removes an item, deleting it if the map owns the values |
44 | | * @param aKey key for item to remove |
45 | | * @return item with specified key, or null if it has been deleted |
46 | | * or no such item exists |
47 | | */ |
48 | | void* removeItem(const txExpandedName& aKey); |
49 | | |
50 | | /** |
51 | | * Clears the items |
52 | | */ |
53 | | void clearItems() |
54 | 0 | { |
55 | 0 | mItems.Clear(); |
56 | 0 | } |
57 | | |
58 | | class iterator_base { |
59 | | public: |
60 | | explicit iterator_base(txExpandedNameMap_base& aMap) |
61 | | : mMap(aMap), |
62 | | mCurrentPos(uint32_t(-1)) |
63 | 0 | { |
64 | 0 | } |
65 | | |
66 | | bool next() |
67 | 0 | { |
68 | 0 | return ++mCurrentPos < mMap.mItems.Length(); |
69 | 0 | } |
70 | | |
71 | | const txExpandedName key() |
72 | 0 | { |
73 | 0 | NS_ASSERTION(mCurrentPos < mMap.mItems.Length(), |
74 | 0 | "invalid position in txExpandedNameMap::iterator"); |
75 | 0 | return txExpandedName(mMap.mItems[mCurrentPos].mNamespaceID, |
76 | 0 | mMap.mItems[mCurrentPos].mLocalName); |
77 | 0 | } |
78 | | |
79 | | protected: |
80 | | void* itemValue() |
81 | 0 | { |
82 | 0 | NS_ASSERTION(mCurrentPos < mMap.mItems.Length(), |
83 | 0 | "invalid position in txExpandedNameMap::iterator"); |
84 | 0 | return mMap.mItems[mCurrentPos].mValue; |
85 | 0 | } |
86 | | |
87 | | private: |
88 | | txExpandedNameMap_base& mMap; |
89 | | uint32_t mCurrentPos; |
90 | | }; |
91 | | |
92 | | friend class iterator_base; |
93 | | |
94 | | friend class txMapItemComparator; |
95 | | struct MapItem { |
96 | | int32_t mNamespaceID; |
97 | | RefPtr<nsAtom> mLocalName; |
98 | | void* mValue; |
99 | | }; |
100 | | |
101 | | nsTArray<MapItem> mItems; |
102 | | }; |
103 | | |
104 | | template<class E> |
105 | | class txExpandedNameMap : public txExpandedNameMap_base |
106 | | { |
107 | | public: |
108 | | nsresult add(const txExpandedName& aKey, E* aValue) |
109 | 123 | { |
110 | 123 | return addItem(aKey, (void*)aValue); |
111 | 123 | } Unexecuted instantiation: txExpandedNameMap<txAExprResult>::add(txExpandedName const&, txAExprResult*) Unexecuted instantiation: txExpandedNameMap<txInstruction>::add(txExpandedName const&, txInstruction*) txExpandedNameMap<txElementHandler const>::add(txExpandedName const&, txElementHandler const*) Line | Count | Source | 109 | 123 | { | 110 | 123 | return addItem(aKey, (void*)aValue); | 111 | 123 | } |
|
112 | | |
113 | | nsresult set(const txExpandedName& aKey, E* aValue) |
114 | 0 | { |
115 | 0 | void* oldValue; |
116 | 0 | return setItem(aKey, (void*)aValue, &oldValue); |
117 | 0 | } |
118 | | |
119 | | E* get(const txExpandedName& aKey) const |
120 | 0 | { |
121 | 0 | return (E*)getItem(aKey); |
122 | 0 | } Unexecuted instantiation: txExpandedNameMap<txAExprResult>::get(txExpandedName const&) const Unexecuted instantiation: txExpandedNameMap<txInstruction>::get(txExpandedName const&) const Unexecuted instantiation: txExpandedNameMap<txElementHandler const>::get(txExpandedName const&) const |
123 | | |
124 | | E* remove(const txExpandedName& aKey) |
125 | 0 | { |
126 | 0 | return (E*)removeItem(aKey); |
127 | 0 | } |
128 | | |
129 | | void clear() |
130 | | { |
131 | | clearItems(); |
132 | | } |
133 | | |
134 | | class iterator : public iterator_base |
135 | | { |
136 | | public: |
137 | | explicit iterator(txExpandedNameMap& aMap) |
138 | | : iterator_base(aMap) |
139 | 0 | { |
140 | 0 | } Unexecuted instantiation: txExpandedNameMap<txAExprResult>::iterator::iterator(txExpandedNameMap<txAExprResult>&) Unexecuted instantiation: txExpandedNameMap<txInstruction>::iterator::iterator(txExpandedNameMap<txInstruction>&) |
141 | | |
142 | | E* value() |
143 | 0 | { |
144 | 0 | return (E*)itemValue(); |
145 | 0 | } Unexecuted instantiation: txExpandedNameMap<txAExprResult>::iterator::value() Unexecuted instantiation: txExpandedNameMap<txInstruction>::iterator::value() |
146 | | }; |
147 | | }; |
148 | | |
149 | | template<class E> |
150 | | class txOwningExpandedNameMap : public txExpandedNameMap_base |
151 | | { |
152 | | public: |
153 | | ~txOwningExpandedNameMap() |
154 | 0 | { |
155 | 0 | clear(); |
156 | 0 | } Unexecuted instantiation: txOwningExpandedNameMap<txIGlobalParameter>::~txOwningExpandedNameMap() Unexecuted instantiation: txOwningExpandedNameMap<nsTArray<txStylesheet::MatchableTemplate> >::~txOwningExpandedNameMap() Unexecuted instantiation: txOwningExpandedNameMap<txDecimalFormat>::~txOwningExpandedNameMap() Unexecuted instantiation: txOwningExpandedNameMap<txStylesheet::GlobalVariable>::~txOwningExpandedNameMap() Unexecuted instantiation: txOwningExpandedNameMap<txXSLKey>::~txOwningExpandedNameMap() |
157 | | |
158 | | nsresult add(const txExpandedName& aKey, E* aValue) |
159 | 0 | { |
160 | 0 | return addItem(aKey, (void*)aValue); |
161 | 0 | } Unexecuted instantiation: txOwningExpandedNameMap<txIGlobalParameter>::add(txExpandedName const&, txIGlobalParameter*) Unexecuted instantiation: txOwningExpandedNameMap<txDecimalFormat>::add(txExpandedName const&, txDecimalFormat*) Unexecuted instantiation: txOwningExpandedNameMap<txStylesheet::GlobalVariable>::add(txExpandedName const&, txStylesheet::GlobalVariable*) Unexecuted instantiation: txOwningExpandedNameMap<txXSLKey>::add(txExpandedName const&, txXSLKey*) |
162 | | |
163 | | nsresult set(const txExpandedName& aKey, E* aValue) |
164 | 0 | { |
165 | 0 | nsAutoPtr<E> oldValue; |
166 | 0 | return setItem(aKey, (void*)aValue, getter_Transfers(oldValue)); |
167 | 0 | } |
168 | | |
169 | | E* get(const txExpandedName& aKey) const |
170 | 0 | { |
171 | 0 | return (E*)getItem(aKey); |
172 | 0 | } Unexecuted instantiation: txOwningExpandedNameMap<txIGlobalParameter>::get(txExpandedName const&) const Unexecuted instantiation: txOwningExpandedNameMap<txXSLKey>::get(txExpandedName const&) const Unexecuted instantiation: txOwningExpandedNameMap<nsTArray<txStylesheet::MatchableTemplate> >::get(txExpandedName const&) const Unexecuted instantiation: txOwningExpandedNameMap<txDecimalFormat>::get(txExpandedName const&) const Unexecuted instantiation: txOwningExpandedNameMap<txStylesheet::GlobalVariable>::get(txExpandedName const&) const |
173 | | |
174 | | void remove(const txExpandedName& aKey) |
175 | 0 | { |
176 | 0 | delete (E*)removeItem(aKey); |
177 | 0 | } |
178 | | |
179 | | void clear() |
180 | 0 | { |
181 | 0 | uint32_t i, len = mItems.Length(); |
182 | 0 | for (i = 0; i < len; ++i) { |
183 | 0 | delete (E*)mItems[i].mValue; |
184 | 0 | } |
185 | 0 | clearItems(); |
186 | 0 | } Unexecuted instantiation: txOwningExpandedNameMap<txIGlobalParameter>::clear() Unexecuted instantiation: txOwningExpandedNameMap<nsTArray<txStylesheet::MatchableTemplate> >::clear() Unexecuted instantiation: txOwningExpandedNameMap<txDecimalFormat>::clear() Unexecuted instantiation: txOwningExpandedNameMap<txStylesheet::GlobalVariable>::clear() Unexecuted instantiation: txOwningExpandedNameMap<txXSLKey>::clear() |
187 | | |
188 | | class iterator : public iterator_base |
189 | | { |
190 | | public: |
191 | | explicit iterator(txOwningExpandedNameMap& aMap) |
192 | | : iterator_base(aMap) |
193 | 0 | { |
194 | 0 | } |
195 | | |
196 | | E* value() |
197 | 0 | { |
198 | 0 | return (E*)itemValue(); |
199 | 0 | } |
200 | | }; |
201 | | }; |
202 | | |
203 | | #endif //TRANSFRMX_EXPANDEDNAMEMAP_H |