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
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
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
133 }
134}
135
137{
138 sal_uInt64 nPos = rStream.Tell();
140}
141
143{
144 sal_uInt64 nPos = rStream.Tell();
146}
147
148/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uInt64 nEntryEnd
Definition: rechead.hxx:56
sal_uInt64 nTotalEnd
Definition: rechead.hxx:57
SvStream & rStream
Definition: rechead.hxx:50
std::unique_ptr< SvMemoryStream > pMemStream
Definition: rechead.hxx:54
std::unique_ptr< sal_uInt8[]> pBuf
Definition: rechead.hxx:52
ScMultipleReadHeader(SvStream &rNewStream)
Definition: rechead.cxx:25
sal_uInt64 BytesLeft() const
Definition: rechead.cxx:97
sal_uInt64 nEndPos
Definition: rechead.hxx:55
sal_uInt64 nDataPos
Definition: rechead.hxx:73
sal_uInt32 nDataSize
Definition: rechead.hxx:74
ScMultipleWriteHeader(SvStream &rNewStream)
Definition: rechead.cxx:107
SvStream & rStream
Definition: rechead.hxx:71
sal_uInt64 nEntryStart
Definition: rechead.hxx:75
SvMemoryStream aMemStream
Definition: rechead.hxx:72
const void * GetData()
sal_uInt64 Tell() const
std::size_t WriteBytes(const void *pData, std::size_t nSize)
SvStream & WriteUInt16(sal_uInt16 nUInt16)
SvStream & WriteUInt32(sal_uInt32 nUInt32)
SvStream & ReadUInt32(sal_uInt32 &rUInt32)
void SetError(ErrCode nErrorCode)
sal_uInt64 Seek(sal_uInt64 nPos)
std::size_t ReadBytes(void *pData, std::size_t nSize)
sal_uInt64 SeekRel(sal_Int64 nPos)
ErrCode GetError() const
SvStream & ReadUInt16(sal_uInt16 &rUInt16)
#define SVSTREAM_FILEFORMAT_ERROR
#define ERRCODE_NONE
sal_uInt16 nPos
#define SCID_SIZES
Definition: rechead.hxx:27
#define SCWARN_IMPORT_INFOLOST
Definition: scerrors.hxx:46
unsigned char sal_uInt8