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 #ifndef INCLUDED_WW8_BIN_TABLE_IMPL_HXX
25 #define INCLUDED_WW8_BIN_TABLE_IMPL_HXX
26 
27 #include <istream>
28 #include <WW8BinTable.hxx>
29 #include <PLCF.hxx>
30 
31 #include <hash_map>
32 
33 namespace writerfilter {
34 namespace doctok
35 {
36 using namespace ::std;
37 
38 /**
39    A number of a FKP.
40  */
41 class PageNumber
42 {
43     /// the page number
44     sal_uInt32 mnPageNumber;
45 
46 public:
47     /// Pointer to a page number
48     typedef boost::shared_ptr<PageNumber> Pointer_t;
49 
50     /// get size of a page number
getSize()51     static size_t getSize() { return 4; }
52 
PageNumber(WW8StructBase::Sequence & rSeq,sal_uInt32 nOffset,sal_uInt32)53     PageNumber(WW8StructBase::Sequence & rSeq, sal_uInt32 nOffset,
54                sal_uInt32 /*nCount*/)
55     : mnPageNumber(getU32(rSeq, nOffset))
56     {
57     }
58 
59     /// Return the page number
get() const60     sal_uInt32 get() const { return mnPageNumber; }
61 
62     virtual void dump(OutputWithDepth<string> & out) const;
63 };
64 
65 /**
66    Implementation class for a binary table
67  */
68 class WW8BinTableImpl : public WW8BinTable
69 {
70     /// PLCF containing the numbers of the FKPs of the binary table
71     PLCF<PageNumber> mData;
72     mutable hash_map<Fc, sal_uInt32, FcHash> mPageMap;
73 
74 public:
WW8BinTableImpl(WW8Stream & rStream,sal_uInt32 nOffset,sal_uInt32 nCount)75     WW8BinTableImpl(WW8Stream & rStream, sal_uInt32 nOffset,
76                     sal_uInt32 nCount)
77     : mData(rStream, nOffset, nCount)
78 
79     {
80     }
81 
getEntryCount() const82     virtual sal_uInt32 getEntryCount() const
83     { return mData.getEntryCount(); }
getFc(sal_uInt32 nIndex) const84     virtual Fc getFc(sal_uInt32 nIndex) const
85     { return mData.getFc(nIndex); }
getPageNumber(sal_uInt32 nIndex) const86     virtual sal_uInt32 getPageNumber(sal_uInt32 nIndex) const
87     { return mData.getEntry(nIndex)->get(); }
88     virtual sal_uInt32 getPageNumber(const Fc & rFc) const;
89     virtual string toString() const;
90 };
91 
92 }}
93 
94 #endif // INCLUDED_WW8_BIN_TABLE_IMPL_HXX
95