LibreOffice Module lotuswordpro (master) 1
lwpidxmgr.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*************************************************************************
3 *
4 * The Contents of this file are made available subject to the terms of
5 * either of the following licenses
6 *
7 * - GNU Lesser General Public License Version 2.1
8 * - Sun Industry Standards Source License Version 1.1
9 *
10 * Sun Microsystems Inc., October, 2000
11 *
12 * GNU Lesser General Public License Version 2.1
13 * =============================================
14 * Copyright 2000 by Sun Microsystems, Inc.
15 * 901 San Antonio Road, Palo Alto, CA 94303, USA
16 *
17 * This library is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU Lesser General Public
19 * License version 2.1, as published by the Free Software Foundation.
20 *
21 * This library is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 * Lesser General Public License for more details.
25 *
26 * You should have received a copy of the GNU Lesser General Public
27 * License along with this library; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
29 * MA 02111-1307 USA
30 *
31 *
32 * Sun Industry Standards Source License Version 1.1
33 * =================================================
34 * The contents of this file are subject to the Sun Industry Standards
35 * Source License Version 1.1 (the "License"); You may not use this file
36 * except in compliance with the License. You may obtain a copy of the
37 * License at http://www.openoffice.org/license.html.
38 *
39 * Software provided under this License is provided on an "AS IS" basis,
40 * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
41 * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
42 * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
43 * See the License for the specific provisions governing your rights and
44 * obligations concerning the Software.
45 *
46 * The Initial Developer of the Original Code is: IBM Corporation
47 *
48 * Copyright: 2008 by IBM Corporation
49 *
50 * All Rights Reserved.
51 *
52 * Contributor(s): _______________________________________
53 *
54 *
55 ************************************************************************/
56
57/**********************************************************************************************************************
58 * @file
59 * index manager implementation
60 * Three record types are related with index information, and two ways are used.
61* 1. VO_ROOTOBJINDEX works with one or more VO_LEAFOBJINDEX records to
62* provide the map of all object ids and their offsets.
63* VO_ROOTOBJINDEX includes k (object id, offset) and timetable which is used to map index to actual low id
64 * 2. VO_ROOTLEAFOBJINDEX is used when the file is so small that the number of objects is less than 256(?)
65 * VO_ROOTLEAFOBJINDEX contains directly the (object id, offset) map and time table.
66
67**********************************************************************************************************************/
68
69#include <lwpidxmgr.hxx>
70#include <lwpobjhdr.hxx>
71#include <lwptools.hxx>
72#include <memory>
73
75
77 : m_nKeyCount(0)
78 , m_nLeafCount(0)
79{
81
82}
83
88{
89 //Read index obj
90 LwpObjectHeader ObjHdr;
91 if (!ObjHdr.Read(*pStrm))
92 throw BadRead();
93 std::unique_ptr<LwpObjectStream> xObjStrm(new LwpObjectStream(pStrm, ObjHdr.IsCompressed(),
94 static_cast<sal_uInt16>(ObjHdr.GetSize())));
95
96 if( ObjHdr.GetTag() == VO_ROOTLEAFOBJINDEX )
97 {
98 ReadLeafData(xObjStrm.get());
99 ReadTimeTable(xObjStrm.get());
100 xObjStrm.reset();
101 }
102 else
103 {
104 ReadRootData(xObjStrm.get());
105 xObjStrm.reset();
106
107 for (sal_uInt16 k = 0; k < m_nLeafCount; k++)
108 {
109 //Read leaf
111 if (!pStrm->CheckSeek(nPos))
112 throw BadSeek();
113
114 //Old Code
115 //ReadLeafIndex(pStrm);
116 //New Code
117 ReadObjIndex( pStrm );
118
119 //Read object in root, these objects are between the leaf objects
120 if(k!=m_nLeafCount-1)
121 {
122 m_ObjectKeys.push_back(m_RootObjs[k]);
123 m_nKeyCount ++;
124 }
125 }
126 m_RootObjs.clear();
127 }
128}
129
134{
135
136 sal_uInt16 KeyCount = pObjStrm->QuickReaduInt16();
137 m_nLeafCount = KeyCount ? KeyCount + 1 : 0;
138
140 throw std::range_error("corrupt RootData");
141
142 if (KeyCount)
143 {
144 //read object keys
145 LwpKey akey;
146 akey.id.Read(pObjStrm);
147 m_RootObjs.push_back(akey);
148
149 sal_uInt16 k = 0;
150
151 for (k = 1; k < KeyCount; k++)
152 {
153 akey.id.ReadCompressed(pObjStrm, m_RootObjs[k-1].id);
154 m_RootObjs.push_back(akey);
155 }
156
157 for (k = 0; k < KeyCount; k++)
158 m_RootObjs[k].offset = pObjStrm->QuickReaduInt32();
159
160 //read leaf index offset
161 for (k = 0; k < m_nLeafCount; k++)
162 m_ChildIndex[k] = pObjStrm->QuickReaduInt32();
163 }
164
165 ReadTimeTable(pObjStrm);
166
167}
168
169//Add new method to handle ObjIndex data
174{
175 sal_uInt16 KeyCount = pObjStrm->QuickReaduInt16();
176 sal_uInt16 LeafCount = KeyCount + 1;
177
178 std::vector<LwpKey> vObjIndexs;
179
180 if (KeyCount)
181 {
182 LwpKey akey;
183 akey.id.Read(pObjStrm);
184 vObjIndexs.push_back(akey);
185
186 sal_uInt16 k = 0;
187
188 for (k = 1; k < KeyCount; k++)
189 {
190 akey.id.ReadCompressed(pObjStrm, vObjIndexs[k-1].id);
191 vObjIndexs.push_back(akey);
192 }
193
194 for (k = 0; k < KeyCount; k++)
195 vObjIndexs[k].offset = pObjStrm->QuickReaduInt32();
196
197 for (k = 0; k < LeafCount; k++)
198 m_TempVec.at(k) = pObjStrm->QuickReaduInt32();
199 }
200
201 for( sal_uInt16 j=0; j<LeafCount; j++ )
202 {
203 sal_Int64 nPos = m_TempVec.at(j) + LwpSvStream::LWP_STREAM_BASE;
204 sal_Int64 nActualPos = pObjStrm->GetStream()->Seek(nPos);
205
206 if (nPos != nActualPos)
207 throw BadSeek();
208
209 ReadLeafIndex(pObjStrm->GetStream());
210
211 if(j!=LeafCount-1)
212 {
213 m_ObjectKeys.push_back(vObjIndexs[j]);
214
215 m_nKeyCount ++;
216 }
217 }
218
219 vObjIndexs.clear();
220 m_TempVec.clear();
221}
222
227{
228 LwpObjectHeader ObjHdr;
229 if (!ObjHdr.Read(*pStrm))
230 throw BadRead();
231 LwpObjectStream aObjStrm(pStrm, ObjHdr.IsCompressed(),
232 static_cast<sal_uInt16>(ObjHdr.GetSize()) );
233
234 if( sal_uInt32(VO_OBJINDEX) == ObjHdr.GetTag() )
235 {
236 ReadObjIndexData( &aObjStrm );
237 }
238 else if( sal_uInt32(VO_LEAFOBJINDEX) == ObjHdr.GetTag() )
239 {
240 ReadLeafData( &aObjStrm );
241 }
242}
243
248{
249 LwpObjectHeader ObjHdr;
250 if (!ObjHdr.Read(*pStrm))
251 throw BadRead();
252 LwpObjectStream aObjStrm( pStrm, ObjHdr.IsCompressed(),
253 static_cast<sal_uInt16>(ObjHdr.GetSize()) );
254
255 ReadLeafData(&aObjStrm);
256}
261{
262 sal_uInt16 KeyCount = pObjStrm->QuickReaduInt16();
263
264 if(KeyCount)
265 {
266 LwpKey akey;
267 //read object keys: id & offset
268 akey.id.Read(pObjStrm);
269 m_ObjectKeys.push_back(akey);
270
271 for (sal_uInt16 k = 1; k < KeyCount; k++)
272 {
273 akey.id.ReadCompressed(pObjStrm, m_ObjectKeys.at(m_nKeyCount+k-1).id);
274 m_ObjectKeys.push_back(akey);
275 }
276
277 for (sal_uInt16 j = 0; j < KeyCount; j++)
278 m_ObjectKeys.at(m_nKeyCount+j).offset = pObjStrm->QuickReaduInt32();
279 }
280 m_nKeyCount += KeyCount;
281}
286{
287 sal_uInt16 nTimeCount = pObjStrm->QuickReaduInt16();
288
289 for(sal_uInt16 i=0; i<nTimeCount; ++i)
290 {
291 sal_uInt32 atime = pObjStrm->QuickReaduInt32();
292 m_TimeTable.push_back(atime);
293 }
294}
299{
300
301 //sal_uInt16 L, U, M;
302 sal_uInt32 L, U, M;
303
304 L = 0;
305 U = m_nKeyCount;
306 while (L != U)
307 {
308 M = (L + U) >> 1;
309
310 if (objid.GetLow() > m_ObjectKeys[M].id.GetLow())
311 L = M + 1;
312 else if (objid.GetLow() < m_ObjectKeys[M].id.GetLow())
313 U = M;
314 else if (objid.GetHigh() > m_ObjectKeys[M].id.GetHigh())
315 L = M + 1;
316 else if (objid.GetHigh() < m_ObjectKeys[M].id.GetHigh())
317 U = M;
318 else
319 {
320 return(m_ObjectKeys[M].offset);
321 }
322 }
323 return BAD_OFFSET;
324}
325
326/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uInt32 m_ChildIndex[256]
Definition: lwpidxmgr.hxx:94
static const sal_uInt8 MAXOBJECTIDS
Definition: lwpidxmgr.hxx:85
void ReadLeafIndex(LwpSvStream *pStrm)
@descr Read VO_LEAFOBJINDEX
Definition: lwpidxmgr.cxx:247
sal_uInt16 m_nLeafCount
Definition: lwpidxmgr.hxx:95
void ReadLeafData(LwpObjectStream *pStrm)
@descr Read data in VO_LEAFOBJINDEX
Definition: lwpidxmgr.cxx:260
std::vector< sal_uInt32 > m_TempVec
Definition: lwpidxmgr.hxx:92
void ReadObjIndex(LwpSvStream *pStrm)
@descr Read VO_OBJINDEX
Definition: lwpidxmgr.cxx:226
sal_uInt32 GetObjOffset(LwpObjectID objid)
@descr get object offset per the object id
Definition: lwpidxmgr.cxx:298
std::vector< LwpKey > m_ObjectKeys
Definition: lwpidxmgr.hxx:86
void ReadTimeTable(LwpObjectStream *pStrm)
@descr Read time table in VO_ROOTLEAFOBJINDEX and VO_ROOTOBJINDEX
Definition: lwpidxmgr.cxx:285
std::vector< LwpKey > m_RootObjs
Definition: lwpidxmgr.hxx:87
void Read(LwpSvStream *pStrm)
@descr Read all index records, VO_ROOTLEAFOBJINDEX, VO_ROOTOBJINDEX, VO_LEAFOBJINDEX
Definition: lwpidxmgr.cxx:87
void ReadObjIndexData(LwpObjectStream *pObjStrm)
@descr Read data in VO_OBJINDEX
Definition: lwpidxmgr.cxx:173
sal_uInt32 m_nKeyCount
Definition: lwpidxmgr.hxx:91
void ReadRootData(LwpObjectStream *pObjStrm)
@descr Read data in VO_ROOTOBJINDEX
Definition: lwpidxmgr.cxx:133
std::vector< sal_uInt32 > m_TimeTable
Definition: lwpidxmgr.hxx:88
Base class of all Lwp VO objects.
Definition: lwpobjhdr.hxx:71
bool Read(LwpSvStream &pStrm)
@descr read header from stream
Definition: lwpobjhdr.cxx:74
sal_uInt32 GetTag() const
Definition: lwpobjhdr.hxx:118
bool IsCompressed() const
Definition: lwpobjhdr.hxx:130
sal_uInt32 GetSize() const
Definition: lwpobjhdr.hxx:122
object id class
Definition: lwpobjid.hxx:79
sal_uInt16 GetHigh() const
Definition: lwpobjid.hxx:130
void Read(LwpSvStream *pStrm)
@descr Read object id with format: low(4bytes)+high(2bytes) from stream for LWP7 record
Definition: lwpobjid.cxx:77
void ReadCompressed(LwpObjectStream *pObj, LwpObjectID const &prev)
@descr Read object id with compressed format from object stream if diff == 255: 255+lowid+highid else...
Definition: lwpobjid.cxx:159
sal_uInt32 GetLow() const
Definition: lwpobjid.hxx:125
stream class for LwpObject body data provide stream like interface to read object data
Definition: lwpobjstrm.hxx:77
sal_uInt16 QuickReaduInt16(bool *pFailure=nullptr)
@descr Quick read sal_uInt32
Definition: lwpobjstrm.cxx:200
LwpSvStream * GetStream()
Definition: lwpobjstrm.hxx:124
sal_uInt32 QuickReaduInt32(bool *pFailure=nullptr)
@descr Quick read sal_uInt32
Definition: lwpobjstrm.cxx:189
encapsulate XInputStream to provide SvStream like interfaces
Definition: lwpsvstream.hxx:69
bool CheckSeek(sal_Int64 pos)
static const sal_uInt32 LWP_STREAM_BASE
Definition: lwpsvstream.hxx:84
sal_Int64 Seek(sal_Int64 pos)
@descr Seek to pos
sal_uInt16 nPos
#define BAD_OFFSET
Definition: lwpdefs.hxx:64
@ VO_ROOTLEAFOBJINDEX
Definition: lwpdefs.hxx:174
@ VO_LEAFOBJINDEX
Definition: lwpdefs.hxx:180
@ VO_OBJINDEX
Definition: lwpdefs.hxx:178
#define SAL_N_ELEMENTS(arr)
int i
M
key structure used to map id to offset
Definition: lwpidxmgr.hxx:72
LwpObjectID id
Definition: lwpidxmgr.hxx:73
unsigned char sal_uInt8