Bug 363242: Make txExpandedNameMap typesafe. r/sr=peterv

This commit is contained in:
cvshook%sicking.cc 2006-12-12 01:59:30 +00:00
Родитель ae03d24806
Коммит 66afe299b7
17 изменённых файлов: 267 добавлений и 305 удалений

Просмотреть файл

@ -38,19 +38,16 @@
#include "txExpandedNameMap.h"
#include "txCore.h"
#include <string.h>
const int kTxExpandedNameMapAllocSize = 16;
txExpandedNameMap::txExpandedNameMap(MBool aOwnsValues) :
mItems(0), mItemCount(0), mBufferCount(0), mOwnsValues(aOwnsValues)
class txMapItemComparator
{
}
txExpandedNameMap::~txExpandedNameMap()
{
clear();
}
public:
PRBool Equals(const txExpandedNameMap_base::MapItem& aItem,
const txExpandedName& aKey) const {
return aItem.mNamespaceID == aKey.mNamespaceID &&
aItem.mLocalName == aKey.mLocalName;
}
};
/**
* Adds an item, if an item with this key already exists an error is
@ -59,37 +56,21 @@ txExpandedNameMap::~txExpandedNameMap()
* @param aValue value of item to add
* @return errorcode
*/
nsresult txExpandedNameMap::add(const txExpandedName& aKey, TxObject* aValue)
nsresult txExpandedNameMap_base::addItem(const txExpandedName& aKey,
void* aValue)
{
int i;
// Check if there already is an item with this key
for (i = 0; i < mItemCount; ++i) {
if (mItems[i].mLocalName == aKey.mLocalName &&
mItems[i].mNamespaceID == aKey.mNamespaceID) {
return NS_ERROR_XSLT_ALREADY_SET;
}
PRUint32 pos = mItems.IndexOf(aKey, 0, txMapItemComparator());
if (pos != mItems.NoIndex) {
return NS_ERROR_XSLT_ALREADY_SET;
}
// Allocate a new array if needed
if (mBufferCount == mItemCount) {
MapItem* newItems = new MapItem[mItemCount +
kTxExpandedNameMapAllocSize];
if (!newItems) {
return NS_ERROR_OUT_OF_MEMORY;
}
mBufferCount += kTxExpandedNameMapAllocSize;
memcpy(newItems, mItems, mItemCount * sizeof(MapItem));
delete [] mItems;
mItems = newItems;
}
mItems[mItemCount].mNamespaceID = aKey.mNamespaceID;
mItems[mItemCount].mLocalName = aKey.mLocalName;
NS_IF_ADDREF(mItems[mItemCount].mLocalName);
mItems[mItemCount].mValue = aValue;
++mItemCount;
MapItem* item = mItems.AppendElement();
NS_ENSURE_TRUE(item, NS_ERROR_OUT_OF_MEMORY);
item->mNamespaceID = aKey.mNamespaceID;
item->mLocalName = aKey.mLocalName;
item->mValue = aValue;
return NS_OK;
}
@ -100,41 +81,26 @@ nsresult txExpandedNameMap::add(const txExpandedName& aKey, TxObject* aValue)
* @param aValue value of item to set
* @return errorcode
*/
nsresult txExpandedNameMap::set(const txExpandedName& aKey, TxObject* aValue)
nsresult txExpandedNameMap_base::setItem(const txExpandedName& aKey,
void* aValue,
void** aOldValue)
{
int i;
// Check if there already is an item with this key
for (i = 0; i < mItemCount; ++i) {
if (mItems[i].mLocalName == aKey.mLocalName &&
mItems[i].mNamespaceID == aKey.mNamespaceID) {
if (mOwnsValues) {
delete mItems[i].mValue;
}
mItems[i].mValue = aValue;
return NS_OK;
}
*aOldValue = nsnull;
PRUint32 pos = mItems.IndexOf(aKey, 0, txMapItemComparator());
if (pos != mItems.NoIndex) {
*aOldValue = mItems[pos].mValue;
mItems[pos].mValue = aValue;
return NS_OK;
}
// Allocate a new array if needed
if (mBufferCount == mItemCount) {
MapItem* newItems = new MapItem[mItemCount +
kTxExpandedNameMapAllocSize];
if (!newItems) {
return NS_ERROR_OUT_OF_MEMORY;
}
mBufferCount += kTxExpandedNameMapAllocSize;
memcpy(newItems, mItems, mItemCount * sizeof(MapItem));
delete [] mItems;
mItems = newItems;
}
mItems[mItemCount].mNamespaceID = aKey.mNamespaceID;
mItems[mItemCount].mLocalName = aKey.mLocalName;
NS_IF_ADDREF(mItems[mItemCount].mLocalName);
mItems[mItemCount].mValue = aValue;
++mItemCount;
MapItem* item = mItems.AppendElement();
NS_ENSURE_TRUE(item, NS_ERROR_OUT_OF_MEMORY);
item->mNamespaceID = aKey.mNamespaceID;
item->mLocalName = aKey.mLocalName;
item->mValue = aValue;
return NS_OK;
}
@ -143,16 +109,14 @@ nsresult txExpandedNameMap::set(const txExpandedName& aKey, TxObject* aValue)
* @param aKey key for item to get
* @return item with specified key, or null if no such item exists
*/
TxObject* txExpandedNameMap::get(const txExpandedName& aKey) const
void* txExpandedNameMap_base::getItem(const txExpandedName& aKey) const
{
int i;
for (i = 0; i < mItemCount; ++i) {
if (mItems[i].mLocalName == aKey.mLocalName &&
mItems[i].mNamespaceID == aKey.mNamespaceID) {
return mItems[i].mValue;
}
PRUint32 pos = mItems.IndexOf(aKey, 0, txMapItemComparator());
if (pos != mItems.NoIndex) {
return mItems[pos].mValue;
}
return 0;
return nsnull;
}
/**
@ -161,43 +125,14 @@ TxObject* txExpandedNameMap::get(const txExpandedName& aKey) const
* @return item with specified key, or null if it has been deleted
* or no such item exists
*/
TxObject* txExpandedNameMap::remove(const txExpandedName& aKey)
void* txExpandedNameMap_base::removeItem(const txExpandedName& aKey)
{
TxObject* value = 0;
int i;
for (i = 0; i < mItemCount; ++i) {
if (mItems[i].mLocalName == aKey.mLocalName &&
mItems[i].mNamespaceID == aKey.mNamespaceID) {
NS_IF_RELEASE(mItems[i].mLocalName);
if (mOwnsValues) {
delete mItems[i].mValue;
}
else {
value = mItems[i].mValue;
}
--mItemCount;
if (i != mItemCount) {
memcpy(&mItems[i], &mItems[mItemCount], sizeof(MapItem));
}
}
void* value = nsnull;
PRUint32 pos = mItems.IndexOf(aKey, 0, txMapItemComparator());
if (pos != mItems.NoIndex) {
value = mItems[pos].mValue;
mItems.RemoveElementAt(pos);
}
return value;
}
/**
* Clears the items
*/
void txExpandedNameMap::clear()
{
int i;
for (i = 0; i < mItemCount; ++i) {
NS_IF_RELEASE(mItems[i].mLocalName);
if (mOwnsValues) {
delete mItems[i].mValue;
}
}
delete [] mItems;
mItems = nsnull;
mItemCount = 0;
mBufferCount = 0;
}

Просмотреть файл

@ -41,15 +41,10 @@
#include "txError.h"
#include "txXMLUtils.h"
#include "nsTArray.h"
class TxObject;
class txExpandedNameMap {
public:
txExpandedNameMap(MBool aOwnsValues);
~txExpandedNameMap();
class txExpandedNameMap_base {
protected:
/**
* Adds an item, if an item with this key already exists an error is
* returned
@ -57,7 +52,7 @@ public:
* @param aValue value of item to add
* @return errorcode
*/
nsresult add(const txExpandedName& aKey, TxObject* aValue);
nsresult addItem(const txExpandedName& aKey, void* aValue);
/**
* Sets an item, if an item with this key already exists it is overwritten
@ -66,14 +61,15 @@ public:
* @param aValue value of item to set
* @return errorcode
*/
nsresult set(const txExpandedName& aKey, TxObject* aValue);
nsresult setItem(const txExpandedName& aKey, void* aValue,
void** aOldValue);
/**
* Gets an item
* @param aKey key for item to get
* @return item with specified key, or null if no such item exists
*/
TxObject* get(const txExpandedName& aKey) const;
void* getItem(const txExpandedName& aKey) const;
/**
* Removes an item, deleting it if the map owns the values
@ -81,57 +77,161 @@ public:
* @return item with specified key, or null if it has been deleted
* or no such item exists
*/
TxObject* remove(const txExpandedName& aKey);
void* removeItem(const txExpandedName& aKey);
/**
* Clears the items
*/
void clear();
void clearItems()
{
mItems.Clear();
}
class iterator {
class iterator_base {
public:
iterator(txExpandedNameMap& aMap) : mMap(aMap),
mCurrentPos(-1)
iterator_base(txExpandedNameMap_base& aMap)
: mMap(aMap),
mCurrentPos(PRUint32(-1))
{
}
MBool next()
{
return ++mCurrentPos < mMap.mItemCount;
return ++mCurrentPos < mMap.mItems.Length();
}
const txExpandedName key()
{
NS_ASSERTION(mCurrentPos >= 0 && mCurrentPos < mMap.mItemCount,
NS_ASSERTION(mCurrentPos >= 0 &&
mCurrentPos < mMap.mItems.Length(),
"invalid position in txExpandedNameMap::iterator");
return txExpandedName(mMap.mItems[mCurrentPos].mNamespaceID,
mMap.mItems[mCurrentPos].mLocalName);
}
TxObject* value()
protected:
void* itemValue()
{
NS_ASSERTION(mCurrentPos >= 0 && mCurrentPos < mMap.mItemCount,
NS_ASSERTION(mCurrentPos >= 0 &&
mCurrentPos < mMap.mItems.Length(),
"invalid position in txExpandedNameMap::iterator");
return mMap.mItems[mCurrentPos].mValue;
}
private:
txExpandedNameMap& mMap;
int mCurrentPos;
txExpandedNameMap_base& mMap;
PRUint32 mCurrentPos;
};
friend class iterator;
friend class iterator_base;
private:
friend class txMapItemComparator;
struct MapItem {
PRInt32 mNamespaceID;
nsIAtom* mLocalName;
TxObject* mValue;
nsCOMPtr<nsIAtom> mLocalName;
void* mValue;
};
MapItem* mItems;
int mItemCount, mBufferCount;
MBool mOwnsValues;
nsTArray<MapItem> mItems;
};
template<class E>
class txExpandedNameMap : public txExpandedNameMap_base
{
public:
nsresult add(const txExpandedName& aKey, E* aValue)
{
return addItem(aKey, (void*)aValue);
}
nsresult set(const txExpandedName& aKey, E* aValue)
{
void* oldValue;
return setItem(aKey, (void*)aValue, &oldValue);
}
E* get(const txExpandedName& aKey) const
{
return (E*)getItem(aKey);
}
E* remove(const txExpandedName& aKey)
{
return (E*)removeItem(aKey);
}
void clear()
{
clearItems();
}
class iterator : public iterator_base
{
public:
iterator(txExpandedNameMap& aMap)
: iterator_base(aMap)
{
}
E* value()
{
return (E*)itemValue();
}
};
};
template<class E>
class txOwningExpandedNameMap : public txExpandedNameMap_base
{
public:
~txOwningExpandedNameMap()
{
clear();
}
nsresult add(const txExpandedName& aKey, E* aValue)
{
return addItem(aKey, (void*)aValue);
}
nsresult set(const txExpandedName& aKey, E* aValue)
{
nsAutoPtr<E> oldValue;
return setItem(aKey, (void*)aValue, getter_Transfers(oldValue));
}
E* get(const txExpandedName& aKey) const
{
return (E*)getItem(aKey);
}
void remove(const txExpandedName& aKey)
{
delete (E*)removeItem(aKey);
}
void clear()
{
PRUint32 i, len = mItems.Length();
for (i = 0; i < len; ++i) {
delete (E*)mItems[i].mValue;
}
clearItems();
}
class iterator : public iterator_base
{
public:
iterator(txOwningExpandedNameMap& aMap)
: iterator_base(aMap)
{
}
E* value()
{
return (E*)itemValue();
}
};
};
#endif //TRANSFRMX_EXPANDEDNAMEMAP_H

Просмотреть файл

@ -67,8 +67,8 @@ class txXPathNode;
/**
* A Base Class for all XSL Expressions
**/
class Expr : public TxObject {
class Expr
{
public:
/**

Просмотреть файл

@ -54,7 +54,7 @@
* Note: for NodeSet, see NodeSet.h
*/
class txAExprResult : public TxObject
class txAExprResult
{
public:
friend class txResultRecycler;

Просмотреть файл

@ -133,13 +133,13 @@ txExecutionState::~txExecutionState()
txStackIterator paramIter(&mParamStack);
while (paramIter.hasNext()) {
delete (txExpandedNameMap*)paramIter.next();
delete (txVariableMap*)paramIter.next();
}
}
nsresult
txExecutionState::init(const txXPathNode& aNode,
txExpandedNameMap* aGlobalParams)
txOwningExpandedNameMap<txIGlobalParameter>* aGlobalParams)
{
nsresult rv = NS_OK;
@ -246,8 +246,7 @@ txExecutionState::getVariable(PRInt32 aNamespace, nsIAtom* aLName,
// Is this a stylesheet parameter that has a value?
if (var->mIsParam && mGlobalParams) {
txIGlobalParameter* param =
(txIGlobalParameter*)mGlobalParams->get(name);
txIGlobalParameter* param = mGlobalParams->get(name);
if (param) {
rv = param->getValue(&aResult);
NS_ENSURE_SUCCESS(rv, rv);

Просмотреть файл

@ -56,7 +56,6 @@ class txAOutputHandlerFactory;
class txAXMLEventHandler;
class txInstruction;
class txIOutputHandlerFactory;
class txExpandedNameMap;
class txLoadedDocumentEntry : public nsStringHashKey
{
@ -96,7 +95,8 @@ class txExecutionState : public txIMatchContext
public:
txExecutionState(txStylesheet* aStylesheet, PRBool aDisableLoads);
~txExecutionState();
nsresult init(const txXPathNode& aNode, txExpandedNameMap* aGlobalParams);
nsresult init(const txXPathNode& aNode,
txOwningExpandedNameMap<txIGlobalParameter>* aGlobalParams);
nsresult end(nsresult aResult);
TX_DECL_MATCH_CONTEXT;
@ -127,7 +127,6 @@ public:
// state-getting functions
txIEvalContext* getEvalContext();
txExpandedNameMap* getParamMap();
const txXPathNode* retrieveDocument(const nsAString& aUri);
nsresult getKeyNodes(const txExpandedName& aKeyName,
const txXPathNode& aRoot,
@ -181,7 +180,7 @@ private:
txIEvalContext* mEvalContext;
txIEvalContext* mInitialEvalContext;
//Document* mRTFDocument;
txExpandedNameMap* mGlobalParams;
txOwningExpandedNameMap<txIGlobalParameter>* mGlobalParams;
txLoadedDocumentsHash mLoadedDocuments;
txKeyHash mKeyHash;

Просмотреть файл

@ -123,13 +123,12 @@ DECL_DHASH_WRAPPER(txIndexedKeyHash, txIndexedKeyHashEntry,
* Class holding all <xsl:key>s of a particular expanded name in the
* stylesheet.
*/
class txXSLKey : public TxObject {
class txXSLKey {
public:
txXSLKey(const txExpandedName& aName) : mName(aName)
{
}
~txXSLKey();
/**
* Adds a match/use pair.
@ -183,7 +182,7 @@ private:
/**
* List of all match/use pairs. The items as |Key|s
*/
List mKeys;
nsTArray<Key> mKeys;
/**
* Name of this key
@ -195,7 +194,7 @@ private:
class txKeyHash
{
public:
txKeyHash(const txExpandedNameMap& aKeys)
txKeyHash(const txOwningExpandedNameMap<txXSLKey>& aKeys)
: mKeys(aKeys)
{
}
@ -217,7 +216,7 @@ private:
txIndexedKeyHash mIndexedKeys;
// Map of txXSLKeys
const txExpandedNameMap& mKeys;
const txOwningExpandedNameMap<txXSLKey>& mKeys;
// Empty nodeset returned if no key is found
nsRefPtr<txNodeSet> mEmptyNodeSet;

Просмотреть файл

@ -269,7 +269,7 @@ txKeyHash::getKeyNodes(const txExpandedName& aKeyName,
}
// The key needs to be indexed.
txXSLKey* xslKey = (txXSLKey*)mKeys.get(aKeyName);
txXSLKey* xslKey = mKeys.get(aKeyName);
if (!xslKey) {
// The key didn't exist, so bail.
return NS_ERROR_INVALID_ARG;
@ -309,18 +309,6 @@ txKeyHash::init()
return NS_OK;
}
/**
* Class holding all <xsl:key>s of a particular expanded name in the
* stylesheet.
*/
txXSLKey::~txXSLKey()
{
txListIterator iter(&mKeys);
Key* key;
while ((key = (Key*)iter.next())) {
delete key;
}
}
/**
* Adds a match/use pair.
@ -333,16 +321,12 @@ PRBool txXSLKey::addKey(nsAutoPtr<txPattern> aMatch, nsAutoPtr<Expr> aUse)
if (!aMatch || !aUse)
return PR_FALSE;
nsAutoPtr<Key> key(new Key);
Key* key = mKeys.AppendElement();
if (!key)
return PR_FALSE;
key->matchPattern = aMatch;
key->useExpr = aUse;
nsresult rv = mKeys.add(key);
NS_ENSURE_SUCCESS(rv, PR_FALSE);
key.forget();
return PR_TRUE;
}
@ -416,18 +400,16 @@ nsresult txXSLKey::testNode(const txXPathNode& aNode,
txExecutionState& aEs)
{
nsAutoString val;
txListIterator iter(&mKeys);
while (iter.hasNext())
{
Key* key = (Key*)iter.next();
if (key->matchPattern->matches(aNode, &aEs)) {
PRUint32 currKey, numKeys = mKeys.Length();
for (currKey = 0; currKey < numKeys; ++currKey) {
if (mKeys[currKey].matchPattern->matches(aNode, &aEs)) {
txSingleNodeContext evalContext(aNode, &aEs);
nsresult rv = aEs.pushEvalContext(&evalContext);
NS_ENSURE_SUCCESS(rv, rv);
nsRefPtr<txAExprResult> exprResult;
rv = key->useExpr->evaluate(&evalContext,
getter_AddRefs(exprResult));
rv = mKeys[currKey].useExpr->evaluate(&evalContext,
getter_AddRefs(exprResult));
NS_ENSURE_SUCCESS(rv, rv);
aEs.popEvalContext();

Просмотреть файл

@ -309,7 +309,6 @@ NS_INTERFACE_MAP_END
txMozillaXSLTProcessor::txMozillaXSLTProcessor() : mStylesheetDocument(nsnull),
mTransformResult(NS_OK),
mCompileResult(NS_OK),
mVariables(PR_TRUE),
mFlags(0)
{
}
@ -515,7 +514,7 @@ txMozillaXSLTProcessor::AddXSLTParam(const nsString& aName,
NS_ENSURE_SUCCESS(rv, rv);
txExpandedName varName(nsId, name);
txVariable* var = (txVariable*)mVariables.get(varName);
txVariable* var = NS_STATIC_CAST(txVariable*, mVariables.get(varName));
if (var) {
var->setValue(value);
@ -953,7 +952,7 @@ txMozillaXSLTProcessor::GetParameter(const nsAString& aNamespaceURI,
nsCOMPtr<nsIAtom> localName = do_GetAtom(aLocalName);
txExpandedName varName(nsId, localName);
txVariable* var = (txVariable*)mVariables.get(varName);
txVariable* var = NS_STATIC_CAST(txVariable*, mVariables.get(varName));
if (var) {
return var->getValue(aResult);
}

Просмотреть файл

@ -54,6 +54,7 @@ class nsIURI;
class nsIXMLContentSink;
class txStylesheet;
class txResultRecycler;
class txIGlobalParameter;
/* bacd8ad0-552f-11d3-a9f7-000064657374 */
#define TRANSFORMIIX_XSLT_PROCESSOR_CID \
@ -144,7 +145,7 @@ private:
nsresult mCompileResult;
nsString mErrorText, mSourceText;
nsCOMPtr<nsITransformObserver> mObserver;
txExpandedNameMap mVariables;
txOwningExpandedNameMap<txIGlobalParameter> mVariables;
txNamespaceMap mParamNamespaceMap;
nsRefPtr<txResultRecycler> mRecycler;

Просмотреть файл

@ -47,12 +47,7 @@
#include "txXPathTreeWalker.h"
txStylesheet::txStylesheet()
: mRootFrame(nsnull),
mNamedTemplates(PR_FALSE),
mDecimalFormats(PR_TRUE),
mAttributeSets(PR_FALSE),
mGlobalVariables(PR_TRUE),
mKeys(PR_TRUE)
: mRootFrame(nsnull)
{
}
@ -129,7 +124,7 @@ txStylesheet::~txStylesheet()
// We can't make the map own its values because then we wouldn't be able
// to merge attributesets of the same name
txExpandedNameMap::iterator attrSetIter(mAttributeSets);
txExpandedNameMap<txInstruction>::iterator attrSetIter(mAttributeSets);
while (attrSetIter.next()) {
delete attrSetIter.value();
}
@ -167,22 +162,19 @@ txStylesheet::findTemplate(const txXPathNode& aNode,
frame != endFrame) {
// get templatelist for this mode
txList* templates =
NS_STATIC_CAST(txList*, frame->mMatchableTemplates.get(aMode));
nsTArray<MatchableTemplate>* templates =
frame->mMatchableTemplates.get(aMode);
if (templates) {
txListIterator templateIter(templates);
// Find template with highest priority
MatchableTemplate* templ;
while (!matchTemplate &&
(templ =
NS_STATIC_CAST(MatchableTemplate*, templateIter.next()))) {
if (templ->mMatch->matches(aNode, aContext)) {
matchTemplate = templ->mFirstInstruction;
PRUint32 i, len = templates->Length();
for (i = 0; i < len && !matchTemplate; ++i) {
MatchableTemplate& templ = (*templates)[i];
if (templ.mMatch->matches(aNode, aContext)) {
matchTemplate = templ.mFirstInstruction;
*aImportFrame = frame;
#ifdef PR_LOGGING
match = templ->mMatch;
match = templ.mMatch;
#endif
}
}
@ -236,19 +228,19 @@ txStylesheet::findTemplate(const txXPathNode& aNode,
txDecimalFormat*
txStylesheet::getDecimalFormat(const txExpandedName& aName)
{
return NS_STATIC_CAST(txDecimalFormat*, mDecimalFormats.get(aName));
return mDecimalFormats.get(aName);
}
txInstruction*
txStylesheet::getAttributeSet(const txExpandedName& aName)
{
return NS_STATIC_CAST(txInstruction*, mAttributeSets.get(aName));
return mAttributeSets.get(aName);
}
txInstruction*
txStylesheet::getNamedTemplate(const txExpandedName& aName)
{
return NS_STATIC_CAST(txInstruction*, mNamedTemplates.get(aName));
return mNamedTemplates.get(aName);
}
txOutputFormat*
@ -260,10 +252,10 @@ txStylesheet::getOutputFormat()
txStylesheet::GlobalVariable*
txStylesheet::getGlobalVariable(const txExpandedName& aName)
{
return NS_STATIC_CAST(GlobalVariable*, mGlobalVariables.get(aName));
return mGlobalVariables.get(aName);
}
const txExpandedNameMap&
const txOwningExpandedNameMap<txXSLKey>&
txStylesheet::getKeyMap()
{
return mKeys;
@ -419,17 +411,17 @@ txStylesheet::addTemplate(txTemplateItem* aTemplate,
}
// get the txList for the right mode
txList* templates =
NS_STATIC_CAST(txList*,
aImportFrame->mMatchableTemplates.get(aTemplate->mMode));
nsTArray<MatchableTemplate>* templates =
aImportFrame->mMatchableTemplates.get(aTemplate->mMode);
if (!templates) {
nsAutoPtr<txList> newList(new txList);
nsAutoPtr< nsTArray<MatchableTemplate> > newList(
new nsTArray<MatchableTemplate>);
NS_ENSURE_TRUE(newList, NS_ERROR_OUT_OF_MEMORY);
rv = aImportFrame->mMatchableTemplates.add(aTemplate->mMode, newList);
rv = aImportFrame->mMatchableTemplates.set(aTemplate->mMode, newList);
NS_ENSURE_SUCCESS(rv, rv);
templates = newList.forget();
}
@ -451,28 +443,20 @@ txStylesheet::addTemplate(txTemplateItem* aTemplate,
NS_ASSERTION(!Double::isNaN(priority),
"simple pattern without default priority");
}
nsAutoPtr<MatchableTemplate>
nt(new MatchableTemplate(instr, simple, priority));
NS_ENSURE_TRUE(nt, NS_ERROR_OUT_OF_MEMORY);
txListIterator templ(templates);
while (templ.hasNext()) {
MatchableTemplate* mt = NS_STATIC_CAST(MatchableTemplate*,
templ.next());
if (priority > mt->mPriority) {
rv = templ.addBefore(nt);
NS_ENSURE_SUCCESS(rv, rv);
nt.forget();
PRUint32 i, len = templates->Length();
for (i = 0; i < len; ++i) {
if (priority > (*templates)[i].mPriority) {
break;
}
}
if (nt) {
rv = templates->add(nt);
NS_ENSURE_SUCCESS(rv, rv);
nt.forget();
}
MatchableTemplate* nt = templates->InsertElementAt(i);
NS_ENSURE_TRUE(nt, NS_ERROR_OUT_OF_MEMORY);
nt->mFirstInstruction = instr;
nt->mMatch = simple;
nt->mPriority = priority;
}
return NS_OK;
@ -532,9 +516,7 @@ nsresult
txStylesheet::addAttributeSet(txAttributeSetItem* aAttributeSetItem)
{
nsresult rv = NS_OK;
txInstruction* oldInstr =
NS_STATIC_CAST(txInstruction*,
mAttributeSets.get(aAttributeSetItem->mName));
txInstruction* oldInstr = mAttributeSets.get(aAttributeSetItem->mName);
if (!oldInstr) {
rv = mAttributeSets.add(aAttributeSetItem->mName,
aAttributeSetItem->mFirstInstruction);
@ -596,7 +578,7 @@ txStylesheet::addKey(const txExpandedName& aName,
{
nsresult rv = NS_OK;
txXSLKey* xslKey = NS_STATIC_CAST(txXSLKey*, mKeys.get(aName));
txXSLKey* xslKey = mKeys.get(aName);
if (!xslKey) {
xslKey = new txXSLKey(aName);
NS_ENSURE_TRUE(xslKey, NS_ERROR_OUT_OF_MEMORY);
@ -617,8 +599,7 @@ nsresult
txStylesheet::addDecimalFormat(const txExpandedName& aName,
nsAutoPtr<txDecimalFormat> aFormat)
{
txDecimalFormat* existing =
NS_STATIC_CAST(txDecimalFormat*, mDecimalFormats.get(aName));
txDecimalFormat* existing = mDecimalFormats.get(aName);
if (existing) {
NS_ENSURE_TRUE(existing->isEqual(aFormat),
NS_ERROR_XSLT_PARSE_FAILURE);
@ -634,24 +615,8 @@ txStylesheet::addDecimalFormat(const txExpandedName& aName,
return NS_OK;
}
txStylesheet::ImportFrame::ImportFrame()
: mMatchableTemplates(MB_TRUE),
mFirstNotImported(nsnull)
{
}
txStylesheet::ImportFrame::~ImportFrame()
{
// Delete templates in mMatchableTemplates
txExpandedNameMap::iterator mapIter(mMatchableTemplates);
while (mapIter.next()) {
txListIterator templIter(NS_STATIC_CAST(txList*, mapIter.value()));
MatchableTemplate* templ;
while ((templ = NS_STATIC_CAST(MatchableTemplate*, templIter.next()))) {
delete templ;
}
}
txListIterator tlIter(&mToplevelItems);
while (tlIter.hasNext()) {
delete NS_STATIC_CAST(txToplevelItem*, tlIter.next());

Просмотреть файл

@ -53,6 +53,7 @@ class txStripSpaceItem;
class txAttributeSetItem;
class txDecimalFormat;
class txStripSpaceTest;
class txXSLKey;
class txStylesheet
{
@ -91,7 +92,7 @@ public:
txInstruction* getNamedTemplate(const txExpandedName& aName);
txOutputFormat* getOutputFormat();
GlobalVariable* getGlobalVariable(const txExpandedName& aName);
const txExpandedNameMap& getKeyMap();
const txOwningExpandedNameMap<txXSLKey>& getKeyMap();
PRBool isStripSpaceAllowed(const txXPathNode& aNode,
txIMatchContext* aContext);
@ -112,20 +113,28 @@ public:
nsresult addDecimalFormat(const txExpandedName& aName,
nsAutoPtr<txDecimalFormat> aFormat);
struct MatchableTemplate {
txInstruction* mFirstInstruction;
nsAutoPtr<txPattern> mMatch;
double mPriority;
};
/**
* Contain information that is import precedence dependant.
*/
class ImportFrame {
public:
ImportFrame();
ImportFrame()
: mFirstNotImported(nsnull)
{
}
~ImportFrame();
// List of toplevel items
txList mToplevelItems;
// Map of template modes, each item in the map is a txList
// of templates
txExpandedNameMap mMatchableTemplates;
// Map of template modes
txOwningExpandedNameMap< nsTArray<MatchableTemplate> > mMatchableTemplates;
// ImportFrame which is the first one *not* imported by this frame
ImportFrame* mFirstNotImported;
@ -143,21 +152,6 @@ public:
};
private:
class MatchableTemplate {
public:
MatchableTemplate(txInstruction* aFirstInstruction,
nsAutoPtr<txPattern> aPattern,
double aPriority)
: mFirstInstruction(aFirstInstruction),
mMatch(aPattern),
mPriority(aPriority)
{
}
txInstruction* mFirstInstruction;
nsAutoPtr<txPattern> mMatch;
double mPriority;
};
nsresult addTemplate(txTemplateItem* aTemplate, ImportFrame* aImportFrame);
nsresult addGlobalVariable(txVariableItem* aVariable);
nsresult addFrames(txListIterator& aInsertIter);
@ -182,19 +176,19 @@ private:
ImportFrame* mRootFrame;
// Named templates
txExpandedNameMap mNamedTemplates;
txExpandedNameMap<txInstruction> mNamedTemplates;
// Map with all decimal-formats
txExpandedNameMap mDecimalFormats;
txOwningExpandedNameMap<txDecimalFormat> mDecimalFormats;
// Map with all named attribute sets
txExpandedNameMap mAttributeSets;
txExpandedNameMap<txInstruction> mAttributeSets;
// Map with all global variables and parameters
txExpandedNameMap mGlobalVariables;
txOwningExpandedNameMap<GlobalVariable> mGlobalVariables;
// Map with all keys
txExpandedNameMap mKeys;
txOwningExpandedNameMap<txXSLKey> mKeys;
// Array of all txStripSpaceTests, sorted in acending order
nsTPtrArray<txStripSpaceTest> mStripSpaceTests;
@ -239,7 +233,7 @@ protected:
/**
* Value of a global parameter
*/
class txIGlobalParameter : public TxObject
class txIGlobalParameter
{
public:
virtual nsresult getValue(txAExprResult** aValue) = 0;

Просмотреть файл

@ -2980,8 +2980,7 @@ txHandlerTable::txHandlerTable(const HandleTextFn aTextHandler,
const txElementHandler* aOtherHandler)
: mTextHandler(aTextHandler),
mLREHandler(aLREHandler),
mOtherHandler(aOtherHandler),
mHandlers(PR_FALSE)
mOtherHandler(aOtherHandler)
{
}
@ -2994,8 +2993,7 @@ txHandlerTable::init(const txElementHandler* aHandlers, PRUint32 aCount)
for (i = 0; i < aCount; ++i) {
nsCOMPtr<nsIAtom> nameAtom = do_GetAtom(aHandlers->mLocalName);
txExpandedName name(aHandlers->mNamespaceID, nameAtom);
// XXX this cast is a reinterpret_cast, which is sad
rv = mHandlers.add(name, (TxObject*)aHandlers);
rv = mHandlers.add(name, aHandlers);
NS_ENSURE_SUCCESS(rv, rv);
++aHandlers;
@ -3007,9 +3005,7 @@ const txElementHandler*
txHandlerTable::find(PRInt32 aNamespaceID, nsIAtom* aLocalName)
{
txExpandedName name(aNamespaceID, aLocalName);
// XXX this cast is a reinterpret_cast, same sad story as in ::init
const txElementHandler* handler =
(const txElementHandler*)mHandlers.get(name);
const txElementHandler* handler = mHandlers.get(name);
if (!handler) {
handler = mOtherHandler;
}

Просмотреть файл

@ -80,7 +80,7 @@ public:
private:
const txElementHandler* const mOtherHandler;
txExpandedNameMap mHandlers;
txExpandedNameMap<const txElementHandler> mHandlers;
};
extern txHandlerTable* gTxRootHandler;

Просмотреть файл

@ -46,7 +46,6 @@
class txVariableMap {
public:
txVariableMap();
~txVariableMap();
nsresult bindVariable(const txExpandedName& aName, txAExprResult* aValue);
@ -56,22 +55,16 @@ public:
void removeVariable(const txExpandedName& aName);
private:
txExpandedNameMap mMap;
txExpandedNameMap<txAExprResult> mMap;
};
inline
txVariableMap::txVariableMap()
: mMap(MB_FALSE)
{
}
inline
txVariableMap::~txVariableMap()
{
txExpandedNameMap::iterator iter(mMap);
txExpandedNameMap<txAExprResult>::iterator iter(mMap);
while (iter.next()) {
txAExprResult* res = NS_STATIC_CAST(txAExprResult*, iter.value());
txAExprResult* res = iter.value();
NS_RELEASE(res);
}
}
@ -90,7 +83,7 @@ txVariableMap::bindVariable(const txExpandedName& aName, txAExprResult* aValue)
inline void
txVariableMap::getVariable(const txExpandedName& aName, txAExprResult** aResult)
{
*aResult = NS_STATIC_CAST(txAExprResult*, mMap.get(aName));
*aResult = mMap.get(aName);
if (*aResult) {
NS_ADDREF(*aResult);
}
@ -99,7 +92,7 @@ txVariableMap::getVariable(const txExpandedName& aName, txAExprResult** aResult)
inline void
txVariableMap::removeVariable(const txExpandedName& aName)
{
txAExprResult* var = NS_STATIC_CAST(txAExprResult*, mMap.remove(aName));
txAExprResult* var = mMap.remove(aName);
NS_IF_RELEASE(var);
}

Просмотреть файл

@ -119,7 +119,7 @@ private:
* DecimalFormat
* A representation of the XSLT element <xsl:decimal-format>
*/
class txDecimalFormat : public TxObject {
class txDecimalFormat {
public:
/*

Просмотреть файл

@ -45,7 +45,7 @@
class ProcessorState;
class txPattern : public TxObject
class txPattern
{
public:
virtual ~txPattern();