LibreOffice Module sc (master)  1
rechead.cxx
Go to the documentation of this file.
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 #include <osl/diagnose.h>
24 
26  rStream( rNewStream )
27 {
28  sal_uInt32 nDataSize;
29  rStream.ReadUInt32( nDataSize );
30  sal_uInt64 nDataPos = rStream.Tell();
31  nTotalEnd = nDataPos + nDataSize;
33 
34  rStream.SeekRel(nDataSize);
35  sal_uInt16 nID;
36  rStream.ReadUInt16( nID );
37  if (nID != SCID_SIZES)
38  {
39  OSL_FAIL("SCID_SIZES not found");
40  if ( rStream.GetError() == ERRCODE_NONE )
42 
43  // everything to 0, so BytesLeft() aborts at least
44  pBuf = nullptr; pMemStream.reset();
45  nEntryEnd = nDataPos;
46  }
47  else
48  {
49  sal_uInt32 nSizeTableLen;
50  rStream.ReadUInt32( nSizeTableLen );
51  pBuf.reset( new sal_uInt8[nSizeTableLen] );
52  rStream.ReadBytes( pBuf.get(), nSizeTableLen );
53  pMemStream.reset(new SvMemoryStream( pBuf.get(), nSizeTableLen, StreamMode::READ ));
54  }
55 
56  nEndPos = rStream.Tell();
57  rStream.Seek( nDataPos );
58 }
59 
61 {
62  if ( pMemStream && pMemStream->Tell() != pMemStream->GetEndOfData() )
63  {
64  OSL_FAIL( "Sizes not fully read" );
65  if ( rStream.GetError() == ERRCODE_NONE )
67  }
68  pMemStream.reset();
69 
71 }
72 
74 {
75  sal_uInt64 nPos = rStream.Tell();
76  OSL_ENSURE( nPos <= nEntryEnd, "read too much" );
77  if ( nPos != nEntryEnd )
78  {
79  if ( rStream.GetError() == ERRCODE_NONE )
81  rStream.Seek( nEntryEnd ); // ignore the rest
82  }
83 
84  nEntryEnd = nTotalEnd; // all remaining, if no StartEntry follows
85 }
86 
88 {
89  sal_uInt64 nPos = rStream.Tell();
90  sal_uInt32 nEntrySize;
91  (*pMemStream).ReadUInt32( nEntrySize );
92 
93  nEntryEnd = nPos + nEntrySize;
94  OSL_ENSURE( nEntryEnd <= nTotalEnd, "read too many entries" );
95 }
96 
98 {
99  sal_uInt64 nReadEnd = rStream.Tell();
100  if (nReadEnd <= nEntryEnd)
101  return nEntryEnd-nReadEnd;
102 
103  OSL_FAIL("ScMultipleReadHeader::BytesLeft: Error");
104  return 0;
105 }
106 
108  rStream( rNewStream ),
109  aMemStream( 4096, 4096 )
110 {
111  nDataSize = 0;
113 
114  nDataPos = rStream.Tell();
116 }
117 
119 {
120  sal_uInt64 nDataEnd = rStream.Tell();
121 
125 
126  if ( nDataEnd - nDataPos != nDataSize ) // matched default ?
127  {
128  nDataSize = nDataEnd - nDataPos;
129  sal_uInt64 nPos = rStream.Tell();
130  rStream.Seek(nDataPos-sizeof(sal_uInt32));
131  rStream.WriteUInt32( nDataSize ); // record size at the beginning
132  rStream.Seek(nPos);
133  }
134 }
135 
137 {
138  sal_uInt64 nPos = rStream.Tell();
140 }
141 
143 {
144  sal_uInt64 nPos = rStream.Tell();
145  nEntryStart = nPos;
146 }
147 
148 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define SCID_SIZES
Definition: rechead.hxx:27
SvStream & WriteUInt16(sal_uInt16 nUInt16)
SvStream & ReadUInt16(sal_uInt16 &rUInt16)
sal_uInt64 BytesLeft() const
Definition: rechead.cxx:97
sal_uInt64 nEndPos
Definition: rechead.hxx:55
sal_uInt64 nTotalEnd
Definition: rechead.hxx:57
sal_uInt64 Seek(sal_uInt64 nPos)
ScMultipleWriteHeader(SvStream &rNewStream)
Definition: rechead.cxx:107
SvStream & rStream
Definition: rechead.hxx:71
sal_uInt64 SeekRel(sal_Int64 nPos)
std::unique_ptr< sal_uInt8[]> pBuf
Definition: rechead.hxx:52
ErrCode GetError() const
SvStream & WriteUInt32(sal_uInt32 nUInt32)
sal_uInt64 nEntryEnd
Definition: rechead.hxx:56
sal_uInt32 nDataSize
Definition: rechead.hxx:74
SvStream & ReadUInt32(sal_uInt32 &rUInt32)
sal_uInt64 nEntryStart
Definition: rechead.hxx:75
std::size_t WriteBytes(const void *pData, std::size_t nSize)
void SetError(ErrCode nErrorCode)
#define SCWARN_IMPORT_INFOLOST
Definition: scerrors.hxx:46
std::size_t ReadBytes(void *pData, std::size_t nSize)
sal_uInt64 nDataPos
Definition: rechead.hxx:73
#define ERRCODE_NONE
unsigned char sal_uInt8
#define SVSTREAM_FILEFORMAT_ERROR
SvMemoryStream aMemStream
Definition: rechead.hxx:72
ScMultipleReadHeader(SvStream &rNewStream)
Definition: rechead.cxx:25
sal_uInt64 Tell() const
SvStream & rStream
Definition: rechead.hxx:50
sal_uInt16 nPos
const void * GetData()
std::unique_ptr< SvMemoryStream > pMemStream
Definition: rechead.hxx:54