LCOV - code coverage report
Current view: top level - sw/source/filter/ww8 - hash_wrap.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 15 15 100.0 %
Date: 2012-08-25 Functions: 3 3 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 8 12 66.7 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : //this is a shameless rip from sortedarray.hxx but changed to boost::unordered_set
      30                 :            : 
      31                 :            : #ifndef WW_HASH_WRAP_HXX
      32                 :            : #define WW_HASH_WRAP_HXX
      33                 :            : 
      34                 :            : #include <boost/unordered_set.hpp>
      35                 :            : 
      36                 :            : //simple wrapper around boost::unordered_set to behave like sorted array
      37                 :            : namespace ww
      38                 :            : {
      39                 :            :     /** simple template that manages a hash
      40                 :            : 
      41                 :            : 
      42                 :            :         @author
      43                 :            :         <a href="mailto:mikeleib@openoffice.org">Michael Leibowitz</a>
      44                 :            :     */
      45                 :         12 :     template<class C, class HashFcn = boost::hash<C> > class WrappedHash
      46                 :            :     {
      47                 :            :     private:
      48                 :            :         boost::unordered_set<C, HashFcn> mHashSet;
      49                 :            : 
      50                 :            :         //No copying
      51                 :            :         WrappedHash(const WrappedHash&);
      52                 :            :         WrappedHash& operator=(const WrappedHash&);
      53                 :            :     public:
      54                 :            :         //Find an entry, return its address if found and 0 if not
      55                 :     745425 :         const C* search(C aSrch) const
      56                 :            :         {
      57                 :     745425 :             typename boost::unordered_set<C, HashFcn>::const_iterator it;
      58         [ +  - ]:     745425 :             it= mHashSet.find(aSrch);
      59         [ +  + ]:     745425 :             if (it != mHashSet.end())
      60         [ +  - ]:     703323 :                 return &(*it);
      61                 :            :             else
      62                 :     745425 :                 return 0;
      63                 :            :         }
      64                 :            : 
      65                 :         12 :         WrappedHash(const C *pWwSprmTab, const size_t nNoElems)
      66         [ +  - ]:         12 :         {
      67                 :            :             OSL_ENSURE(nNoElems && pWwSprmTab, "WW8: empty Array: Don't do that");
      68                 :         12 :             const C *pIter = pWwSprmTab;
      69                 :         12 :             const C *pEnd  = pWwSprmTab + nNoElems;
      70         [ +  + ]:       3372 :             while (pIter < pEnd)
      71                 :            :             {
      72         [ +  - ]:       3360 :                 mHashSet.insert(*pIter);
      73                 :       3360 :                 pIter++;
      74                 :            :             }
      75                 :            : #if OSL_DEBUG_LEVEL > 1
      76                 :            :             bool bBroken=false;
      77                 :            :             rtl::OUString sError;
      78                 :            :             pIter = pWwSprmTab;
      79                 :            :             const C *pBeforeEnd = pWwSprmTab + nNoElems - 1;
      80                 :            :             while (pIter < pBeforeEnd)
      81                 :            :             {
      82                 :            :                 if (*pIter == *(pIter+1))
      83                 :            :                 {
      84                 :            :                     if (!bBroken)
      85                 :            :                     {
      86                 :            :                         sError =
      87                 :            :                             "WW8: Duplicate in list, almost certainly don't "
      88                 :            :                             "want that!\n"
      89                 :            :                             "(You will not see this message again unless you "
      90                 :            :                             "restart)\n"
      91                 :            :                             "Extra entries are...\n";
      92                 :            :                         bBroken=true;
      93                 :            :                     }
      94                 :            : 
      95                 :            :                     size_t nSize = sizeof(C);
      96                 :            :                     const sal_uInt8 *pHack =
      97                 :            :                         reinterpret_cast<const sal_uInt8 *>(&(*pIter));
      98                 :            :                     for (size_t i=0; i < nSize; ++i)
      99                 :            :                     {
     100                 :            :                         sError += rtl::OUString::valueOf(
     101                 :            :                             static_cast<sal_Int32>(pHack[i]), 16);
     102                 :            :                         sError += rtl::OUString::valueOf(sal_Unicode(' '));
     103                 :            :                     }
     104                 :            :                     sError += rtl::OUString::valueOf(sal_Unicode('\n'));
     105                 :            :                     while (*pIter == *(pIter+1) && pIter < pBeforeEnd)
     106                 :            :                         ++pIter;
     107                 :            :                 }
     108                 :            :                 else
     109                 :            :                     ++pIter;
     110                 :            :             }
     111                 :            :             if (bBroken)
     112                 :            :             {
     113                 :            :                OSL_FAIL( rtl::OUStringToOString( sError, RTL_TEXTENCODING_ASCII_US ).getStr() );
     114                 :            :             }
     115                 :            : #endif
     116                 :         12 :         }
     117                 :            :     };
     118                 :            : }
     119                 :            : #endif
     120                 :            : 
     121                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10