Back to index

lightning-sunbird  0.9+nobinonly
Classes | Public Member Functions | Private Attributes | Friends
txExpandedNameMap Class Reference

#include <txExpandedNameMap.h>

Collaboration diagram for txExpandedNameMap:
Collaboration graph
[legend]

List of all members.

Classes

class  iterator
struct  MapItem

Public Member Functions

 txExpandedNameMap (MBool aOwnsValues)
 ~txExpandedNameMap ()
nsresult add (const txExpandedName &aKey, TxObject *aValue)
 Adds an item, if an item with this key already exists an error is returned.
nsresult set (const txExpandedName &aKey, TxObject *aValue)
 Sets an item, if an item with this key already exists it is overwritten with the new value.
TxObjectget (const txExpandedName &aKey) const
 Gets an item.
TxObjectremove (const txExpandedName &aKey)
 Removes an item, deleting it if the map owns the values.
void clear ()
 Clears the items.

Private Attributes

MapItemmItems
int mItemCount
int mBufferCount
MBool mOwnsValues

Friends

class iterator

Detailed Description

Definition at line 47 of file txExpandedNameMap.h.


Class Documentation

struct txExpandedNameMap::MapItem

Definition at line 126 of file txExpandedNameMap.h.

Collaboration diagram for txExpandedNameMap::MapItem:
Class Members
nsIAtom * mLocalName
PRInt32 mNamespaceID
TxObject * mValue

Constructor & Destructor Documentation

Definition at line 45 of file txExpandedNameMap.cpp.

                                                      :
    mItems(0), mItemCount(0), mBufferCount(0), mOwnsValues(aOwnsValues)
{
}

Definition at line 50 of file txExpandedNameMap.cpp.

{
    clear();
}

Here is the call graph for this function:


Member Function Documentation

Adds an item, if an item with this key already exists an error is returned.

Parameters:
aKeykey for item to add
aValuevalue of item to add
Returns:
errorcode

Definition at line 62 of file txExpandedNameMap.cpp.

{
    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;
        }
    }
    
    // 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;
    
    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Clears the items.

Definition at line 190 of file txExpandedNameMap.cpp.

{
    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;
}

Here is the caller graph for this function:

Gets an item.

Parameters:
aKeykey for item to get
Returns:
item with specified key, or null if no such item exists

Definition at line 146 of file txExpandedNameMap.cpp.

{
    int i;
    for (i = 0; i < mItemCount; ++i) {
        if (mItems[i].mLocalName == aKey.mLocalName &&
            mItems[i].mNamespaceID == aKey.mNamespaceID) {
            return mItems[i].mValue;
        }
    }
    return 0;
}

Here is the caller graph for this function:

Removes an item, deleting it if the map owns the values.

Parameters:
aKeykey for item to remove
Returns:
item with specified key, or null if it has been deleted or no such item exists

Definition at line 164 of file txExpandedNameMap.cpp.

{
    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));
            }
        }
    }
    return value;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Sets an item, if an item with this key already exists it is overwritten with the new value.

Parameters:
aKeykey for item to set
aValuevalue of item to set
Returns:
errorcode

Definition at line 103 of file txExpandedNameMap.cpp.

{
    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;
        }
    }
    
    // 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;
    
    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Friends And Related Function Documentation

friend class iterator [friend]

Definition at line 123 of file txExpandedNameMap.h.


Member Data Documentation

Definition at line 133 of file txExpandedNameMap.h.

Definition at line 133 of file txExpandedNameMap.h.

Definition at line 132 of file txExpandedNameMap.h.

Definition at line 134 of file txExpandedNameMap.h.


The documentation for this class was generated from the following files: