2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
1998-12-11 05:30:59 +03:00
|
|
|
|
2014-02-28 03:04:46 +04:00
|
|
|
#ifndef nsNameSpaceManager_h___
|
|
|
|
#define nsNameSpaceManager_h___
|
1998-12-11 05:30:59 +03:00
|
|
|
|
2014-02-28 03:04:46 +04:00
|
|
|
#include "nsDataHashtable.h"
|
|
|
|
#include "nsTArray.h"
|
|
|
|
|
|
|
|
#include "mozilla/StaticPtr.h"
|
1998-12-11 05:30:59 +03:00
|
|
|
|
2013-10-22 01:23:33 +04:00
|
|
|
class nsAString;
|
1998-12-11 05:30:59 +03:00
|
|
|
|
2014-02-28 03:04:46 +04:00
|
|
|
class nsNameSpaceKey : public PLDHashEntryHdr
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef const nsAString* KeyType;
|
|
|
|
typedef const nsAString* KeyTypePointer;
|
|
|
|
|
2014-08-05 17:19:51 +04:00
|
|
|
explicit nsNameSpaceKey(KeyTypePointer aKey) : mKey(aKey)
|
2014-02-28 03:04:46 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
nsNameSpaceKey(const nsNameSpaceKey& toCopy) : mKey(toCopy.mKey)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
KeyType GetKey() const
|
|
|
|
{
|
|
|
|
return mKey;
|
|
|
|
}
|
|
|
|
bool KeyEquals(KeyType aKey) const
|
|
|
|
{
|
|
|
|
return mKey->Equals(*aKey);
|
|
|
|
}
|
|
|
|
|
|
|
|
static KeyTypePointer KeyToPointer(KeyType aKey)
|
|
|
|
{
|
|
|
|
return aKey;
|
|
|
|
}
|
|
|
|
static PLDHashNumber HashKey(KeyTypePointer aKey) {
|
|
|
|
return mozilla::HashString(*aKey);
|
|
|
|
}
|
1998-12-11 05:30:59 +03:00
|
|
|
|
2014-02-28 03:04:46 +04:00
|
|
|
enum {
|
|
|
|
ALLOW_MEMMOVE = true
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
const nsAString* mKey;
|
|
|
|
};
|
|
|
|
|
1998-12-11 05:30:59 +03:00
|
|
|
/**
|
2010-05-13 16:19:51 +04:00
|
|
|
* The Name Space Manager tracks the association between a NameSpace
|
2012-08-22 19:56:38 +04:00
|
|
|
* URI and the int32_t runtime id. Mappings between NameSpaces and
|
2002-11-30 02:44:07 +03:00
|
|
|
* NameSpace prefixes are managed by nsINameSpaces.
|
1998-12-11 05:30:59 +03:00
|
|
|
*
|
|
|
|
* All NameSpace URIs are stored in a global table so that IDs are
|
|
|
|
* consistent accross the app. NameSpace IDs are only consistent at runtime
|
|
|
|
* ie: they are not guaranteed to be consistent accross app sessions.
|
|
|
|
*
|
2014-02-28 03:04:46 +04:00
|
|
|
* The nsNameSpaceManager needs to have a live reference for as long as
|
2002-11-30 02:44:07 +03:00
|
|
|
* the NameSpace IDs are needed.
|
1998-12-11 05:30:59 +03:00
|
|
|
*
|
|
|
|
*/
|
2001-09-05 08:20:54 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class nsNameSpaceManager final
|
2001-09-05 08:20:54 +04:00
|
|
|
{
|
1998-12-11 05:30:59 +03:00
|
|
|
public:
|
2014-02-28 03:04:46 +04:00
|
|
|
virtual ~nsNameSpaceManager() {}
|
1999-06-30 23:28:16 +04:00
|
|
|
|
2005-09-11 15:24:16 +04:00
|
|
|
virtual nsresult RegisterNameSpace(const nsAString& aURI,
|
2014-02-28 03:04:46 +04:00
|
|
|
int32_t& aNameSpaceID);
|
1998-12-11 05:30:59 +03:00
|
|
|
|
2014-02-28 03:04:46 +04:00
|
|
|
virtual nsresult GetNameSpaceURI(int32_t aNameSpaceID, nsAString& aURI);
|
|
|
|
virtual int32_t GetNameSpaceID(const nsAString& aURI);
|
2001-09-05 08:20:54 +04:00
|
|
|
|
2014-02-28 03:04:46 +04:00
|
|
|
virtual bool HasElementCreator(int32_t aNameSpaceID);
|
2005-11-11 17:36:26 +03:00
|
|
|
|
2014-02-28 03:04:46 +04:00
|
|
|
static nsNameSpaceManager* GetInstance();
|
|
|
|
private:
|
|
|
|
bool Init();
|
|
|
|
nsresult AddNameSpace(const nsAString& aURI, const int32_t aNameSpaceID);
|
1998-12-11 05:30:59 +03:00
|
|
|
|
2014-02-28 03:04:46 +04:00
|
|
|
nsDataHashtable<nsNameSpaceKey,int32_t> mURIToIDTable;
|
|
|
|
nsTArray< nsAutoPtr<nsString> > mURIArray;
|
2001-09-06 10:18:31 +04:00
|
|
|
|
2014-02-28 03:04:46 +04:00
|
|
|
static mozilla::StaticAutoPtr<nsNameSpaceManager> sInstance;
|
|
|
|
};
|
|
|
|
|
2014-02-28 03:04:46 +04:00
|
|
|
#endif // nsNameSpaceManager_h___
|