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 nsNameSpaceManager_h___ |
michael@0 | 7 | #define nsNameSpaceManager_h___ |
michael@0 | 8 | |
michael@0 | 9 | #include "nsDataHashtable.h" |
michael@0 | 10 | #include "nsTArray.h" |
michael@0 | 11 | |
michael@0 | 12 | #include "mozilla/StaticPtr.h" |
michael@0 | 13 | |
michael@0 | 14 | class nsIAtom; |
michael@0 | 15 | class nsAString; |
michael@0 | 16 | |
michael@0 | 17 | #define kNameSpaceID_Unknown -1 |
michael@0 | 18 | // 0 is special at C++, so use a static const int32_t for |
michael@0 | 19 | // kNameSpaceID_None to keep if from being cast to pointers |
michael@0 | 20 | // Note that the XBL cache assumes (and asserts) that it can treat a |
michael@0 | 21 | // single-byte value higher than kNameSpaceID_LastBuiltin specially. |
michael@0 | 22 | static const int32_t kNameSpaceID_None = 0; |
michael@0 | 23 | #define kNameSpaceID_XMLNS 1 // not really a namespace, but it needs to play the game |
michael@0 | 24 | #define kNameSpaceID_XML 2 |
michael@0 | 25 | #define kNameSpaceID_XHTML 3 |
michael@0 | 26 | #define kNameSpaceID_XLink 4 |
michael@0 | 27 | #define kNameSpaceID_XSLT 5 |
michael@0 | 28 | #define kNameSpaceID_XBL 6 |
michael@0 | 29 | #define kNameSpaceID_MathML 7 |
michael@0 | 30 | #define kNameSpaceID_RDF 8 |
michael@0 | 31 | #define kNameSpaceID_XUL 9 |
michael@0 | 32 | #define kNameSpaceID_SVG 10 |
michael@0 | 33 | #define kNameSpaceID_LastBuiltin 10 // last 'built-in' namespace |
michael@0 | 34 | |
michael@0 | 35 | class nsNameSpaceKey : public PLDHashEntryHdr |
michael@0 | 36 | { |
michael@0 | 37 | public: |
michael@0 | 38 | typedef const nsAString* KeyType; |
michael@0 | 39 | typedef const nsAString* KeyTypePointer; |
michael@0 | 40 | |
michael@0 | 41 | nsNameSpaceKey(KeyTypePointer aKey) : mKey(aKey) |
michael@0 | 42 | { |
michael@0 | 43 | } |
michael@0 | 44 | nsNameSpaceKey(const nsNameSpaceKey& toCopy) : mKey(toCopy.mKey) |
michael@0 | 45 | { |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | KeyType GetKey() const |
michael@0 | 49 | { |
michael@0 | 50 | return mKey; |
michael@0 | 51 | } |
michael@0 | 52 | bool KeyEquals(KeyType aKey) const |
michael@0 | 53 | { |
michael@0 | 54 | return mKey->Equals(*aKey); |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | static KeyTypePointer KeyToPointer(KeyType aKey) |
michael@0 | 58 | { |
michael@0 | 59 | return aKey; |
michael@0 | 60 | } |
michael@0 | 61 | static PLDHashNumber HashKey(KeyTypePointer aKey) { |
michael@0 | 62 | return mozilla::HashString(*aKey); |
michael@0 | 63 | } |
michael@0 | 64 | |
michael@0 | 65 | enum { |
michael@0 | 66 | ALLOW_MEMMOVE = true |
michael@0 | 67 | }; |
michael@0 | 68 | |
michael@0 | 69 | private: |
michael@0 | 70 | const nsAString* mKey; |
michael@0 | 71 | }; |
michael@0 | 72 | |
michael@0 | 73 | /** |
michael@0 | 74 | * The Name Space Manager tracks the association between a NameSpace |
michael@0 | 75 | * URI and the int32_t runtime id. Mappings between NameSpaces and |
michael@0 | 76 | * NameSpace prefixes are managed by nsINameSpaces. |
michael@0 | 77 | * |
michael@0 | 78 | * All NameSpace URIs are stored in a global table so that IDs are |
michael@0 | 79 | * consistent accross the app. NameSpace IDs are only consistent at runtime |
michael@0 | 80 | * ie: they are not guaranteed to be consistent accross app sessions. |
michael@0 | 81 | * |
michael@0 | 82 | * The nsNameSpaceManager needs to have a live reference for as long as |
michael@0 | 83 | * the NameSpace IDs are needed. |
michael@0 | 84 | * |
michael@0 | 85 | */ |
michael@0 | 86 | |
michael@0 | 87 | class nsNameSpaceManager |
michael@0 | 88 | { |
michael@0 | 89 | public: |
michael@0 | 90 | virtual ~nsNameSpaceManager() {} |
michael@0 | 91 | |
michael@0 | 92 | virtual nsresult RegisterNameSpace(const nsAString& aURI, |
michael@0 | 93 | int32_t& aNameSpaceID); |
michael@0 | 94 | |
michael@0 | 95 | virtual nsresult GetNameSpaceURI(int32_t aNameSpaceID, nsAString& aURI); |
michael@0 | 96 | virtual int32_t GetNameSpaceID(const nsAString& aURI); |
michael@0 | 97 | |
michael@0 | 98 | virtual bool HasElementCreator(int32_t aNameSpaceID); |
michael@0 | 99 | |
michael@0 | 100 | static nsNameSpaceManager* GetInstance(); |
michael@0 | 101 | private: |
michael@0 | 102 | bool Init(); |
michael@0 | 103 | nsresult AddNameSpace(const nsAString& aURI, const int32_t aNameSpaceID); |
michael@0 | 104 | |
michael@0 | 105 | nsDataHashtable<nsNameSpaceKey,int32_t> mURIToIDTable; |
michael@0 | 106 | nsTArray< nsAutoPtr<nsString> > mURIArray; |
michael@0 | 107 | |
michael@0 | 108 | static mozilla::StaticAutoPtr<nsNameSpaceManager> sInstance; |
michael@0 | 109 | }; |
michael@0 | 110 | |
michael@0 | 111 | #endif // nsNameSpaceManager_h___ |