Thu, 15 Jan 2015 15:55:04 +0100
Back out 97036ab72558 which inappropriately compared turds to third parties.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #ifndef nsXMLNameSpaceMap_h_ |
michael@0 | 7 | #define nsXMLNameSpaceMap_h_ |
michael@0 | 8 | |
michael@0 | 9 | #include "nsString.h" |
michael@0 | 10 | #include "nsTArray.h" |
michael@0 | 11 | #include "nsCOMPtr.h" |
michael@0 | 12 | #include "nsIAtom.h" |
michael@0 | 13 | |
michael@0 | 14 | struct nsNameSpaceEntry |
michael@0 | 15 | { |
michael@0 | 16 | nsNameSpaceEntry(nsIAtom *aPrefix) |
michael@0 | 17 | : prefix(aPrefix) {} |
michael@0 | 18 | |
michael@0 | 19 | nsCOMPtr<nsIAtom> prefix; |
michael@0 | 20 | int32_t nameSpaceID; |
michael@0 | 21 | }; |
michael@0 | 22 | |
michael@0 | 23 | /** |
michael@0 | 24 | * nsXMLNameSpaceMap contains a set of prefixes which are mapped onto |
michael@0 | 25 | * namespaces. It allows the set to be searched by prefix or by namespace ID. |
michael@0 | 26 | */ |
michael@0 | 27 | class nsXMLNameSpaceMap |
michael@0 | 28 | { |
michael@0 | 29 | public: |
michael@0 | 30 | /** |
michael@0 | 31 | * Allocates a new nsXMLNameSpaceMap (with new()) and if aForXML is |
michael@0 | 32 | * true initializes it with the xmlns and xml namespaces. |
michael@0 | 33 | */ |
michael@0 | 34 | static NS_HIDDEN_(nsXMLNameSpaceMap*) Create(bool aForXML); |
michael@0 | 35 | |
michael@0 | 36 | /** |
michael@0 | 37 | * Add a prefix and its corresponding namespace ID to the map. |
michael@0 | 38 | * Passing a null |aPrefix| corresponds to the default namespace, which may |
michael@0 | 39 | * be set to something other than kNameSpaceID_None. |
michael@0 | 40 | */ |
michael@0 | 41 | NS_HIDDEN_(nsresult) AddPrefix(nsIAtom *aPrefix, int32_t aNameSpaceID); |
michael@0 | 42 | |
michael@0 | 43 | /** |
michael@0 | 44 | * Add a prefix and a namespace URI to the map. The URI will be converted |
michael@0 | 45 | * to its corresponding namespace ID. |
michael@0 | 46 | */ |
michael@0 | 47 | NS_HIDDEN_(nsresult) AddPrefix(nsIAtom *aPrefix, nsString &aURI); |
michael@0 | 48 | |
michael@0 | 49 | /* |
michael@0 | 50 | * Returns the namespace ID for the given prefix, if it is in the map. |
michael@0 | 51 | * If |aPrefix| is null and is not in the map, then a null namespace |
michael@0 | 52 | * (kNameSpaceID_None) is returned. If |aPrefix| is non-null and is not in |
michael@0 | 53 | * the map, then kNameSpaceID_Unknown is returned. |
michael@0 | 54 | */ |
michael@0 | 55 | NS_HIDDEN_(int32_t) FindNameSpaceID(nsIAtom *aPrefix) const; |
michael@0 | 56 | |
michael@0 | 57 | /** |
michael@0 | 58 | * If the given namespace ID is in the map, then the first prefix which |
michael@0 | 59 | * maps to that namespace is returned. Otherwise, null is returned. |
michael@0 | 60 | */ |
michael@0 | 61 | NS_HIDDEN_(nsIAtom*) FindPrefix(int32_t aNameSpaceID) const; |
michael@0 | 62 | |
michael@0 | 63 | /* Removes all prefix mappings. */ |
michael@0 | 64 | NS_HIDDEN_(void) Clear(); |
michael@0 | 65 | |
michael@0 | 66 | ~nsXMLNameSpaceMap() { Clear(); } |
michael@0 | 67 | |
michael@0 | 68 | private: |
michael@0 | 69 | nsXMLNameSpaceMap() NS_HIDDEN; // use Create() to create new instances |
michael@0 | 70 | |
michael@0 | 71 | nsTArray<nsNameSpaceEntry> mNameSpaces; |
michael@0 | 72 | }; |
michael@0 | 73 | |
michael@0 | 74 | #endif |