LCOV - code coverage report
Current view: top level - tools/source/memtools - unqidx.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 48 59 81.4 %
Date: 2012-08-25 Functions: 7 8 87.5 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 41 84 48.8 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*
       3                 :            :  * This file is part of the LibreOffice project.
       4                 :            :  *
       5                 :            :  * This Source Code Form is subject to the terms of the Mozilla Public
       6                 :            :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7                 :            :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8                 :            :  *
       9                 :            :  * This file incorporates work covered by the following license notice:
      10                 :            :  *
      11                 :            :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12                 :            :  *   contributor license agreements. See the NOTICE file distributed
      13                 :            :  *   with this work for additional information regarding copyright
      14                 :            :  *   ownership. The ASF licenses this file to you under the Apache
      15                 :            :  *   License, Version 2.0 (the "License"); you may not use this file
      16                 :            :  *   except in compliance with the License. You may obtain a copy of
      17                 :            :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18                 :            :  */
      19                 :            : 
      20                 :            : #include <tools/unqidx.hxx>
      21                 :            : 
      22                 :      52488 : sal_uIntPtr UniqueIndexImpl::Insert( void* p )
      23                 :            : {
      24                 :            :     // NULL-Pointer not allowed
      25         [ -  + ]:      52488 :     if ( !p )
      26                 :          0 :         return UNIQUEINDEX_ENTRY_NOTFOUND;
      27                 :            : 
      28                 :            :    // Expend array if full
      29                 :      52488 :     sal_uIntPtr nTmp = size();
      30         [ +  - ]:      52488 :     if( nTmp == nCount )
      31                 :      52488 :         nTmp++;
      32                 :            : 
      33                 :            :     // Avoid overflow of UniqIndex upon deletion
      34                 :      52488 :     nUniqIndex = nUniqIndex % nTmp;
      35                 :            : 
      36                 :            :     // Search next empty index
      37 [ +  - ][ +  - ]:      52488 :     while ( find( nUniqIndex ) != end() )
                 [ -  + ]
      38                 :          0 :         nUniqIndex = (nUniqIndex+1) % nTmp;
      39                 :            : 
      40                 :            :     // Insert object to array
      41                 :      52488 :     (*this)[ nUniqIndex ] = p;
      42                 :            : 
      43                 :      52488 :     nCount++;
      44                 :      52488 :     nUniqIndex++;
      45                 :      52488 :     return ( nUniqIndex + nStartIndex - 1 );
      46                 :            : }
      47                 :            : 
      48                 :          0 : void UniqueIndexImpl::Insert( sal_uIntPtr nIndex, void* p )
      49                 :            : {
      50                 :            :     // NULL-Pointer not allowed
      51         [ #  # ]:          0 :     if ( !p )
      52                 :          0 :         return;
      53                 :            : 
      54                 :          0 :     sal_uIntPtr nContIndex = nIndex - nStartIndex;
      55                 :            : 
      56 [ #  # ][ #  # ]:          0 :     bool bFound = find( nContIndex ) != end();
      57                 :            : 
      58                 :            :     // Insert object to array
      59         [ #  # ]:          0 :     (*this)[ nContIndex ] = p;
      60                 :            : 
      61         [ #  # ]:          0 :     if( !bFound )
      62                 :          0 :         nCount++;
      63                 :            : }
      64                 :            : 
      65                 :       2764 : void* UniqueIndexImpl::Remove( sal_uIntPtr nIndex )
      66                 :            : {
      67                 :            :     // Check for valid index
      68   [ +  -  +  - ]:       5528 :     if ( (nIndex >= nStartIndex) &&
                 [ +  - ]
      69                 :       2764 :          (nIndex < (size() + nStartIndex)) )
      70                 :            :     {
      71                 :            :         // insert index as empty entry, and reduce indexcount,
      72                 :            :         // if this entry was used
      73         [ +  - ]:       2764 :         iterator it = find( nIndex - nStartIndex );
      74 [ +  - ][ +  - ]:       2764 :         if( it != end() )
      75                 :            :         {
      76         [ +  - ]:       2764 :             void* p = it->second;
      77         [ +  - ]:       2764 :             erase( it );
      78                 :       2764 :             nCount--;
      79                 :       2764 :             return p;
      80                 :            :         }
      81                 :            :     }
      82                 :       2764 :     return NULL;
      83                 :            : }
      84                 :            : 
      85                 :      11798 : void* UniqueIndexImpl::Get( sal_uIntPtr nIndex ) const
      86                 :            : {
      87                 :            :     // check for valid index
      88   [ +  -  +  - ]:      23596 :     if ( (nIndex >= nStartIndex) &&
                 [ +  - ]
      89                 :      11798 :          (nIndex < (size() + nStartIndex)) )
      90                 :            :     {
      91         [ +  - ]:      11798 :         const_iterator it = find( nIndex - nStartIndex );
      92 [ +  - ][ +  - ]:      11798 :         if( it != end() )
      93         [ +  - ]:      11798 :             return it->second;
      94                 :            :     }
      95                 :      11798 :     return NULL;
      96                 :            : }
      97                 :            : 
      98                 :       7086 : sal_uIntPtr UniqueIndexImpl::FirstIndex() const
      99                 :            : {
     100         [ +  + ]:       7086 :     if ( empty() )
     101                 :       1440 :         return UNIQUEINDEX_ENTRY_NOTFOUND;
     102                 :            : 
     103         [ +  - ]:       7086 :     return begin()->first;
     104                 :            : }
     105                 :            : 
     106                 :       4204 : sal_uIntPtr UniqueIndexImpl::LastIndex() const
     107                 :            : {
     108         [ +  + ]:       4204 :     if ( empty() )
     109                 :       1440 :         return UNIQUEINDEX_ENTRY_NOTFOUND;
     110                 :            : 
     111         [ +  - ]:       4204 :     return rbegin()->first;
     112                 :            : }
     113                 :            : 
     114                 :       6978 : sal_uIntPtr UniqueIndexImpl::NextIndex(sal_uIntPtr aIndex) const
     115                 :            : {
     116         [ +  - ]:       6978 :     const_iterator it = find( aIndex );
     117 [ +  - ][ -  + ]:       6978 :     if ( it == end() )
     118                 :          0 :         return UNIQUEINDEX_ENTRY_NOTFOUND;
     119         [ +  - ]:       6978 :     ++it;
     120 [ +  - ][ +  + ]:       6978 :     if ( it == end() )
     121                 :       4324 :         return UNIQUEINDEX_ENTRY_NOTFOUND;
     122         [ +  - ]:       6978 :     return it->first;
     123                 :            : }
     124                 :            : 
     125                 :       3008 : sal_uIntPtr UniqueIndexImpl::GetIndexOf(void* p) const
     126                 :            : {
     127 [ +  - ][ +  - ]:       4338 :     for( const_iterator it = begin(); it != end(); ++it )
                 [ +  - ]
     128 [ +  - ][ +  + ]:       4338 :         if( it->second == p )
     129         [ +  - ]:       3008 :             return it->first;
     130                 :       3008 :     return UNIQUEINDEX_ENTRY_NOTFOUND;
     131                 :            : }
     132                 :            : 
     133                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10