LCOV - code coverage report
Current view: top level - lotuswordpro/source/filter - lwpidxmgr.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 90 136 66.2 %
Date: 2014-11-03 Functions: 8 10 80.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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             :  * Change History
      68             :  Jan 2005           Created
      69             : **********************************************************************************************************************/
      70             : 
      71             : #include "lwpidxmgr.hxx"
      72             : #include "lwptools.hxx"
      73             : 
      74             : const sal_uInt8 LwpIndexManager::MAXOBJECTIDS = 255;
      75             : 
      76          12 : LwpIndexManager::LwpIndexManager()
      77          12 :     :m_nKeyCount(0), m_nLeafCount(0)
      78             : {
      79             : 
      80          12 :     m_TempVec.resize( LwpIndexManager::MAXOBJECTIDS );
      81             : 
      82          12 : }
      83             : 
      84          24 : LwpIndexManager::~LwpIndexManager()
      85             : {
      86             :     //Clear m_ObjectKeys
      87          12 :     std::vector<LwpKey*>::iterator it;
      88             : 
      89        4470 :     for( it = m_ObjectKeys.begin(); it != m_ObjectKeys.end(); ++it )
      90             :     {
      91        4458 :         LwpKey* pKey = *it;
      92        4458 :         if( pKey )
      93             :         {
      94        4458 :             delete pKey;
      95        4458 :             pKey = NULL;
      96             :         }
      97             :     }
      98          12 :     m_ObjectKeys.clear();
      99          12 : }
     100             : 
     101             : /**
     102             :  * @descr   Read all index records, VO_ROOTLEAFOBJINDEX, VO_ROOTOBJINDEX, VO_LEAFOBJINDEX
     103             :  */
     104          12 : void LwpIndexManager::Read(LwpSvStream* pStrm)
     105             : {
     106             :     //Read index obj
     107          12 :     LwpObjectHeader ObjHdr;
     108          12 :     ObjHdr.Read(*pStrm);
     109          12 :     LwpObjectStream* pObjStrm = new LwpObjectStream(pStrm, ObjHdr.IsCompressed(),
     110          12 :             static_cast<sal_uInt16>(ObjHdr.GetSize()) );
     111             : 
     112          12 :     if( ObjHdr.GetTag() == VO_ROOTLEAFOBJINDEX )
     113             :     {
     114           0 :         ReadLeafData(pObjStrm);
     115           0 :         ReadTimeTable(pObjStrm);
     116           0 :         delete pObjStrm;
     117             :     }
     118             :     else
     119             :     {
     120          12 :         ReadRootData(pObjStrm);
     121          12 :         delete pObjStrm;
     122             : 
     123          36 :         for (sal_uInt16 k = 0; k < m_nLeafCount; k++)
     124             :         {
     125             :             //Read leaf
     126          24 :             sal_Int64 nPos = m_ChildIndex[k]+LwpSvStream::LWP_STREAM_BASE;
     127          24 :             sal_Int64 nActualPos = pStrm->Seek(nPos);
     128             : 
     129          24 :             if (nPos != nActualPos)
     130           0 :                 throw BadSeek();
     131             : 
     132             :             //Old Code
     133             :             //ReadLeafIndex(pStrm);
     134             :             //New Code
     135          24 :             ReadObjIndex( pStrm );
     136             : 
     137             :             //Read object in root, these objects are between the leaf objects
     138          24 :             if(k!=m_nLeafCount-1)
     139             :             {
     140          12 :                 m_ObjectKeys.push_back(m_RootObjs[k]);
     141          12 :                 m_nKeyCount ++;
     142             :             }
     143             :         }
     144          12 :         m_RootObjs.clear();
     145             :     }
     146          12 : }
     147             : 
     148             : /**
     149             :  * @descr   Read data in VO_ROOTOBJINDEX
     150             :  */
     151          12 : void LwpIndexManager::ReadRootData(LwpObjectStream* pObjStrm)
     152             : {
     153             : 
     154          12 :     sal_uInt16 KeyCount = pObjStrm->QuickReaduInt16();
     155          12 :     m_nLeafCount = KeyCount ? KeyCount + 1 : 0;
     156             : 
     157          12 :     if(KeyCount)
     158             :     {
     159             :         //read object keys
     160          12 :         LwpKey* akey = new LwpKey();
     161          12 :         akey->id.Read(pObjStrm);
     162          12 :         m_RootObjs.push_back(akey);
     163             : 
     164          12 :         sal_uInt16 k = 0;
     165             : 
     166          12 :         for (k = 1; k < KeyCount; k++)
     167             :         {
     168           0 :             akey = new LwpKey();
     169           0 :             akey->id.ReadCompressed(pObjStrm, m_RootObjs[k-1]->id);
     170           0 :             m_RootObjs.push_back(akey);
     171             :         }
     172             : 
     173          24 :         for (k = 0; k < KeyCount; k++)
     174          12 :             m_RootObjs[k]->offset = pObjStrm->QuickReaduInt32();
     175             : 
     176             :         //read leaf index offset
     177          36 :         for (k = 0; k < m_nLeafCount; k++)
     178          24 :             m_ChildIndex[k] = pObjStrm->QuickReaduInt32();
     179             :     }
     180             : 
     181          12 :     ReadTimeTable(pObjStrm);
     182             : 
     183          12 : }
     184             : 
     185             : //Add new method to handle ObjIndex data
     186             : /**
     187             :  * @descr   Read data in VO_OBJINDEX
     188             :  */
     189           0 : void LwpIndexManager::ReadObjIndexData(LwpObjectStream* pObjStrm)
     190             : {
     191           0 :     sal_uInt16 KeyCount = pObjStrm->QuickReaduInt16();
     192           0 :     sal_uInt16 LeafCount = KeyCount + 1;
     193             : 
     194           0 :     std::vector<LwpKey*> vObjIndexs;
     195             : 
     196           0 :     if(KeyCount)
     197             :     {
     198           0 :         LwpKey* akey = new LwpKey();
     199           0 :         akey->id.Read(pObjStrm);
     200           0 :         vObjIndexs.push_back(akey);
     201             : 
     202           0 :         sal_uInt16 k = 0;
     203             : 
     204           0 :         for (k = 1; k < KeyCount; k++)
     205             :         {
     206           0 :             akey = new LwpKey();
     207           0 :             akey->id.ReadCompressed(pObjStrm, vObjIndexs[k-1]->id);
     208           0 :             vObjIndexs.push_back(akey);
     209             :         }
     210             : 
     211           0 :         for (k = 0; k < KeyCount; k++)
     212           0 :             vObjIndexs[k]->offset = pObjStrm->QuickReaduInt32();
     213             : 
     214           0 :         for (k = 0; k < LeafCount; k++)
     215           0 :             m_TempVec[k] = pObjStrm->QuickReaduInt32();
     216             :     }
     217             : 
     218           0 :     for( sal_uInt16 j=0; j<LeafCount; j++ )
     219             :     {
     220           0 :         sal_Int64 nPos = m_TempVec[j]+LwpSvStream::LWP_STREAM_BASE;
     221           0 :         sal_Int64 nActualPos = pObjStrm->GetStream()->Seek(nPos);
     222             : 
     223           0 :         if (nPos != nActualPos)
     224           0 :             throw BadSeek();
     225             : 
     226           0 :         ReadLeafIndex(pObjStrm->GetStream());
     227             : 
     228           0 :         if(j!=LeafCount-1)
     229             :         {
     230           0 :             m_ObjectKeys.push_back(vObjIndexs[j]);
     231             : 
     232           0 :             m_nKeyCount ++;
     233             :         }
     234             :     }
     235             : 
     236           0 :     vObjIndexs.clear();
     237           0 :     m_TempVec.clear();
     238           0 : }
     239             : 
     240             : /**
     241             :  * @descr   Read VO_OBJINDEX
     242             :  */
     243          24 : void LwpIndexManager::ReadObjIndex( LwpSvStream *pStrm )
     244             : {
     245             : 
     246          24 :     LwpObjectHeader ObjHdr;
     247          24 :     ObjHdr.Read(*pStrm);
     248          24 :     LwpObjectStream* pObjStrm = new LwpObjectStream(pStrm, ObjHdr.IsCompressed(),
     249          24 :             static_cast<sal_uInt16>(ObjHdr.GetSize()) );
     250             : 
     251          24 :     if( (sal_uInt32)VO_OBJINDEX == ObjHdr.GetTag() )
     252             :     {
     253           0 :         ReadObjIndexData( pObjStrm );
     254             :     }
     255          24 :     else if( (sal_uInt32)VO_LEAFOBJINDEX == ObjHdr.GetTag() )
     256             :     {
     257          24 :         ReadLeafData(pObjStrm);
     258             :     }
     259             : 
     260          24 :     delete pObjStrm;
     261          24 : }
     262             : 
     263             : /**
     264             :  * @descr   Read VO_LEAFOBJINDEX
     265             :  */
     266           0 : void LwpIndexManager::ReadLeafIndex( LwpSvStream *pStrm )
     267             : {
     268           0 :     LwpObjectHeader ObjHdr;
     269           0 :     ObjHdr.Read(*pStrm);
     270           0 :     LwpObjectStream* pObjStrm = new LwpObjectStream(pStrm, ObjHdr.IsCompressed(),
     271           0 :             static_cast<sal_uInt16>(ObjHdr.GetSize()) );
     272             : 
     273           0 :     ReadLeafData(pObjStrm);
     274             : 
     275           0 :     delete pObjStrm;
     276           0 : }
     277             : /**
     278             :  * @descr   Read data in VO_LEAFOBJINDEX
     279             :  */
     280          24 : void LwpIndexManager::ReadLeafData( LwpObjectStream *pObjStrm )
     281             : {
     282          24 :     sal_uInt16 KeyCount = pObjStrm->QuickReaduInt16();
     283             : 
     284          24 :     if(KeyCount)
     285             :     {
     286          24 :         LwpKey* akey = new LwpKey();
     287             :         //read object keys: id & offset
     288          24 :         akey->id.Read(pObjStrm);
     289          24 :         m_ObjectKeys.push_back(akey);
     290             : 
     291        4446 :         for (sal_uInt8 k = 1; k < KeyCount; k++)
     292             :         {
     293        4422 :             akey = new LwpKey();
     294        4422 :             akey->id.ReadCompressed(pObjStrm, m_ObjectKeys.at(m_nKeyCount+k-1)->id);
     295        4422 :             m_ObjectKeys.push_back(akey);
     296             :         }
     297             : 
     298        4470 :         for (sal_uInt8 j = 0; j < KeyCount; j++)
     299        4446 :             m_ObjectKeys.at(m_nKeyCount+j)->offset = pObjStrm->QuickReaduInt32();
     300             :     }
     301          24 :     m_nKeyCount += KeyCount;
     302          24 : }
     303             : /**
     304             :  * @descr   Read time table in VO_ROOTLEAFOBJINDEX and VO_ROOTOBJINDEX
     305             :  */
     306          12 : void LwpIndexManager::ReadTimeTable(LwpObjectStream *pObjStrm)
     307             : {
     308          12 :     sal_uInt16 nTimeCount = pObjStrm->QuickReaduInt16();
     309             : 
     310         192 :     for(sal_uInt16 i=0; i<nTimeCount; ++i)
     311             :     {
     312         180 :         sal_uInt32 atime = pObjStrm->QuickReaduInt32();
     313         180 :         m_TimeTable.push_back(atime);
     314             :     }
     315          12 : }
     316             : /**
     317             :  * @descr       get object offset per the object id
     318             :  */
     319        1828 : sal_uInt32 LwpIndexManager::GetObjOffset( LwpObjectID objid )
     320             : {
     321             : 
     322             :     //sal_uInt16 L, U, M;
     323             :     sal_uInt32 L, U, M;
     324             : 
     325        1828 :     L = 0;
     326        1828 :     U = m_nKeyCount;
     327       15918 :     while (L != U)
     328             :     {
     329       14090 :         M = (L + U) >> 1;
     330             : 
     331       14090 :         if (objid.GetLow() > m_ObjectKeys[M]->id.GetLow())
     332        2364 :             L = M + 1;
     333       11726 :         else if (objid.GetLow() < m_ObjectKeys[M]->id.GetLow())
     334        2102 :             U = M;
     335        9624 :         else if (objid.GetHigh() > m_ObjectKeys[M]->id.GetHigh())
     336        3768 :             L = M + 1;
     337        5856 :         else if (objid.GetHigh() < m_ObjectKeys[M]->id.GetHigh())
     338        4028 :             U = M;
     339             :         else
     340             :         {
     341        1828 :             return(m_ObjectKeys[M]->offset);
     342             :         }
     343             :     }
     344           0 :     return BAD_OFFSET;
     345             : }
     346             : 
     347             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10