Update ooo320-m1
[ooovba.git] / svtools / source / numbers / numhead.cxx
blob6bd6ac46102544fc7e6e1aaedc90dc261a21d924
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: numhead.cxx,v $
10 * $Revision: 1.9 $
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_svtools.hxx"
33 #ifndef GCC
34 #endif
35 #include <tools/debug.hxx>
37 #include "numhead.hxx"
39 // ID's fuer Dateien:
40 #define SV_NUMID_SIZES 0x4200
42 // STATIC DATA -----------------------------------------------------------
44 //SEG_EOFGLOBALS()
46 // =======================================================================
47 /* wird fuer SvNumberformatter nicht gebraucht
48 //#pragma SEG_FUNCDEF(numhead_01)
50 SvNumReadHeader::SvNumReadHeader(SvStream& rNewStream) :
51 rStream( rNewStream )
53 ULONG nDataSize;
54 rStream >> nDataSize;
55 nDataEnd = rStream.Tell() + nDataSize;
58 //#pragma SEG_FUNCDEF(numhead_02)
60 SvNumReadHeader::~SvNumReadHeader()
62 ULONG nReadEnd = rStream.Tell();
63 DBG_ASSERT( nReadEnd <= nDataEnd, "zuviele Bytes gelesen" );
64 if ( nReadEnd != nDataEnd )
65 rStream.Seek(nDataEnd); // Rest ueberspringen
68 //#pragma SEG_FUNCDEF(numhead_03)
70 ULONG SvNumReadHeader::BytesLeft() const
72 ULONG nReadEnd = rStream.Tell();
73 if (nReadEnd <= nDataEnd)
74 return nDataEnd-nReadEnd;
76 DBG_ERROR("Fehler bei SvNumReadHeader::BytesLeft");
77 return 0;
80 // -----------------------------------------------------------------------
82 //#pragma SEG_FUNCDEF(numhead_04)
84 SvNumWriteHeader::SvNumWriteHeader(SvStream& rNewStream, ULONG nDefault) :
85 rStream( rNewStream )
87 nDataSize = nDefault;
88 rStream << nDataSize;
89 nDataPos = rStream.Tell();
92 //#pragma SEG_FUNCDEF(numhead_05)
94 SvNumWriteHeader::~SvNumWriteHeader()
96 ULONG nPos = rStream.Tell();
98 if ( nPos - nDataPos != nDataSize ) // Default getroffen?
100 nDataSize = nPos - nDataPos;
101 rStream.Seek(nDataPos - sizeof(sal_uInt32));
102 rStream << nDataSize; // Groesse am Anfang eintragen
103 rStream.Seek(nPos);
108 // =======================================================================
110 //#pragma SEG_FUNCDEF(numhead_06)
112 //! mit Skip() synchron
113 ImpSvNumMultipleReadHeader::ImpSvNumMultipleReadHeader(SvStream& rNewStream) :
114 rStream( rNewStream )
116 sal_uInt32 nDataSize;
117 rStream >> nDataSize;
118 ULONG nDataPos = rStream.Tell();
119 nEntryEnd = nDataPos;
121 rStream.SeekRel(nDataSize);
122 USHORT nID;
123 rStream >> nID;
124 if (nID != SV_NUMID_SIZES)
126 DBG_ERROR("SV_NUMID_SIZES nicht gefunden");
128 sal_uInt32 nSizeTableLen;
129 rStream >> nSizeTableLen;
130 pBuf = new char[nSizeTableLen];
131 rStream.Read( pBuf, nSizeTableLen );
132 pMemStream = new SvMemoryStream( pBuf, nSizeTableLen, STREAM_READ );
134 nEndPos = rStream.Tell();
135 rStream.Seek( nDataPos );
138 //#pragma SEG_FUNCDEF(numhead_07)
140 ImpSvNumMultipleReadHeader::~ImpSvNumMultipleReadHeader()
142 DBG_ASSERT( pMemStream->Tell() == pMemStream->GetSize(),
143 "Sizes nicht vollstaendig gelesen" );
144 delete pMemStream;
145 delete [] pBuf;
147 rStream.Seek(nEndPos);
150 //! mit ctor synchron
151 // static
152 void ImpSvNumMultipleReadHeader::Skip( SvStream& rStream )
154 sal_uInt32 nDataSize;
155 rStream >> nDataSize;
156 rStream.SeekRel( nDataSize );
157 USHORT nID;
158 rStream >> nID;
159 if ( nID != SV_NUMID_SIZES )
161 DBG_ERROR("SV_NUMID_SIZES nicht gefunden");
163 sal_uInt32 nSizeTableLen;
164 rStream >> nSizeTableLen;
165 rStream.SeekRel( nSizeTableLen );
168 //#pragma SEG_FUNCDEF(numhead_08)
170 void ImpSvNumMultipleReadHeader::EndEntry()
172 ULONG nPos = rStream.Tell();
173 DBG_ASSERT( nPos <= nEntryEnd, "zuviel gelesen" );
174 if ( nPos != nEntryEnd )
175 rStream.Seek( nEntryEnd ); // Rest ueberspringen
178 //#pragma SEG_FUNCDEF(numhead_0d)
180 void ImpSvNumMultipleReadHeader::StartEntry()
182 ULONG nPos = rStream.Tell();
183 sal_uInt32 nEntrySize;
184 (*pMemStream) >> nEntrySize;
186 nEntryEnd = nPos + nEntrySize;
189 //#pragma SEG_FUNCDEF(numhead_09)
191 ULONG ImpSvNumMultipleReadHeader::BytesLeft() const
193 ULONG nReadEnd = rStream.Tell();
194 if (nReadEnd <= nEntryEnd)
195 return nEntryEnd-nReadEnd;
197 DBG_ERROR("Fehler bei ImpSvNumMultipleReadHeader::BytesLeft");
198 return 0;
201 // -----------------------------------------------------------------------
203 //#pragma SEG_FUNCDEF(numhead_0a)
205 ImpSvNumMultipleWriteHeader::ImpSvNumMultipleWriteHeader(SvStream& rNewStream,
206 ULONG nDefault) :
207 rStream( rNewStream ),
208 aMemStream( 4096, 4096 )
210 nDataSize = nDefault;
211 rStream << nDataSize;
213 nDataPos = rStream.Tell();
214 nEntryStart = nDataPos;
217 //#pragma SEG_FUNCDEF(numhead_0b)
219 ImpSvNumMultipleWriteHeader::~ImpSvNumMultipleWriteHeader()
221 ULONG nDataEnd = rStream.Tell();
223 rStream << (USHORT) SV_NUMID_SIZES;
224 rStream << static_cast<sal_uInt32>(aMemStream.Tell());
225 rStream.Write( aMemStream.GetData(), aMemStream.Tell() );
227 if ( nDataEnd - nDataPos != nDataSize ) // Default getroffen?
229 nDataSize = nDataEnd - nDataPos;
230 ULONG nPos = rStream.Tell();
231 rStream.Seek(nDataPos-sizeof(sal_uInt32));
232 rStream << nDataSize; // Groesse am Anfang eintragen
233 rStream.Seek(nPos);
237 //#pragma SEG_FUNCDEF(numhead_0c)
239 void ImpSvNumMultipleWriteHeader::EndEntry()
241 ULONG nPos = rStream.Tell();
242 aMemStream << static_cast<sal_uInt32>(nPos - nEntryStart);
245 //#pragma SEG_FUNCDEF(numhead_0e)
247 void ImpSvNumMultipleWriteHeader::StartEntry()
249 ULONG nPos = rStream.Tell();
250 nEntryStart = nPos;