/src/mozilla-central/dom/base/nsXMLNameSpaceMap.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
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 nsXMLNameSpaceMap_h_ |
8 | | #define nsXMLNameSpaceMap_h_ |
9 | | |
10 | | #include "nsString.h" |
11 | | #include "nsTArray.h" |
12 | | #include "nsCOMPtr.h" |
13 | | #include "nsAtom.h" |
14 | | |
15 | | struct nsNameSpaceEntry |
16 | | { |
17 | | explicit nsNameSpaceEntry(nsAtom* aPrefix) |
18 | 0 | : prefix(aPrefix) {} |
19 | | |
20 | | RefPtr<nsAtom> prefix; |
21 | | MOZ_INIT_OUTSIDE_CTOR int32_t nameSpaceID; |
22 | | }; |
23 | | |
24 | | /** |
25 | | * nsXMLNameSpaceMap contains a set of prefixes which are mapped onto |
26 | | * namespaces. It allows the set to be searched by prefix or by namespace ID. |
27 | | */ |
28 | | class nsXMLNameSpaceMap |
29 | | { |
30 | | public: |
31 | | /** |
32 | | * Allocates a new nsXMLNameSpaceMap (with new()) and if aForXML is |
33 | | * true initializes it with the xmlns and xml namespaces. |
34 | | */ |
35 | | static nsXMLNameSpaceMap* Create(bool aForXML); |
36 | | |
37 | | /** |
38 | | * Add a prefix and its corresponding namespace ID to the map. |
39 | | * Passing a null |aPrefix| corresponds to the default namespace, which may |
40 | | * be set to something other than kNameSpaceID_None. |
41 | | */ |
42 | | nsresult AddPrefix(nsAtom *aPrefix, int32_t aNameSpaceID); |
43 | | |
44 | | /** |
45 | | * Add a prefix and a namespace URI to the map. The URI will be converted |
46 | | * to its corresponding namespace ID. |
47 | | */ |
48 | | nsresult AddPrefix(nsAtom *aPrefix, nsString &aURI); |
49 | | |
50 | | /* |
51 | | * Returns the namespace ID for the given prefix, if it is in the map. |
52 | | * If |aPrefix| is null and is not in the map, then a null namespace |
53 | | * (kNameSpaceID_None) is returned. If |aPrefix| is non-null and is not in |
54 | | * the map, then kNameSpaceID_Unknown is returned. |
55 | | */ |
56 | | int32_t FindNameSpaceID(nsAtom *aPrefix) const; |
57 | | |
58 | | /** |
59 | | * If the given namespace ID is in the map, then the first prefix which |
60 | | * maps to that namespace is returned. Otherwise, null is returned. |
61 | | */ |
62 | | nsAtom* FindPrefix(int32_t aNameSpaceID) const; |
63 | | |
64 | | /* Removes all prefix mappings. */ |
65 | | void Clear(); |
66 | | |
67 | 0 | ~nsXMLNameSpaceMap() { Clear(); } |
68 | | |
69 | | private: |
70 | | nsXMLNameSpaceMap(); // use Create() to create new instances |
71 | | |
72 | | nsTArray<nsNameSpaceEntry> mNameSpaces; |
73 | | }; |
74 | | |
75 | | #endif |