LCOV - code coverage report
Current view: top level - sc/source/core/tool - rechead.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 73 0.0 %
Date: 2014-04-14 Functions: 0 9 0.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             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "rechead.hxx"
      21             : #include "scerrors.hxx"
      22             : 
      23             : // STATIC DATA
      24             : 
      25           0 : ScMultipleReadHeader::ScMultipleReadHeader(SvStream& rNewStream) :
      26           0 :     rStream( rNewStream )
      27             : {
      28             :     sal_uInt32 nDataSize;
      29           0 :     rStream.ReadUInt32( nDataSize );
      30           0 :     sal_uLong nDataPos = rStream.Tell();
      31           0 :     nTotalEnd = nDataPos + nDataSize;
      32           0 :     nEntryEnd = nTotalEnd;
      33             : 
      34           0 :     rStream.SeekRel(nDataSize);
      35             :     sal_uInt16 nID;
      36           0 :     rStream.ReadUInt16( nID );
      37           0 :     if (nID != SCID_SIZES)
      38             :     {
      39             :         OSL_FAIL("SCID_SIZES not found");
      40           0 :         if ( rStream.GetError() == SVSTREAM_OK )
      41           0 :             rStream.SetError( SVSTREAM_FILEFORMAT_ERROR );
      42             : 
      43             :         //  everything to 0, so  BytesLeft() aborts at least
      44           0 :         pBuf = NULL; pMemStream = NULL;
      45           0 :         nEntryEnd = nDataPos;
      46             :     }
      47             :     else
      48             :     {
      49             :         sal_uInt32 nSizeTableLen;
      50           0 :         rStream.ReadUInt32( nSizeTableLen );
      51           0 :         pBuf = new sal_uInt8[nSizeTableLen];
      52           0 :         rStream.Read( pBuf, nSizeTableLen );
      53           0 :         pMemStream = new SvMemoryStream( (char*)pBuf, nSizeTableLen, STREAM_READ );
      54             :     }
      55             : 
      56           0 :     nEndPos = rStream.Tell();
      57           0 :     rStream.Seek( nDataPos );
      58           0 : }
      59             : 
      60           0 : ScMultipleReadHeader::~ScMultipleReadHeader()
      61             : {
      62           0 :     if ( pMemStream && pMemStream->Tell() != pMemStream->GetEndOfData() )
      63             :     {
      64             :         OSL_FAIL( "Sizes not fully read" );
      65           0 :         if ( rStream.GetError() == SVSTREAM_OK )
      66           0 :             rStream.SetError( SCWARN_IMPORT_INFOLOST );
      67             :     }
      68           0 :     delete pMemStream;
      69           0 :     delete[] pBuf;
      70             : 
      71           0 :     rStream.Seek(nEndPos);
      72           0 : }
      73             : 
      74           0 : void ScMultipleReadHeader::EndEntry()
      75             : {
      76           0 :     sal_uLong nPos = rStream.Tell();
      77             :     OSL_ENSURE( nPos <= nEntryEnd, "read too much" );
      78           0 :     if ( nPos != nEntryEnd )
      79             :     {
      80           0 :         if ( rStream.GetError() == SVSTREAM_OK )
      81           0 :             rStream.SetError( SCWARN_IMPORT_INFOLOST );
      82           0 :         rStream.Seek( nEntryEnd );          // ignore the rest
      83             :     }
      84             : 
      85           0 :     nEntryEnd = nTotalEnd;          // all remaining, if no StartEntry follows
      86           0 : }
      87             : 
      88           0 : void ScMultipleReadHeader::StartEntry()
      89             : {
      90           0 :     sal_uLong nPos = rStream.Tell();
      91             :     sal_uInt32 nEntrySize;
      92           0 :     (*pMemStream).ReadUInt32( nEntrySize );
      93             : 
      94           0 :     nEntryEnd = nPos + nEntrySize;
      95             :     OSL_ENSURE( nEntryEnd <= nTotalEnd, "read too many entries" );
      96           0 : }
      97             : 
      98           0 : sal_uLong ScMultipleReadHeader::BytesLeft() const
      99             : {
     100           0 :     sal_uLong nReadEnd = rStream.Tell();
     101           0 :     if (nReadEnd <= nEntryEnd)
     102           0 :         return nEntryEnd-nReadEnd;
     103             : 
     104             :     OSL_FAIL("ScMultipleReadHeader::BytesLeft: Error");
     105           0 :     return 0;
     106             : }
     107             : 
     108           0 : ScMultipleWriteHeader::ScMultipleWriteHeader(SvStream& rNewStream, sal_uInt32 nDefault) :
     109             :     rStream( rNewStream ),
     110           0 :     aMemStream( 4096, 4096 )
     111             : {
     112           0 :     nDataSize = nDefault;
     113           0 :     rStream.WriteUInt32( nDataSize );
     114             : 
     115           0 :     nDataPos = rStream.Tell();
     116           0 :     nEntryStart = nDataPos;
     117           0 : }
     118             : 
     119           0 : ScMultipleWriteHeader::~ScMultipleWriteHeader()
     120             : {
     121           0 :     sal_uLong nDataEnd = rStream.Tell();
     122             : 
     123           0 :     rStream.WriteUInt16( (sal_uInt16) SCID_SIZES );
     124           0 :     rStream.WriteUInt32( static_cast<sal_uInt32>(aMemStream.Tell()) );
     125           0 :     rStream.Write( aMemStream.GetData(), aMemStream.Tell() );
     126             : 
     127           0 :     if ( nDataEnd - nDataPos != nDataSize )                 // matched default ?
     128             :     {
     129           0 :         nDataSize = nDataEnd - nDataPos;
     130           0 :         sal_uLong nPos = rStream.Tell();
     131           0 :         rStream.Seek(nDataPos-sizeof(sal_uInt32));
     132           0 :         rStream.WriteUInt32( nDataSize );                               // record size at the beginning
     133           0 :         rStream.Seek(nPos);
     134             :     }
     135           0 : }
     136             : 
     137           0 : void ScMultipleWriteHeader::EndEntry()
     138             : {
     139           0 :     sal_uLong nPos = rStream.Tell();
     140           0 :     aMemStream.WriteUInt32( static_cast<sal_uInt32>(nPos - nEntryStart) );
     141           0 : }
     142             : 
     143           0 : void ScMultipleWriteHeader::StartEntry()
     144             : {
     145           0 :     sal_uLong nPos = rStream.Tell();
     146           0 :     nEntryStart = nPos;
     147           0 : }
     148             : 
     149             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10