LCOV - code coverage report
Current view: top level - sw/source/filter/ww8 - hash_wrap.hxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 15 15 100.0 %
Date: 2014-04-11 Functions: 3 3 100.0 %
Legend: Lines: hit not hit

          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             : //this is a shameless rip from sortedarray.hxx but changed to boost::unordered_set
      21             : 
      22             : #ifndef INCLUDED_SW_SOURCE_FILTER_WW8_HASH_WRAP_HXX
      23             : #define INCLUDED_SW_SOURCE_FILTER_WW8_HASH_WRAP_HXX
      24             : 
      25             : #include <boost/unordered_set.hpp>
      26             : 
      27             : //simple wrapper around boost::unordered_set to behave like sorted array
      28             : namespace ww
      29             : {
      30             :     /** simple template that manages a hash
      31             : 
      32             :         @author
      33             :         <a href="mailto:mikeleib@openoffice.org">Michael Leibowitz</a>
      34             :     */
      35           7 :     template<class C, class HashFcn = boost::hash<C> > class WrappedHash
      36             :     {
      37             :     private:
      38             :         boost::unordered_set<C, HashFcn> mHashSet;
      39             : 
      40             :         //No copying
      41             :         WrappedHash(const WrappedHash&);
      42             :         WrappedHash& operator=(const WrappedHash&);
      43             :     public:
      44             :         //Find an entry, return its address if found and 0 if not
      45     1356509 :         const C* search(C aSrch) const
      46             :         {
      47     1356509 :             typename boost::unordered_set<C, HashFcn>::const_iterator it;
      48     1356509 :             it= mHashSet.find(aSrch);
      49     1356509 :             if (it != mHashSet.end())
      50     1265518 :                 return &(*it);
      51             :             else
      52       90991 :                 return 0;
      53             :         }
      54             : 
      55           7 :         WrappedHash(const C *pWwSprmTab, const size_t nNoElems)
      56           7 :         {
      57             :             OSL_ENSURE(nNoElems && pWwSprmTab, "WW8: empty Array: Don't do that");
      58           7 :             const C *pIter = pWwSprmTab;
      59           7 :             const C *pEnd  = pWwSprmTab + nNoElems;
      60        1839 :             while (pIter < pEnd)
      61             :             {
      62        1825 :                 mHashSet.insert(*pIter);
      63        1825 :                 pIter++;
      64             :             }
      65             : #if OSL_DEBUG_LEVEL > 1
      66             :             bool bBroken=false;
      67             :             OUString sError;
      68             :             pIter = pWwSprmTab;
      69             :             const C *pBeforeEnd = pWwSprmTab + nNoElems - 1;
      70             :             while (pIter < pBeforeEnd)
      71             :             {
      72             :                 if (*pIter == *(pIter+1))
      73             :                 {
      74             :                     if (!bBroken)
      75             :                     {
      76             :                         sError =
      77             :                             "WW8: Duplicate in list, almost certainly don't "
      78             :                             "want that!\n"
      79             :                             "(You will not see this message again unless you "
      80             :                             "restart)\n"
      81             :                             "Extra entries are...\n";
      82             :                         bBroken=true;
      83             :                     }
      84             : 
      85             :                     size_t nSize = sizeof(C);
      86             :                     const sal_uInt8 *pHack =
      87             :                         reinterpret_cast<const sal_uInt8 *>(&(*pIter));
      88             :                     for (size_t i=0; i < nSize; ++i)
      89             :                     {
      90             :                         sError += OUString::number(
      91             :                             static_cast<sal_Int32>(pHack[i]), 16);
      92             :                         sError += OUString(' ');
      93             :                     }
      94             :                     sError += OUString('\n');
      95             :                     while (*pIter == *(pIter+1) && pIter < pBeforeEnd)
      96             :                         ++pIter;
      97             :                 }
      98             :                 else
      99             :                     ++pIter;
     100             :             }
     101             :             if (bBroken)
     102             :             {
     103             :                OSL_FAIL( OUStringToOString( sError, RTL_TEXTENCODING_ASCII_US ).getStr() );
     104             :             }
     105             : #endif
     106           7 :         }
     107             :     };
     108             : }
     109             : #endif
     110             : 
     111             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10