LCOV - code coverage report
Current view: directory - content/xslt/src/base - txExpandedNameMap.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 37 11 29.7 %
Date: 2012-06-02 Functions: 5 2 40.0 %

       1                 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 : /* ***** BEGIN LICENSE BLOCK *****
       3                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       4                 :  *
       5                 :  * The contents of this file are subject to the Mozilla Public License Version
       6                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       7                 :  * the License. You may obtain a copy of the License at
       8                 :  * http://www.mozilla.org/MPL/
       9                 :  *
      10                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      11                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12                 :  * for the specific language governing rights and limitations under the
      13                 :  * License.
      14                 :  *
      15                 :  * The Original Code is TransforMiiX XSLT processor code.
      16                 :  *
      17                 :  * The Initial Developer of the Original Code is
      18                 :  * Jonas Sicking.
      19                 :  * Portions created by the Initial Developer are Copyright (C) 2002
      20                 :  * the Initial Developer. All Rights Reserved.
      21                 :  *
      22                 :  * Contributor(s):
      23                 :  *   Jonas Sicking <sicking@bigfoot.com>
      24                 :  *
      25                 :  * Alternatively, the contents of this file may be used under the terms of
      26                 :  * either the GNU General Public License Version 2 or later (the "GPL"), or
      27                 :  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      28                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      29                 :  * of those above. If you wish to allow use of your version of this file only
      30                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      31                 :  * use your version of this file under the terms of the MPL, indicate your
      32                 :  * decision by deleting the provisions above and replace them with the notice
      33                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      34                 :  * the provisions above, a recipient may use your version of this file under
      35                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      36                 :  *
      37                 :  * ***** END LICENSE BLOCK ***** */
      38                 : 
      39                 : #include "txExpandedNameMap.h"
      40                 : #include "txCore.h"
      41                 : 
      42                 : class txMapItemComparator
      43                 : {
      44                 :   public:
      45          296244 :     bool Equals(const txExpandedNameMap_base::MapItem& aItem,
      46                 :                   const txExpandedName& aKey) const {
      47                 :       return aItem.mNamespaceID == aKey.mNamespaceID &&
      48          296244 :              aItem.mLocalName == aKey.mLocalName;
      49                 :     }
      50                 : };
      51                 : 
      52                 : /**
      53                 :  * Adds an item, if an item with this key already exists an error is
      54                 :  * returned
      55                 :  * @param  aKey   key for item to add
      56                 :  * @param  aValue value of item to add
      57                 :  * @return errorcode
      58                 :  */
      59           57564 : nsresult txExpandedNameMap_base::addItem(const txExpandedName& aKey,
      60                 :                                          void* aValue)
      61                 : {
      62           57564 :     PRUint32 pos = mItems.IndexOf(aKey, 0, txMapItemComparator());
      63           57564 :     if (pos != mItems.NoIndex) {
      64               0 :         return NS_ERROR_XSLT_ALREADY_SET;
      65                 :     }
      66                 : 
      67           57564 :     MapItem* item = mItems.AppendElement();
      68           57564 :     NS_ENSURE_TRUE(item, NS_ERROR_OUT_OF_MEMORY);
      69                 : 
      70           57564 :     item->mNamespaceID = aKey.mNamespaceID;
      71           57564 :     item->mLocalName = aKey.mLocalName;
      72           57564 :     item->mValue = aValue;
      73                 : 
      74           57564 :     return NS_OK;
      75                 : }
      76                 : 
      77                 : /**
      78                 :  * Sets an item, if an item with this key already exists it is overwritten
      79                 :  * with the new value
      80                 :  * @param  aKey   key for item to set
      81                 :  * @param  aValue value of item to set
      82                 :  * @return errorcode
      83                 :  */
      84               0 : nsresult txExpandedNameMap_base::setItem(const txExpandedName& aKey,
      85                 :                                          void* aValue,
      86                 :                                          void** aOldValue)
      87                 : {
      88               0 :     *aOldValue = nsnull;
      89               0 :     PRUint32 pos = mItems.IndexOf(aKey, 0, txMapItemComparator());
      90               0 :     if (pos != mItems.NoIndex) {
      91               0 :         *aOldValue = mItems[pos].mValue;
      92               0 :         mItems[pos].mValue = aValue;
      93                 :         
      94               0 :         return NS_OK;
      95                 :     }
      96                 : 
      97               0 :     MapItem* item = mItems.AppendElement();
      98               0 :     NS_ENSURE_TRUE(item, NS_ERROR_OUT_OF_MEMORY);
      99                 : 
     100               0 :     item->mNamespaceID = aKey.mNamespaceID;
     101               0 :     item->mLocalName = aKey.mLocalName;
     102               0 :     item->mValue = aValue;
     103                 : 
     104               0 :     return NS_OK;
     105                 : }
     106                 : 
     107                 : /**
     108                 :  * Gets an item
     109                 :  * @param  aKey  key for item to get
     110                 :  * @return item with specified key, or null if no such item exists
     111                 :  */
     112               0 : void* txExpandedNameMap_base::getItem(const txExpandedName& aKey) const
     113                 : {
     114               0 :     PRUint32 pos = mItems.IndexOf(aKey, 0, txMapItemComparator());
     115               0 :     if (pos != mItems.NoIndex) {
     116               0 :         return mItems[pos].mValue;
     117                 :     }
     118                 : 
     119               0 :     return nsnull;
     120                 : }
     121                 : 
     122                 : /**
     123                 :  * Removes an item, deleting it if the map owns the values
     124                 :  * @param  aKey  key for item to remove
     125                 :  * @return item with specified key, or null if it has been deleted
     126                 :  *         or no such item exists
     127                 :  */
     128               0 : void* txExpandedNameMap_base::removeItem(const txExpandedName& aKey)
     129                 : {
     130               0 :     void* value = nsnull;
     131               0 :     PRUint32 pos = mItems.IndexOf(aKey, 0, txMapItemComparator());
     132               0 :     if (pos != mItems.NoIndex) {
     133               0 :         value = mItems[pos].mValue;
     134               0 :         mItems.RemoveElementAt(pos);
     135                 :     }
     136                 : 
     137               0 :     return value;
     138                 : }

Generated by: LCOV version 1.7