Update ooo320-m1
[ooovba.git] / sc / source / core / tool / rechead.cxx
blob10539002cdb06a8a90268d4f38cbb206a8b5a754
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: rechead.cxx,v $
10 * $Revision: 1.6.32.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
36 // INCLUDE ---------------------------------------------------------------
38 #include <tools/debug.hxx>
40 #include "rechead.hxx"
41 #include "scerrors.hxx"
43 // STATIC DATA -----------------------------------------------------------
45 // =======================================================================
47 ScMultipleReadHeader::ScMultipleReadHeader(SvStream& rNewStream) :
48 rStream( rNewStream )
50 sal_uInt32 nDataSize;
51 rStream >> nDataSize;
52 ULONG nDataPos = rStream.Tell();
53 nTotalEnd = nDataPos + nDataSize;
54 nEntryEnd = nTotalEnd;
56 rStream.SeekRel(nDataSize);
57 USHORT nID;
58 rStream >> nID;
59 if (nID != SCID_SIZES)
61 DBG_ERROR("SCID_SIZES nicht gefunden");
62 if ( rStream.GetError() == SVSTREAM_OK )
63 rStream.SetError( SVSTREAM_FILEFORMAT_ERROR );
65 // alles auf 0, damit BytesLeft() wenigstens abbricht
66 pBuf = NULL; pMemStream = NULL;
67 nEntryEnd = nDataPos;
69 else
71 sal_uInt32 nSizeTableLen;
72 rStream >> nSizeTableLen;
73 pBuf = new BYTE[nSizeTableLen];
74 rStream.Read( pBuf, nSizeTableLen );
75 pMemStream = new SvMemoryStream( (char*)pBuf, nSizeTableLen, STREAM_READ );
78 nEndPos = rStream.Tell();
79 rStream.Seek( nDataPos );
82 ScMultipleReadHeader::~ScMultipleReadHeader()
84 if ( pMemStream && pMemStream->Tell() != pMemStream->GetSize() )
86 DBG_ERRORFILE( "Sizes nicht vollstaendig gelesen" );
87 if ( rStream.GetError() == SVSTREAM_OK )
88 rStream.SetError( SCWARN_IMPORT_INFOLOST );
90 delete pMemStream;
91 delete[] pBuf;
93 rStream.Seek(nEndPos);
96 void ScMultipleReadHeader::EndEntry()
98 ULONG nPos = rStream.Tell();
99 DBG_ASSERT( nPos <= nEntryEnd, "zuviel gelesen" );
100 if ( nPos != nEntryEnd )
102 if ( rStream.GetError() == SVSTREAM_OK )
103 rStream.SetError( SCWARN_IMPORT_INFOLOST );
104 rStream.Seek( nEntryEnd ); // Rest ueberspringen
107 nEntryEnd = nTotalEnd; // den ganzen Rest, wenn kein StartEntry kommt
110 void ScMultipleReadHeader::StartEntry()
112 ULONG nPos = rStream.Tell();
113 sal_uInt32 nEntrySize;
114 (*pMemStream) >> nEntrySize;
116 nEntryEnd = nPos + nEntrySize;
117 DBG_ASSERT( nEntryEnd <= nTotalEnd, "zuviele Eintraege gelesen" );
120 ULONG ScMultipleReadHeader::BytesLeft() const
122 ULONG nReadEnd = rStream.Tell();
123 if (nReadEnd <= nEntryEnd)
124 return nEntryEnd-nReadEnd;
126 DBG_ERROR("Fehler bei ScMultipleReadHeader::BytesLeft");
127 return 0;
130 // -----------------------------------------------------------------------
132 ScMultipleWriteHeader::ScMultipleWriteHeader(SvStream& rNewStream, sal_uInt32 nDefault) :
133 rStream( rNewStream ),
134 aMemStream( 4096, 4096 )
136 nDataSize = nDefault;
137 rStream << nDataSize;
139 nDataPos = rStream.Tell();
140 nEntryStart = nDataPos;
143 ScMultipleWriteHeader::~ScMultipleWriteHeader()
145 ULONG nDataEnd = rStream.Tell();
147 rStream << (USHORT) SCID_SIZES;
148 rStream << static_cast<sal_uInt32>(aMemStream.Tell());
149 rStream.Write( aMemStream.GetData(), aMemStream.Tell() );
151 if ( nDataEnd - nDataPos != nDataSize ) // Default getroffen?
153 nDataSize = nDataEnd - nDataPos;
154 ULONG nPos = rStream.Tell();
155 rStream.Seek(nDataPos-sizeof(sal_uInt32));
156 rStream << nDataSize; // Groesse am Anfang eintragen
157 rStream.Seek(nPos);
161 void ScMultipleWriteHeader::EndEntry()
163 ULONG nPos = rStream.Tell();
164 aMemStream << static_cast<sal_uInt32>(nPos - nEntryStart);
167 void ScMultipleWriteHeader::StartEntry()
169 ULONG nPos = rStream.Tell();
170 nEntryStart = nPos;