1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #include "WW8BinTableImpl.hxx" 29 30 namespace writerfilter { 31 namespace doctok 32 { 33 using namespace ::std; 34 35 void PageNumber::dump(OutputWithDepth<string> & /*output*/) const 36 { 37 } 38 39 sal_uInt32 WW8BinTableImpl::getPageNumber(const Fc & rFc) const 40 { 41 sal_uInt32 nResult = 0; 42 43 if (mPageMap.find(rFc) == mPageMap.end()) 44 { 45 #if 0 46 sal_uInt32 n = getEntryCount(); 47 48 while (rFc < getFc(n)) 49 { 50 --n; 51 } 52 53 nResult = getPageNumber(n); 54 mPageMap[rFc] = nResult; 55 #else 56 sal_uInt32 left = 0; 57 sal_uInt32 right = getEntryCount(); 58 59 while (right - left > 1) 60 { 61 sal_uInt32 middle = (right + left) / 2; 62 63 Fc aFc = getFc(middle); 64 65 if (rFc < aFc) 66 right = middle; 67 else 68 left = middle; 69 70 } 71 72 nResult = getPageNumber(left); 73 mPageMap[rFc] = nResult; 74 #endif 75 76 } 77 else 78 nResult = mPageMap[rFc]; 79 80 return nResult; 81 } 82 83 string WW8BinTableImpl::toString() const 84 { 85 string aResult; 86 char sBuffer[255]; 87 88 aResult += "("; 89 90 for (sal_uInt32 n = 0; n < getEntryCount(); n++) 91 { 92 if (n > 0) 93 aResult += ", "; 94 95 snprintf(sBuffer, 255, "%" SAL_PRIxUINT32, getFc(n).get()); 96 aResult += sBuffer; 97 aResult += "->"; 98 snprintf(sBuffer, 255, "%" SAL_PRIxUINT32, getPageNumber(n)); 99 aResult += sBuffer; 100 } 101 102 aResult += ")"; 103 104 return aResult; 105 } 106 }} 107