michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsNameSpaceManager_h___ michael@0: #define nsNameSpaceManager_h___ michael@0: michael@0: #include "nsDataHashtable.h" michael@0: #include "nsTArray.h" michael@0: michael@0: #include "mozilla/StaticPtr.h" michael@0: michael@0: class nsIAtom; michael@0: class nsAString; michael@0: michael@0: #define kNameSpaceID_Unknown -1 michael@0: // 0 is special at C++, so use a static const int32_t for michael@0: // kNameSpaceID_None to keep if from being cast to pointers michael@0: // Note that the XBL cache assumes (and asserts) that it can treat a michael@0: // single-byte value higher than kNameSpaceID_LastBuiltin specially. michael@0: static const int32_t kNameSpaceID_None = 0; michael@0: #define kNameSpaceID_XMLNS 1 // not really a namespace, but it needs to play the game michael@0: #define kNameSpaceID_XML 2 michael@0: #define kNameSpaceID_XHTML 3 michael@0: #define kNameSpaceID_XLink 4 michael@0: #define kNameSpaceID_XSLT 5 michael@0: #define kNameSpaceID_XBL 6 michael@0: #define kNameSpaceID_MathML 7 michael@0: #define kNameSpaceID_RDF 8 michael@0: #define kNameSpaceID_XUL 9 michael@0: #define kNameSpaceID_SVG 10 michael@0: #define kNameSpaceID_LastBuiltin 10 // last 'built-in' namespace michael@0: michael@0: class nsNameSpaceKey : public PLDHashEntryHdr michael@0: { michael@0: public: michael@0: typedef const nsAString* KeyType; michael@0: typedef const nsAString* KeyTypePointer; michael@0: michael@0: nsNameSpaceKey(KeyTypePointer aKey) : mKey(aKey) michael@0: { michael@0: } michael@0: nsNameSpaceKey(const nsNameSpaceKey& toCopy) : mKey(toCopy.mKey) michael@0: { michael@0: } michael@0: michael@0: KeyType GetKey() const michael@0: { michael@0: return mKey; michael@0: } michael@0: bool KeyEquals(KeyType aKey) const michael@0: { michael@0: return mKey->Equals(*aKey); michael@0: } michael@0: michael@0: static KeyTypePointer KeyToPointer(KeyType aKey) michael@0: { michael@0: return aKey; michael@0: } michael@0: static PLDHashNumber HashKey(KeyTypePointer aKey) { michael@0: return mozilla::HashString(*aKey); michael@0: } michael@0: michael@0: enum { michael@0: ALLOW_MEMMOVE = true michael@0: }; michael@0: michael@0: private: michael@0: const nsAString* mKey; michael@0: }; michael@0: michael@0: /** michael@0: * The Name Space Manager tracks the association between a NameSpace michael@0: * URI and the int32_t runtime id. Mappings between NameSpaces and michael@0: * NameSpace prefixes are managed by nsINameSpaces. michael@0: * michael@0: * All NameSpace URIs are stored in a global table so that IDs are michael@0: * consistent accross the app. NameSpace IDs are only consistent at runtime michael@0: * ie: they are not guaranteed to be consistent accross app sessions. michael@0: * michael@0: * The nsNameSpaceManager needs to have a live reference for as long as michael@0: * the NameSpace IDs are needed. michael@0: * michael@0: */ michael@0: michael@0: class nsNameSpaceManager michael@0: { michael@0: public: michael@0: virtual ~nsNameSpaceManager() {} michael@0: michael@0: virtual nsresult RegisterNameSpace(const nsAString& aURI, michael@0: int32_t& aNameSpaceID); michael@0: michael@0: virtual nsresult GetNameSpaceURI(int32_t aNameSpaceID, nsAString& aURI); michael@0: virtual int32_t GetNameSpaceID(const nsAString& aURI); michael@0: michael@0: virtual bool HasElementCreator(int32_t aNameSpaceID); michael@0: michael@0: static nsNameSpaceManager* GetInstance(); michael@0: private: michael@0: bool Init(); michael@0: nsresult AddNameSpace(const nsAString& aURI, const int32_t aNameSpaceID); michael@0: michael@0: nsDataHashtable mURIToIDTable; michael@0: nsTArray< nsAutoPtr > mURIArray; michael@0: michael@0: static mozilla::StaticAutoPtr sInstance; michael@0: }; michael@0: michael@0: #endif // nsNameSpaceManager_h___