diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2014-04-17 12:09:50 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2014-04-17 13:59:51 +0200 |
commit | a0656ed3386a071ee43440ee870a90d7a1fe7fa7 (patch) | |
tree | bef918bcc1fe555c8e0d9e6bb05b711f7e6ac214 /sw | |
parent | 892ba2c5bafb237f150598cc35f9776dffbdca69 (diff) |
Simplify wwSprmSearcher
Change-Id: I1642556f507af9db722dadda707ae11b4080fcf0
Diffstat (limited to 'sw')
-rw-r--r-- | sw/source/filter/ww8/hash_wrap.hxx | 111 | ||||
-rw-r--r-- | sw/source/filter/ww8/ww8par.cxx | 1 | ||||
-rw-r--r-- | sw/source/filter/ww8/ww8scan.cxx | 81 | ||||
-rw-r--r-- | sw/source/filter/ww8/ww8scan.hxx | 26 |
4 files changed, 60 insertions, 159 deletions
diff --git a/sw/source/filter/ww8/hash_wrap.hxx b/sw/source/filter/ww8/hash_wrap.hxx deleted file mode 100644 index a07dd66da62b..000000000000 --- a/sw/source/filter/ww8/hash_wrap.hxx +++ /dev/null @@ -1,111 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -//this is a shameless rip from sortedarray.hxx but changed to boost::unordered_set - -#ifndef INCLUDED_SW_SOURCE_FILTER_WW8_HASH_WRAP_HXX -#define INCLUDED_SW_SOURCE_FILTER_WW8_HASH_WRAP_HXX - -#include <boost/unordered_set.hpp> - -//simple wrapper around boost::unordered_set to behave like sorted array -namespace ww -{ - /** simple template that manages a hash - - @author - <a href="mailto:mikeleib@openoffice.org">Michael Leibowitz</a> - */ - template<class C, class HashFcn = boost::hash<C> > class WrappedHash - { - private: - boost::unordered_set<C, HashFcn> mHashSet; - - //No copying - WrappedHash(const WrappedHash&); - WrappedHash& operator=(const WrappedHash&); - public: - //Find an entry, return its address if found and 0 if not - const C* search(C aSrch) const - { - typename boost::unordered_set<C, HashFcn>::const_iterator it; - it= mHashSet.find(aSrch); - if (it != mHashSet.end()) - return &(*it); - else - return 0; - } - - WrappedHash(const C *pWwSprmTab, const size_t nNoElems) - { - OSL_ENSURE(nNoElems && pWwSprmTab, "WW8: empty Array: Don't do that"); - const C *pIter = pWwSprmTab; - const C *pEnd = pWwSprmTab + nNoElems; - while (pIter < pEnd) - { - mHashSet.insert(*pIter); - pIter++; - } -#if OSL_DEBUG_LEVEL > 1 - bool bBroken=false; - OUString sError; - pIter = pWwSprmTab; - const C *pBeforeEnd = pWwSprmTab + nNoElems - 1; - while (pIter < pBeforeEnd) - { - if (*pIter == *(pIter+1)) - { - if (!bBroken) - { - sError = - "WW8: Duplicate in list, almost certainly don't " - "want that!\n" - "(You will not see this message again unless you " - "restart)\n" - "Extra entries are...\n"; - bBroken=true; - } - - size_t nSize = sizeof(C); - const sal_uInt8 *pHack = - reinterpret_cast<const sal_uInt8 *>(&(*pIter)); - for (size_t i=0; i < nSize; ++i) - { - sError += OUString::number( - static_cast<sal_Int32>(pHack[i]), 16); - sError += OUString(' '); - } - sError += OUString('\n'); - while (*pIter == *(pIter+1) && pIter < pBeforeEnd) - ++pIter; - } - else - ++pIter; - } - if (bBroken) - { - OSL_FAIL( OUStringToOString( sError, RTL_TEXTENCODING_ASCII_US ).getStr() ); - } -#endif - } - }; -} -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/filter/ww8/ww8par.cxx b/sw/source/filter/ww8/ww8par.cxx index ba99b4f70bf0..8f4927df228d 100644 --- a/sw/source/filter/ww8/ww8par.cxx +++ b/sw/source/filter/ww8/ww8par.cxx @@ -20,6 +20,7 @@ #include <sal/config.h> #include <boost/noncopyable.hpp> +#include <boost/unordered_set.hpp> #include <com/sun/star/embed/ElementModes.hpp> #include <i18nlangtag/languagetag.hxx> diff --git a/sw/source/filter/ww8/ww8scan.cxx b/sw/source/filter/ww8/ww8scan.cxx index f2711945cd19..cfa95f05dc74 100644 --- a/sw/source/filter/ww8/ww8scan.cxx +++ b/sw/source/filter/ww8/ww8scan.cxx @@ -105,11 +105,6 @@ namespace } } -inline bool operator==(const SprmInfo &rFirst, const SprmInfo &rSecond) -{ - return (rFirst.nId == rSecond.nId); -} - const wwSprmSearcher *wwSprmParser::GetWW2SprmSearcher() { //double lock me @@ -800,53 +795,47 @@ wwSprmParser::wwSprmParser(ww::WordVersion eVersion) : meVersion(eVersion) SprmInfo wwSprmParser::GetSprmInfo(sal_uInt16 nId) const { - // Find sprm - SprmInfo aSrch={0,0,0}; - aSrch.nId = nId; - const SprmInfo* pFound = mpKnownSprms->search(aSrch); - if (pFound == 0) + const SprmInfo* pFound = mpKnownSprms->search(nId); + if (pFound != 0) { - OSL_ENSURE(ww::IsEightPlus(meVersion), - "Unknown ww7- sprm, dangerous, report to development"); + return *pFound; + } - aSrch.nId = 0; - aSrch.nLen = 0; - //All the unknown ww7 sprms appear to be variable (which makes sense) - aSrch.nVari = L_VAR; + OSL_ENSURE(ww::IsEightPlus(meVersion), + "Unknown ww7- sprm, dangerous, report to development"); - if (ww::IsEightPlus(meVersion)) //We can recover perfectly in this case + //All the unknown ww7 sprms appear to be variable (which makes sense) + SprmInfo aSrch = { nId, 0, L_VAR }; + if (ww::IsEightPlus(meVersion)) //We can recover perfectly in this case + { + aSrch.nVari = L_FIX; + switch (nId >> 13) { - aSrch.nVari = L_FIX; - switch (nId >> 13) - { - case 0: - case 1: - aSrch.nLen = 1; - break; - case 2: - aSrch.nLen = 2; - break; - case 3: - aSrch.nLen = 4; - break; - case 4: - case 5: - aSrch.nLen = 2; - break; - case 6: - aSrch.nLen = 0; - aSrch.nVari = L_VAR; - break; - case 7: - default: - aSrch.nLen = 3; - break; - } + case 0: + case 1: + aSrch.nLen = 1; + break; + case 2: + aSrch.nLen = 2; + break; + case 3: + aSrch.nLen = 4; + break; + case 4: + case 5: + aSrch.nLen = 2; + break; + case 6: + aSrch.nLen = 0; + aSrch.nVari = L_VAR; + break; + case 7: + default: + aSrch.nLen = 3; + break; } - - pFound = &aSrch; } - return *pFound; + return aSrch; } //-end diff --git a/sw/source/filter/ww8/ww8scan.hxx b/sw/source/filter/ww8/ww8scan.hxx index 9538447d4701..5eb2ebe28cb5 100644 --- a/sw/source/filter/ww8/ww8scan.hxx +++ b/sw/source/filter/ww8/ww8scan.hxx @@ -23,14 +23,17 @@ #ifndef LONG_MAX #include <limits.h> #endif +#include <cassert> +#include <cstddef> #include <stack> #include <vector> #include <list> #include <algorithm> + +#include <boost/unordered_map.hpp> #include <tools/solar.h> #include <tools/stream.hxx> #include <rtl/ustring.hxx> -#include "hash_wrap.hxx" #include "sortedarray.hxx" #include "ww8struc.hxx" @@ -70,7 +73,26 @@ struct SprmInfoHash } }; -typedef ww::WrappedHash<SprmInfo, SprmInfoHash> wwSprmSearcher; +class wwSprmSearcher { +public: + wwSprmSearcher(SprmInfo const * infos, std::size_t size) { + for (std::size_t i = 0; i != size; ++i) { + bool ins = map_.insert(Map::value_type(infos[i].nId, infos[i])) + .second; + assert(ins); (void) ins; + } + } + + SprmInfo const * search(sal_uInt16 id) const { + Map::const_iterator i(map_.find(id)); + return i == map_.end() ? 0 : &i->second; + } + +private: + typedef boost::unordered_map<sal_uInt16, SprmInfo> Map; + + Map map_; +}; /** wwSprmParser knows how to take a sequence of bytes and split it up into |