1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include "WW8BinTableImpl.hxx"
25 
26 namespace writerfilter {
27 namespace doctok
28 {
29 using namespace ::std;
30 
dump(OutputWithDepth<string> &) const31 void PageNumber::dump(OutputWithDepth<string> & /*output*/) const
32 {
33 }
34 
getPageNumber(const Fc & rFc) const35 sal_uInt32 WW8BinTableImpl::getPageNumber(const Fc & rFc) const
36 {
37     sal_uInt32 nResult = 0;
38 
39     if (mPageMap.find(rFc) == mPageMap.end())
40     {
41 #if 0
42         sal_uInt32 n = getEntryCount();
43 
44         while (rFc < getFc(n))
45         {
46             --n;
47         }
48 
49         nResult = getPageNumber(n);
50         mPageMap[rFc] = nResult;
51 #else
52         sal_uInt32 left = 0;
53         sal_uInt32 right = getEntryCount();
54 
55         while (right - left > 1)
56         {
57             sal_uInt32 middle = (right + left) / 2;
58 
59             Fc aFc = getFc(middle);
60 
61             if (rFc < aFc)
62                 right = middle;
63             else
64                 left = middle;
65 
66         }
67 
68         nResult = getPageNumber(left);
69         mPageMap[rFc] = nResult;
70 #endif
71 
72     }
73     else
74         nResult = mPageMap[rFc];
75 
76     return nResult;
77 }
78 
toString() const79 string WW8BinTableImpl::toString() const
80 {
81     string aResult;
82     char sBuffer[255];
83 
84     aResult += "(";
85 
86     for (sal_uInt32 n = 0; n < getEntryCount(); n++)
87     {
88         if (n > 0)
89             aResult += ", ";
90 
91         snprintf(sBuffer, 255, "%" SAL_PRIxUINT32, getFc(n).get());
92         aResult += sBuffer;
93         aResult += "->";
94         snprintf(sBuffer, 255, "%" SAL_PRIxUINT32, getPageNumber(n));
95         aResult += sBuffer;
96     }
97 
98     aResult += ")";
99 
100     return aResult;
101 }
102 }}
103