xref: /aoo4110/main/svl/source/numbers/numhead.cxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svl.hxx"
26 #ifndef GCC
27 #endif
28 #include <tools/debug.hxx>
29 
30 #include "numhead.hxx"
31 
32 //		ID's fuer Dateien:
33 #define SV_NUMID_SIZES						0x4200
34 
35 // STATIC DATA -----------------------------------------------------------
36 
37 //SEG_EOFGLOBALS()
38 
39 // =======================================================================
40 /*								wird fuer SvNumberformatter nicht gebraucht
41 //#pragma SEG_FUNCDEF(numhead_01)
42 
43 SvNumReadHeader::SvNumReadHeader(SvStream& rNewStream) :
44 	rStream( rNewStream )
45 {
46 	sal_uLong nDataSize;
47 	rStream >> nDataSize;
48 	nDataEnd = rStream.Tell() + nDataSize;
49 }
50 
51 //#pragma SEG_FUNCDEF(numhead_02)
52 
53 SvNumReadHeader::~SvNumReadHeader()
54 {
55 	sal_uLong nReadEnd = rStream.Tell();
56 	DBG_ASSERT( nReadEnd <= nDataEnd, "zuviele Bytes gelesen" );
57 	if ( nReadEnd != nDataEnd )
58 		rStream.Seek(nDataEnd); 					// Rest ueberspringen
59 }
60 
61 //#pragma SEG_FUNCDEF(numhead_03)
62 
63 sal_uLong SvNumReadHeader::BytesLeft() const
64 {
65 	sal_uLong nReadEnd = rStream.Tell();
66 	if (nReadEnd <= nDataEnd)
67 		return nDataEnd-nReadEnd;
68 
69 	DBG_ERROR("Fehler bei SvNumReadHeader::BytesLeft");
70 	return 0;
71 }
72 
73 // -----------------------------------------------------------------------
74 
75 //#pragma SEG_FUNCDEF(numhead_04)
76 
77 SvNumWriteHeader::SvNumWriteHeader(SvStream& rNewStream, sal_uLong nDefault) :
78 	rStream( rNewStream )
79 {
80 	nDataSize = nDefault;
81 	rStream << nDataSize;
82 	nDataPos = rStream.Tell();
83 }
84 
85 //#pragma SEG_FUNCDEF(numhead_05)
86 
87 SvNumWriteHeader::~SvNumWriteHeader()
88 {
89 	sal_uLong nPos = rStream.Tell();
90 
91 	if ( nPos - nDataPos != nDataSize )				// Default getroffen?
92 	{
93 		nDataSize = nPos - nDataPos;
94 		rStream.Seek(nDataPos - sizeof(sal_uInt32));
95 		rStream << nDataSize;						// Groesse am Anfang eintragen
96 		rStream.Seek(nPos);
97 	}
98 }
99 */
100 
101 // =======================================================================
102 
103 //#pragma SEG_FUNCDEF(numhead_06)
104 
105 //! mit Skip() synchron
ImpSvNumMultipleReadHeader(SvStream & rNewStream)106 ImpSvNumMultipleReadHeader::ImpSvNumMultipleReadHeader(SvStream& rNewStream) :
107 	rStream( rNewStream )
108 {
109 	sal_uInt32 nDataSize;
110 	rStream >> nDataSize;
111 	sal_uLong nDataPos = rStream.Tell();
112 	nEntryEnd = nDataPos;
113 
114 	rStream.SeekRel(nDataSize);
115 	sal_uInt16 nID;
116 	rStream >> nID;
117 	if (nID != SV_NUMID_SIZES)
118 	{
119 		DBG_ERROR("SV_NUMID_SIZES nicht gefunden");
120 	}
121 	sal_uInt32 nSizeTableLen;
122 	rStream >> nSizeTableLen;
123 	pBuf = new char[nSizeTableLen];
124 	rStream.Read( pBuf, nSizeTableLen );
125 	pMemStream = new SvMemoryStream( pBuf, nSizeTableLen, STREAM_READ );
126 
127 	nEndPos = rStream.Tell();
128 	rStream.Seek( nDataPos );
129 }
130 
131 //#pragma SEG_FUNCDEF(numhead_07)
132 
~ImpSvNumMultipleReadHeader()133 ImpSvNumMultipleReadHeader::~ImpSvNumMultipleReadHeader()
134 {
135     DBG_ASSERT( pMemStream->Tell() == pMemStream->GetEndOfData(),
136 				"Sizes nicht vollstaendig gelesen" );
137 	delete pMemStream;
138 	delete [] pBuf;
139 
140 	rStream.Seek(nEndPos);
141 }
142 
143 //! mit ctor synchron
144 // static
Skip(SvStream & rStream)145 void ImpSvNumMultipleReadHeader::Skip( SvStream& rStream )
146 {
147 	sal_uInt32 nDataSize;
148 	rStream >> nDataSize;
149 	rStream.SeekRel( nDataSize );
150 	sal_uInt16 nID;
151 	rStream >> nID;
152 	if ( nID != SV_NUMID_SIZES )
153 	{
154 		DBG_ERROR("SV_NUMID_SIZES nicht gefunden");
155 	}
156 	sal_uInt32 nSizeTableLen;
157 	rStream >> nSizeTableLen;
158 	rStream.SeekRel( nSizeTableLen );
159 }
160 
161 //#pragma SEG_FUNCDEF(numhead_08)
162 
EndEntry()163 void ImpSvNumMultipleReadHeader::EndEntry()
164 {
165 	sal_uLong nPos = rStream.Tell();
166 	DBG_ASSERT( nPos <= nEntryEnd, "zuviel gelesen" );
167 	if ( nPos != nEntryEnd )
168 		rStream.Seek( nEntryEnd );			// Rest ueberspringen
169 }
170 
171 //#pragma SEG_FUNCDEF(numhead_0d)
172 
StartEntry()173 void ImpSvNumMultipleReadHeader::StartEntry()
174 {
175 	sal_uLong nPos = rStream.Tell();
176 	sal_uInt32 nEntrySize;
177 	(*pMemStream) >> nEntrySize;
178 
179 	nEntryEnd = nPos + nEntrySize;
180 }
181 
182 //#pragma SEG_FUNCDEF(numhead_09)
183 
BytesLeft() const184 sal_uLong ImpSvNumMultipleReadHeader::BytesLeft() const
185 {
186 	sal_uLong nReadEnd = rStream.Tell();
187 	if (nReadEnd <= nEntryEnd)
188 		return nEntryEnd-nReadEnd;
189 
190 	DBG_ERROR("Fehler bei ImpSvNumMultipleReadHeader::BytesLeft");
191 	return 0;
192 }
193 
194 // -----------------------------------------------------------------------
195 
196 //#pragma SEG_FUNCDEF(numhead_0a)
197 
ImpSvNumMultipleWriteHeader(SvStream & rNewStream,sal_uLong nDefault)198 ImpSvNumMultipleWriteHeader::ImpSvNumMultipleWriteHeader(SvStream& rNewStream,
199 												   sal_uLong nDefault) :
200 	rStream( rNewStream ),
201 	aMemStream( 4096, 4096 )
202 {
203 	nDataSize = nDefault;
204 	rStream << nDataSize;
205 
206 	nDataPos = rStream.Tell();
207 	nEntryStart = nDataPos;
208 }
209 
210 //#pragma SEG_FUNCDEF(numhead_0b)
211 
~ImpSvNumMultipleWriteHeader()212 ImpSvNumMultipleWriteHeader::~ImpSvNumMultipleWriteHeader()
213 {
214 	sal_uLong nDataEnd = rStream.Tell();
215 
216 	rStream << (sal_uInt16) SV_NUMID_SIZES;
217 	rStream << static_cast<sal_uInt32>(aMemStream.Tell());
218 	rStream.Write( aMemStream.GetData(), aMemStream.Tell() );
219 
220 	if ( nDataEnd - nDataPos != nDataSize )					// Default getroffen?
221 	{
222 		nDataSize = nDataEnd - nDataPos;
223 		sal_uLong nPos = rStream.Tell();
224 		rStream.Seek(nDataPos-sizeof(sal_uInt32));
225 		rStream << nDataSize;								// Groesse am Anfang eintragen
226 		rStream.Seek(nPos);
227 	}
228 }
229 
230 //#pragma SEG_FUNCDEF(numhead_0c)
231 
EndEntry()232 void ImpSvNumMultipleWriteHeader::EndEntry()
233 {
234 	sal_uLong nPos = rStream.Tell();
235 	aMemStream << static_cast<sal_uInt32>(nPos - nEntryStart);
236 }
237 
238 //#pragma SEG_FUNCDEF(numhead_0e)
239 
StartEntry()240 void ImpSvNumMultipleWriteHeader::StartEntry()
241 {
242 	sal_uLong nPos = rStream.Tell();
243 	nEntryStart = nPos;
244 }
245 
246