1 /*************************************************************************
3 * The Contents of this file are made available subject to the terms of
4 * either of the following licenses
6 * - GNU Lesser General Public License Version 2.1
7 * - Sun Industry Standards Source License Version 1.1
9 * Sun Microsystems Inc., October, 2000
11 * GNU Lesser General Public License Version 2.1
12 * =============================================
13 * Copyright 2000 by Sun Microsystems, Inc.
14 * 901 San Antonio Road, Palo Alto, CA 94303, USA
16 * This library is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU Lesser General Public
18 * License version 2.1, as published by the Free Software Foundation.
20 * This library is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 * Lesser General Public License for more details.
25 * You should have received a copy of the GNU Lesser General Public
26 * License along with this library; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
31 * Sun Industry Standards Source License Version 1.1
32 * =================================================
33 * The contents of this file are subject to the Sun Industry Standards
34 * Source License Version 1.1 (the "License"); You may not use this file
35 * except in compliance with the License. You may obtain a copy of the
36 * License at http://www.openoffice.org/license.html.
38 * Software provided under this License is provided on an "AS IS" basis,
39 * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
40 * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
41 * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
42 * See the License for the specific provisions governing your rights and
43 * obligations concerning the Software.
45 * The Initial Developer of the Original Code is: IBM Corporation
47 * Copyright: 2008 by IBM Corporation
49 * All Rights Reserved.
51 * Contributor(s): _______________________________________
54 ************************************************************************/
55 /**********************************************************************************************************************
57 * index manager implementation
58 * Three record types are related with index information, and two ways are used.
59 * 1. VO_ROOTOBJINDEX works with one or more VO_LEAFOBJINDEX records to
60 * provide the map of all object ids and their offsets.
61 * VO_ROOTOBJINDEX includes k (object id, offset) and timetable which is used to map index to actual low id
62 * 2. VO_ROOTLEAFOBJINDEX is used when the file is so small that the number of objects is less than 256(?)
63 * VO_ROOTLEAFOBJINDEX contains directly the (object id, offset) map and time table.
64 /**********************************************************************************************************************/
65 /**********************************************************************************************************************
68 /**********************************************************************************************************************/
70 #include "lwpidxmgr.hxx"
72 const sal_uInt8
LwpIndexManager::MAXOBJECTIDS
= 255;
74 LwpIndexManager::LwpIndexManager()
75 :m_nKeyCount(0), m_nLeafCount(0)
78 m_TempVec
.resize( LwpIndexManager::MAXOBJECTIDS
);
82 LwpIndexManager::~LwpIndexManager()
85 std::vector
<LwpKey
*>::iterator it
;
87 for( it
= m_ObjectKeys
.begin(); it
!= m_ObjectKeys
.end(); it
++ )
100 * @descr Read all index records, VO_ROOTLEAFOBJINDEX, VO_ROOTOBJINDEX, VO_LEAFOBJINDEX
102 void LwpIndexManager::Read(LwpSvStream
* pStrm
)
105 LwpObjectHeader ObjHdr
;
107 LwpObjectStream
* pObjStrm
= new LwpObjectStream(pStrm
, ObjHdr
.IsCompressed(),
108 static_cast<sal_uInt16
>(ObjHdr
.GetSize()) );
110 if( ObjHdr
.GetTag() == VO_ROOTLEAFOBJINDEX
)
112 ReadLeafData(pObjStrm
);
113 ReadTimeTable(pObjStrm
);
118 ReadRootData(pObjStrm
);
121 for (sal_uInt16 k
= 0; k
< m_nLeafCount
; k
++)
124 pStrm
->Seek(m_ChildIndex
[k
]+LwpSvStream::LWP_STREAM_BASE
);
128 //ReadLeafIndex(pStrm);
130 ReadObjIndex( pStrm
);
133 //Read object in root, these objects are between the leaf objects
134 if(k
!=m_nLeafCount
-1)
136 m_ObjectKeys
.push_back(m_RootObjs
[k
]);
145 * @descr Read data in VO_ROOTOBJINDEX
147 void LwpIndexManager::ReadRootData(LwpObjectStream
* pObjStrm
)
150 sal_uInt16 KeyCount
= 0;
151 pObjStrm
->QuickRead(&KeyCount
, sizeof(KeyCount
));
152 m_nLeafCount
= KeyCount
+ 1;
157 LwpKey
* akey
= new LwpKey();
158 akey
->id
.Read(pObjStrm
);
159 m_RootObjs
.push_back(akey
);
165 for (k
= 1; k
< KeyCount
; k
++)
168 akey
->id
.ReadCompressed(pObjStrm
, m_RootObjs
[k
-1]->id
);
169 m_RootObjs
.push_back(akey
);
172 for (k
= 0; k
< KeyCount
; k
++)
174 pObjStrm
->QuickRead(&(m_RootObjs
[k
]->offset
), sizeof(sal_uInt32
));
177 //read leaf index offset
178 for (k
= 0; k
< m_nLeafCount
; k
++)
180 pObjStrm
->QuickRead(&(m_ChildIndex
[k
]), sizeof(sal_uInt32
));
184 ReadTimeTable(pObjStrm
);
189 //Add new method to handle ObjIndex data
191 * @descr Read data in VO_OBJINDEX
193 void LwpIndexManager::ReadObjIndexData(LwpObjectStream
* pObjStrm
)
195 sal_uInt16 KeyCount
= 0;
196 sal_uInt16 LeafCount
= 0;
197 pObjStrm
->QuickRead(&KeyCount
, sizeof(KeyCount
));
198 LeafCount
= KeyCount
+ 1;
200 std::vector
<LwpKey
*> vObjIndexs
;
204 LwpKey
* akey
= new LwpKey();
205 akey
->id
.Read(pObjStrm
);
206 vObjIndexs
.push_back(akey
);
210 for (k
= 1; k
< KeyCount
; k
++)
213 akey
->id
.ReadCompressed(pObjStrm
, vObjIndexs
[k
-1]->id
);
214 vObjIndexs
.push_back(akey
);
217 for (k
= 0; k
< KeyCount
; k
++)
218 pObjStrm
->QuickRead(&(vObjIndexs
[k
]->offset
), sizeof(sal_uInt32
));
220 for (k
= 0; k
< LeafCount
; k
++)
221 pObjStrm
->QuickRead(&(m_TempVec
[k
]), sizeof(sal_uInt32
));
224 for( sal_uInt16 j
=0; j
<LeafCount
; j
++ )
226 pObjStrm
->GetStream()->Seek( m_TempVec
[j
]+LwpSvStream::LWP_STREAM_BASE
);
227 ReadLeafIndex(pObjStrm
->GetStream());
231 m_ObjectKeys
.push_back(vObjIndexs
[j
]);
243 * @descr Read VO_OBJINDEX
245 void LwpIndexManager::ReadObjIndex( LwpSvStream
*pStrm
)
248 LwpObjectHeader ObjHdr
;
250 LwpObjectStream
* pObjStrm
= new LwpObjectStream(pStrm
, ObjHdr
.IsCompressed(),
251 static_cast<sal_uInt16
>(ObjHdr
.GetSize()) );
253 if( (sal_uInt32
)VO_OBJINDEX
== ObjHdr
.GetTag() )
255 ReadObjIndexData( pObjStrm
);
257 else if( (sal_uInt32
)VO_LEAFOBJINDEX
== ObjHdr
.GetTag() )
259 ReadLeafData(pObjStrm
);
267 * @descr Read VO_LEAFOBJINDEX
269 void LwpIndexManager::ReadLeafIndex( LwpSvStream
*pStrm
)
271 LwpObjectHeader ObjHdr
;
273 LwpObjectStream
* pObjStrm
= new LwpObjectStream(pStrm
, ObjHdr
.IsCompressed(),
274 static_cast<sal_uInt16
>(ObjHdr
.GetSize()) );
276 ReadLeafData(pObjStrm
);
281 * @descr Read data in VO_LEAFOBJINDEX
283 void LwpIndexManager::ReadLeafData( LwpObjectStream
*pObjStrm
)
286 pObjStrm
->QuickRead(&KeyCount
, sizeof(KeyCount
));
290 LwpKey
* akey
= new LwpKey();
291 //read object keys: id & offset
292 akey
->id
.Read(pObjStrm
);
293 m_ObjectKeys
.push_back(akey
);
295 for (sal_uInt8 k
= 1; k
< KeyCount
; k
++)
298 akey
->id
.ReadCompressed(pObjStrm
, m_ObjectKeys
[m_nKeyCount
+k
-1]->id
);
299 m_ObjectKeys
.push_back(akey
);
302 for (sal_uInt8 j
= 0; j
< KeyCount
; j
++)
304 pObjStrm
->QuickRead(&(m_ObjectKeys
[m_nKeyCount
+j
]->offset
), sizeof(sal_uInt32
));
307 m_nKeyCount
+= KeyCount
;
310 * @descr Read time table in VO_ROOTLEAFOBJINDEX and VO_ROOTOBJINDEX
312 void LwpIndexManager::ReadTimeTable(LwpObjectStream
*pObjStrm
)
314 sal_uInt16 nTimeCount
;
315 pObjStrm
->QuickRead(&nTimeCount
, sizeof(nTimeCount
));
318 for(sal_uInt16 i
=0; i
<nTimeCount
; i
++)
320 pObjStrm
->QuickRead( &atime
, sizeof(atime
) );
321 m_TimeTable
.push_back(atime
);
325 * @descr get object offset per the object id
327 sal_uInt32
LwpIndexManager::GetObjOffset( LwpObjectID objid
)
330 //sal_uInt16 L, U, M;
340 if (objid
.GetLow() > m_ObjectKeys
[M
]->id
.GetLow())
342 else if (objid
.GetLow() < m_ObjectKeys
[M
]->id
.GetLow())
344 else if (objid
.GetHigh() > m_ObjectKeys
[M
]->id
.GetHigh())
346 else if (objid
.GetHigh() < m_ObjectKeys
[M
]->id
.GetHigh())
350 return(m_ObjectKeys
[M
]->offset
);