LCOV - code coverage report
Current view: top level - libreoffice/sw/source/filter/ww8 - hash_wrap.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 15 15 100.0 %
Date: 2012-12-17 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 WW_HASH_WRAP_HXX
      23             : #define WW_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             : 
      33             :         @author
      34             :         <a href="mailto:mikeleib@openoffice.org">Michael Leibowitz</a>
      35             :     */
      36           8 :     template<class C, class HashFcn = boost::hash<C> > class WrappedHash
      37             :     {
      38             :     private:
      39             :         boost::unordered_set<C, HashFcn> mHashSet;
      40             : 
      41             :         //No copying
      42             :         WrappedHash(const WrappedHash&);
      43             :         WrappedHash& operator=(const WrappedHash&);
      44             :     public:
      45             :         //Find an entry, return its address if found and 0 if not
      46     1421906 :         const C* search(C aSrch) const
      47             :         {
      48     1421906 :             typename boost::unordered_set<C, HashFcn>::const_iterator it;
      49     1421906 :             it= mHashSet.find(aSrch);
      50     1421906 :             if (it != mHashSet.end())
      51     1334026 :                 return &(*it);
      52             :             else
      53       87880 :                 return 0;
      54             :         }
      55             : 
      56           8 :         WrappedHash(const C *pWwSprmTab, const size_t nNoElems)
      57           8 :         {
      58             :             OSL_ENSURE(nNoElems && pWwSprmTab, "WW8: empty Array: Don't do that");
      59           8 :             const C *pIter = pWwSprmTab;
      60           8 :             const C *pEnd  = pWwSprmTab + nNoElems;
      61        2256 :             while (pIter < pEnd)
      62             :             {
      63        2240 :                 mHashSet.insert(*pIter);
      64        2240 :                 pIter++;
      65             :             }
      66             : #if OSL_DEBUG_LEVEL > 1
      67             :             bool bBroken=false;
      68             :             rtl::OUString sError;
      69             :             pIter = pWwSprmTab;
      70             :             const C *pBeforeEnd = pWwSprmTab + nNoElems - 1;
      71             :             while (pIter < pBeforeEnd)
      72             :             {
      73             :                 if (*pIter == *(pIter+1))
      74             :                 {
      75             :                     if (!bBroken)
      76             :                     {
      77             :                         sError =
      78             :                             "WW8: Duplicate in list, almost certainly don't "
      79             :                             "want that!\n"
      80             :                             "(You will not see this message again unless you "
      81             :                             "restart)\n"
      82             :                             "Extra entries are...\n";
      83             :                         bBroken=true;
      84             :                     }
      85             : 
      86             :                     size_t nSize = sizeof(C);
      87             :                     const sal_uInt8 *pHack =
      88             :                         reinterpret_cast<const sal_uInt8 *>(&(*pIter));
      89             :                     for (size_t i=0; i < nSize; ++i)
      90             :                     {
      91             :                         sError += rtl::OUString::valueOf(
      92             :                             static_cast<sal_Int32>(pHack[i]), 16);
      93             :                         sError += rtl::OUString::valueOf(sal_Unicode(' '));
      94             :                     }
      95             :                     sError += rtl::OUString::valueOf(sal_Unicode('\n'));
      96             :                     while (*pIter == *(pIter+1) && pIter < pBeforeEnd)
      97             :                         ++pIter;
      98             :                 }
      99             :                 else
     100             :                     ++pIter;
     101             :             }
     102             :             if (bBroken)
     103             :             {
     104             :                OSL_FAIL( rtl::OUStringToOString( sError, RTL_TEXTENCODING_ASCII_US ).getStr() );
     105             :             }
     106             : #endif
     107           8 :         }
     108             :     };
     109             : }
     110             : #endif
     111             : 
     112             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10