Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / source / core / tool / rechead.cxx
blob606941aaa6c3f4e71ee8866f55c571f55fefe9d6
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "rechead.hxx"
21 #include "scerrors.hxx"
23 // STATIC DATA
25 ScMultipleReadHeader::ScMultipleReadHeader(SvStream& rNewStream) :
26 rStream( rNewStream )
28 sal_uInt32 nDataSize;
29 rStream >> nDataSize;
30 sal_uLong nDataPos = rStream.Tell();
31 nTotalEnd = nDataPos + nDataSize;
32 nEntryEnd = nTotalEnd;
34 rStream.SeekRel(nDataSize);
35 sal_uInt16 nID;
36 rStream >> nID;
37 if (nID != SCID_SIZES)
39 OSL_FAIL("SCID_SIZES not found");
40 if ( rStream.GetError() == SVSTREAM_OK )
41 rStream.SetError( SVSTREAM_FILEFORMAT_ERROR );
43 // everything to 0, so BytesLeft() aborts at least
44 pBuf = NULL; pMemStream = NULL;
45 nEntryEnd = nDataPos;
47 else
49 sal_uInt32 nSizeTableLen;
50 rStream >> nSizeTableLen;
51 pBuf = new sal_uInt8[nSizeTableLen];
52 rStream.Read( pBuf, nSizeTableLen );
53 pMemStream = new SvMemoryStream( (char*)pBuf, nSizeTableLen, STREAM_READ );
56 nEndPos = rStream.Tell();
57 rStream.Seek( nDataPos );
60 ScMultipleReadHeader::~ScMultipleReadHeader()
62 if ( pMemStream && pMemStream->Tell() != pMemStream->GetEndOfData() )
64 OSL_FAIL( "Sizes not fully read" );
65 if ( rStream.GetError() == SVSTREAM_OK )
66 rStream.SetError( SCWARN_IMPORT_INFOLOST );
68 delete pMemStream;
69 delete[] pBuf;
71 rStream.Seek(nEndPos);
74 void ScMultipleReadHeader::EndEntry()
76 sal_uLong nPos = rStream.Tell();
77 OSL_ENSURE( nPos <= nEntryEnd, "read too much" );
78 if ( nPos != nEntryEnd )
80 if ( rStream.GetError() == SVSTREAM_OK )
81 rStream.SetError( SCWARN_IMPORT_INFOLOST );
82 rStream.Seek( nEntryEnd ); // ignore the rest
85 nEntryEnd = nTotalEnd; // all remaining, if no StartEntry follows
88 void ScMultipleReadHeader::StartEntry()
90 sal_uLong nPos = rStream.Tell();
91 sal_uInt32 nEntrySize;
92 (*pMemStream) >> nEntrySize;
94 nEntryEnd = nPos + nEntrySize;
95 OSL_ENSURE( nEntryEnd <= nTotalEnd, "read too many entries" );
98 sal_uLong ScMultipleReadHeader::BytesLeft() const
100 sal_uLong nReadEnd = rStream.Tell();
101 if (nReadEnd <= nEntryEnd)
102 return nEntryEnd-nReadEnd;
104 OSL_FAIL("ScMultipleReadHeader::BytesLeft: Error");
105 return 0;
108 ScMultipleWriteHeader::ScMultipleWriteHeader(SvStream& rNewStream, sal_uInt32 nDefault) :
109 rStream( rNewStream ),
110 aMemStream( 4096, 4096 )
112 nDataSize = nDefault;
113 rStream << nDataSize;
115 nDataPos = rStream.Tell();
116 nEntryStart = nDataPos;
119 ScMultipleWriteHeader::~ScMultipleWriteHeader()
121 sal_uLong nDataEnd = rStream.Tell();
123 rStream << (sal_uInt16) SCID_SIZES;
124 rStream << static_cast<sal_uInt32>(aMemStream.Tell());
125 rStream.Write( aMemStream.GetData(), aMemStream.Tell() );
127 if ( nDataEnd - nDataPos != nDataSize ) // matched default ?
129 nDataSize = nDataEnd - nDataPos;
130 sal_uLong nPos = rStream.Tell();
131 rStream.Seek(nDataPos-sizeof(sal_uInt32));
132 rStream << nDataSize; // record size at the beginning
133 rStream.Seek(nPos);
137 void ScMultipleWriteHeader::EndEntry()
139 sal_uLong nPos = rStream.Tell();
140 aMemStream << static_cast<sal_uInt32>(nPos - nEntryStart);
143 void ScMultipleWriteHeader::StartEntry()
145 sal_uLong nPos = rStream.Tell();
146 nEntryStart = nPos;
149 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */