1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_svl.hxx" 30 #ifndef GCC 31 #endif 32 #include <tools/debug.hxx> 33 34 #include "numhead.hxx" 35 36 // ID's fuer Dateien: 37 #define SV_NUMID_SIZES 0x4200 38 39 // STATIC DATA ----------------------------------------------------------- 40 41 //SEG_EOFGLOBALS() 42 43 // ======================================================================= 44 /* wird fuer SvNumberformatter nicht gebraucht 45 //#pragma SEG_FUNCDEF(numhead_01) 46 47 SvNumReadHeader::SvNumReadHeader(SvStream& rNewStream) : 48 rStream( rNewStream ) 49 { 50 sal_uLong nDataSize; 51 rStream >> nDataSize; 52 nDataEnd = rStream.Tell() + nDataSize; 53 } 54 55 //#pragma SEG_FUNCDEF(numhead_02) 56 57 SvNumReadHeader::~SvNumReadHeader() 58 { 59 sal_uLong nReadEnd = rStream.Tell(); 60 DBG_ASSERT( nReadEnd <= nDataEnd, "zuviele Bytes gelesen" ); 61 if ( nReadEnd != nDataEnd ) 62 rStream.Seek(nDataEnd); // Rest ueberspringen 63 } 64 65 //#pragma SEG_FUNCDEF(numhead_03) 66 67 sal_uLong SvNumReadHeader::BytesLeft() const 68 { 69 sal_uLong nReadEnd = rStream.Tell(); 70 if (nReadEnd <= nDataEnd) 71 return nDataEnd-nReadEnd; 72 73 DBG_ERROR("Fehler bei SvNumReadHeader::BytesLeft"); 74 return 0; 75 } 76 77 // ----------------------------------------------------------------------- 78 79 //#pragma SEG_FUNCDEF(numhead_04) 80 81 SvNumWriteHeader::SvNumWriteHeader(SvStream& rNewStream, sal_uLong nDefault) : 82 rStream( rNewStream ) 83 { 84 nDataSize = nDefault; 85 rStream << nDataSize; 86 nDataPos = rStream.Tell(); 87 } 88 89 //#pragma SEG_FUNCDEF(numhead_05) 90 91 SvNumWriteHeader::~SvNumWriteHeader() 92 { 93 sal_uLong nPos = rStream.Tell(); 94 95 if ( nPos - nDataPos != nDataSize ) // Default getroffen? 96 { 97 nDataSize = nPos - nDataPos; 98 rStream.Seek(nDataPos - sizeof(sal_uInt32)); 99 rStream << nDataSize; // Groesse am Anfang eintragen 100 rStream.Seek(nPos); 101 } 102 } 103 */ 104 105 // ======================================================================= 106 107 //#pragma SEG_FUNCDEF(numhead_06) 108 109 //! mit Skip() synchron 110 ImpSvNumMultipleReadHeader::ImpSvNumMultipleReadHeader(SvStream& rNewStream) : 111 rStream( rNewStream ) 112 { 113 sal_uInt32 nDataSize; 114 rStream >> nDataSize; 115 sal_uLong nDataPos = rStream.Tell(); 116 nEntryEnd = nDataPos; 117 118 rStream.SeekRel(nDataSize); 119 sal_uInt16 nID; 120 rStream >> nID; 121 if (nID != SV_NUMID_SIZES) 122 { 123 DBG_ERROR("SV_NUMID_SIZES nicht gefunden"); 124 } 125 sal_uInt32 nSizeTableLen; 126 rStream >> nSizeTableLen; 127 pBuf = new char[nSizeTableLen]; 128 rStream.Read( pBuf, nSizeTableLen ); 129 pMemStream = new SvMemoryStream( pBuf, nSizeTableLen, STREAM_READ ); 130 131 nEndPos = rStream.Tell(); 132 rStream.Seek( nDataPos ); 133 } 134 135 //#pragma SEG_FUNCDEF(numhead_07) 136 137 ImpSvNumMultipleReadHeader::~ImpSvNumMultipleReadHeader() 138 { 139 DBG_ASSERT( pMemStream->Tell() == pMemStream->GetEndOfData(), 140 "Sizes nicht vollstaendig gelesen" ); 141 delete pMemStream; 142 delete [] pBuf; 143 144 rStream.Seek(nEndPos); 145 } 146 147 //! mit ctor synchron 148 // static 149 void ImpSvNumMultipleReadHeader::Skip( SvStream& rStream ) 150 { 151 sal_uInt32 nDataSize; 152 rStream >> nDataSize; 153 rStream.SeekRel( nDataSize ); 154 sal_uInt16 nID; 155 rStream >> nID; 156 if ( nID != SV_NUMID_SIZES ) 157 { 158 DBG_ERROR("SV_NUMID_SIZES nicht gefunden"); 159 } 160 sal_uInt32 nSizeTableLen; 161 rStream >> nSizeTableLen; 162 rStream.SeekRel( nSizeTableLen ); 163 } 164 165 //#pragma SEG_FUNCDEF(numhead_08) 166 167 void ImpSvNumMultipleReadHeader::EndEntry() 168 { 169 sal_uLong nPos = rStream.Tell(); 170 DBG_ASSERT( nPos <= nEntryEnd, "zuviel gelesen" ); 171 if ( nPos != nEntryEnd ) 172 rStream.Seek( nEntryEnd ); // Rest ueberspringen 173 } 174 175 //#pragma SEG_FUNCDEF(numhead_0d) 176 177 void ImpSvNumMultipleReadHeader::StartEntry() 178 { 179 sal_uLong nPos = rStream.Tell(); 180 sal_uInt32 nEntrySize; 181 (*pMemStream) >> nEntrySize; 182 183 nEntryEnd = nPos + nEntrySize; 184 } 185 186 //#pragma SEG_FUNCDEF(numhead_09) 187 188 sal_uLong ImpSvNumMultipleReadHeader::BytesLeft() const 189 { 190 sal_uLong nReadEnd = rStream.Tell(); 191 if (nReadEnd <= nEntryEnd) 192 return nEntryEnd-nReadEnd; 193 194 DBG_ERROR("Fehler bei ImpSvNumMultipleReadHeader::BytesLeft"); 195 return 0; 196 } 197 198 // ----------------------------------------------------------------------- 199 200 //#pragma SEG_FUNCDEF(numhead_0a) 201 202 ImpSvNumMultipleWriteHeader::ImpSvNumMultipleWriteHeader(SvStream& rNewStream, 203 sal_uLong nDefault) : 204 rStream( rNewStream ), 205 aMemStream( 4096, 4096 ) 206 { 207 nDataSize = nDefault; 208 rStream << nDataSize; 209 210 nDataPos = rStream.Tell(); 211 nEntryStart = nDataPos; 212 } 213 214 //#pragma SEG_FUNCDEF(numhead_0b) 215 216 ImpSvNumMultipleWriteHeader::~ImpSvNumMultipleWriteHeader() 217 { 218 sal_uLong nDataEnd = rStream.Tell(); 219 220 rStream << (sal_uInt16) SV_NUMID_SIZES; 221 rStream << static_cast<sal_uInt32>(aMemStream.Tell()); 222 rStream.Write( aMemStream.GetData(), aMemStream.Tell() ); 223 224 if ( nDataEnd - nDataPos != nDataSize ) // Default getroffen? 225 { 226 nDataSize = nDataEnd - nDataPos; 227 sal_uLong nPos = rStream.Tell(); 228 rStream.Seek(nDataPos-sizeof(sal_uInt32)); 229 rStream << nDataSize; // Groesse am Anfang eintragen 230 rStream.Seek(nPos); 231 } 232 } 233 234 //#pragma SEG_FUNCDEF(numhead_0c) 235 236 void ImpSvNumMultipleWriteHeader::EndEntry() 237 { 238 sal_uLong nPos = rStream.Tell(); 239 aMemStream << static_cast<sal_uInt32>(nPos - nEntryStart); 240 } 241 242 //#pragma SEG_FUNCDEF(numhead_0e) 243 244 void ImpSvNumMultipleWriteHeader::StartEntry() 245 { 246 sal_uLong nPos = rStream.Tell(); 247 nEntryStart = nPos; 248 } 249 250