1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * The Contents of this file are made available subject to the terms of
5 * either of the following licenses
7 * - GNU Lesser General Public License Version 2.1
8 * - Sun Industry Standards Source License Version 1.1
10 * Sun Microsystems Inc., October, 2000
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
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.
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.
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,
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.
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.
46 * The Initial Developer of the Original Code is: IBM Corporation
48 * Copyright: 2008 by IBM Corporation
50 * All Rights Reserved.
52 * Contributor(s): _______________________________________
55 ************************************************************************/
57 /**********************************************************************************************************************
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.
69 **********************************************************************************************************************/
71 #include "lwpidxmgr.hxx"
72 #include "lwptools.hxx"
74 const sal_uInt8
LwpIndexManager::MAXOBJECTIDS
= 255;
76 LwpIndexManager::LwpIndexManager()
77 :m_nKeyCount(0), m_nLeafCount(0)
80 m_TempVec
.resize( LwpIndexManager::MAXOBJECTIDS
);
84 LwpIndexManager::~LwpIndexManager()
87 std::vector
<LwpKey
*>::iterator it
;
89 for( it
= m_ObjectKeys
.begin(); it
!= m_ObjectKeys
.end(); ++it
)
102 * @descr Read all index records, VO_ROOTLEAFOBJINDEX, VO_ROOTOBJINDEX, VO_LEAFOBJINDEX
104 void LwpIndexManager::Read(LwpSvStream
* pStrm
)
107 LwpObjectHeader ObjHdr
;
109 LwpObjectStream
* pObjStrm
= new LwpObjectStream(pStrm
, ObjHdr
.IsCompressed(),
110 static_cast<sal_uInt16
>(ObjHdr
.GetSize()) );
112 if( ObjHdr
.GetTag() == VO_ROOTLEAFOBJINDEX
)
114 ReadLeafData(pObjStrm
);
115 ReadTimeTable(pObjStrm
);
120 ReadRootData(pObjStrm
);
123 for (sal_uInt16 k
= 0; k
< m_nLeafCount
; k
++)
126 sal_Int64 nPos
= m_ChildIndex
[k
]+LwpSvStream::LWP_STREAM_BASE
;
127 sal_Int64 nActualPos
= pStrm
->Seek(nPos
);
129 if (nPos
!= nActualPos
)
133 //ReadLeafIndex(pStrm);
135 ReadObjIndex( pStrm
);
137 //Read object in root, these objects are between the leaf objects
138 if(k
!=m_nLeafCount
-1)
140 m_ObjectKeys
.push_back(m_RootObjs
[k
]);
149 * @descr Read data in VO_ROOTOBJINDEX
151 void LwpIndexManager::ReadRootData(LwpObjectStream
* pObjStrm
)
154 sal_uInt16 KeyCount
= pObjStrm
->QuickReaduInt16();
155 m_nLeafCount
= KeyCount
? KeyCount
+ 1 : 0;
160 LwpKey
* akey
= new LwpKey();
161 akey
->id
.Read(pObjStrm
);
162 m_RootObjs
.push_back(akey
);
166 for (k
= 1; k
< KeyCount
; k
++)
169 akey
->id
.ReadCompressed(pObjStrm
, m_RootObjs
[k
-1]->id
);
170 m_RootObjs
.push_back(akey
);
173 for (k
= 0; k
< KeyCount
; k
++)
174 m_RootObjs
[k
]->offset
= pObjStrm
->QuickReaduInt32();
176 //read leaf index offset
177 for (k
= 0; k
< m_nLeafCount
; k
++)
178 m_ChildIndex
[k
] = pObjStrm
->QuickReaduInt32();
181 ReadTimeTable(pObjStrm
);
185 //Add new method to handle ObjIndex data
187 * @descr Read data in VO_OBJINDEX
189 void LwpIndexManager::ReadObjIndexData(LwpObjectStream
* pObjStrm
)
191 sal_uInt16 KeyCount
= pObjStrm
->QuickReaduInt16();
192 sal_uInt16 LeafCount
= KeyCount
+ 1;
194 std::vector
<LwpKey
*> vObjIndexs
;
198 LwpKey
* akey
= new LwpKey();
199 akey
->id
.Read(pObjStrm
);
200 vObjIndexs
.push_back(akey
);
204 for (k
= 1; k
< KeyCount
; k
++)
207 akey
->id
.ReadCompressed(pObjStrm
, vObjIndexs
[k
-1]->id
);
208 vObjIndexs
.push_back(akey
);
211 for (k
= 0; k
< KeyCount
; k
++)
212 vObjIndexs
[k
]->offset
= pObjStrm
->QuickReaduInt32();
214 for (k
= 0; k
< LeafCount
; k
++)
215 m_TempVec
[k
] = pObjStrm
->QuickReaduInt32();
218 for( sal_uInt16 j
=0; j
<LeafCount
; j
++ )
220 sal_Int64 nPos
= m_TempVec
[j
]+LwpSvStream::LWP_STREAM_BASE
;
221 sal_Int64 nActualPos
= pObjStrm
->GetStream()->Seek(nPos
);
223 if (nPos
!= nActualPos
)
226 ReadLeafIndex(pObjStrm
->GetStream());
230 m_ObjectKeys
.push_back(vObjIndexs
[j
]);
241 * @descr Read VO_OBJINDEX
243 void LwpIndexManager::ReadObjIndex( LwpSvStream
*pStrm
)
246 LwpObjectHeader ObjHdr
;
248 LwpObjectStream
* pObjStrm
= new LwpObjectStream(pStrm
, ObjHdr
.IsCompressed(),
249 static_cast<sal_uInt16
>(ObjHdr
.GetSize()) );
251 if( (sal_uInt32
)VO_OBJINDEX
== ObjHdr
.GetTag() )
253 ReadObjIndexData( pObjStrm
);
255 else if( (sal_uInt32
)VO_LEAFOBJINDEX
== ObjHdr
.GetTag() )
257 ReadLeafData(pObjStrm
);
264 * @descr Read VO_LEAFOBJINDEX
266 void LwpIndexManager::ReadLeafIndex( LwpSvStream
*pStrm
)
268 LwpObjectHeader ObjHdr
;
270 LwpObjectStream
* pObjStrm
= new LwpObjectStream(pStrm
, ObjHdr
.IsCompressed(),
271 static_cast<sal_uInt16
>(ObjHdr
.GetSize()) );
273 ReadLeafData(pObjStrm
);
278 * @descr Read data in VO_LEAFOBJINDEX
280 void LwpIndexManager::ReadLeafData( LwpObjectStream
*pObjStrm
)
282 sal_uInt16 KeyCount
= pObjStrm
->QuickReaduInt16();
286 LwpKey
* akey
= new LwpKey();
287 //read object keys: id & offset
288 akey
->id
.Read(pObjStrm
);
289 m_ObjectKeys
.push_back(akey
);
291 for (sal_uInt8 k
= 1; k
< KeyCount
; k
++)
294 akey
->id
.ReadCompressed(pObjStrm
, m_ObjectKeys
.at(m_nKeyCount
+k
-1)->id
);
295 m_ObjectKeys
.push_back(akey
);
298 for (sal_uInt8 j
= 0; j
< KeyCount
; j
++)
299 m_ObjectKeys
.at(m_nKeyCount
+j
)->offset
= pObjStrm
->QuickReaduInt32();
301 m_nKeyCount
+= KeyCount
;
304 * @descr Read time table in VO_ROOTLEAFOBJINDEX and VO_ROOTOBJINDEX
306 void LwpIndexManager::ReadTimeTable(LwpObjectStream
*pObjStrm
)
308 sal_uInt16 nTimeCount
= pObjStrm
->QuickReaduInt16();
310 for(sal_uInt16 i
=0; i
<nTimeCount
; ++i
)
312 sal_uInt32 atime
= pObjStrm
->QuickReaduInt32();
313 m_TimeTable
.push_back(atime
);
317 * @descr get object offset per the object id
319 sal_uInt32
LwpIndexManager::GetObjOffset( LwpObjectID objid
)
322 //sal_uInt16 L, U, M;
331 if (objid
.GetLow() > m_ObjectKeys
[M
]->id
.GetLow())
333 else if (objid
.GetLow() < m_ObjectKeys
[M
]->id
.GetLow())
335 else if (objid
.GetHigh() > m_ObjectKeys
[M
]->id
.GetHigh())
337 else if (objid
.GetHigh() < m_ObjectKeys
[M
]->id
.GetHigh())
341 return(m_ObjectKeys
[M
]->offset
);
347 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */