1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: swgstr.hxx,v $
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 ************************************************************************/
34 #ifndef _STREAM_HXX //autogen
35 #include <tools/stream.hxx>
39 typedef long long3
; // Zur Dokumentation: 3-byte-Longs
41 #define MAX_BEGIN 64 // Maximale Blockschachtelung
42 #define PASSWDLEN 16 // Maximale Passwortlaenge
44 // Neue Version mit SvStreams
46 // Passwort- und Codierungs-Funktionalitaet
50 sal_Char cPasswd
[ PASSWDLEN
]; // Passwort-Puffer
51 BOOL bPasswd
; // TRUE wenn mit Passwort
52 void encode( sal_Char
*, USHORT
); // Puffer codieren/decodieren
55 BOOL
setpasswd( const String
& ); // Passwort setzen
56 void copypasswd( const sal_Char
* ); // Passwort direkt setzen
57 const sal_Char
* getpasswd() { return cPasswd
; }
60 // Reader/Writer-Stream-Basisklasse mit Pufferverwaltung fuer Texte
61 // und Spezial-I/O fuer 3-Byte-Longs
63 class swstreambase
: public swcrypter
{
65 SvStream
* pStrm
; // eigentlicher Stream
66 sal_Char
* pBuf
; // Zwischenpuffer
67 USHORT nBuflen
; // Laenge des Zwischenpuffers
68 short nLong
; // Long-Laenge (3 oder 4)
69 BOOL bTempStrm
; // TRUE: Stream loeschen
70 void checkbuf( USHORT
); // Testen der Pufferlaenge
72 swstreambase( SvStream
& );
74 swstreambase( const swstreambase
& );
75 int operator=( const swstreambase
& );
78 SvStream
& Strm() { return *pStrm
; }
79 sal_Char
* GetBuf() { return pBuf
; }
81 // Zusatzfunktionen zur I/O von LONGs als 3-Byte-Zahlen
83 void long3() { nLong
= 3; }
84 void long4() { nLong
= 4; }
86 void sync( swstreambase
& r
) { pStrm
->Seek( r
.tell() ); }
88 // Alias- und Hilfsfunktionen
90 void seek( long nPos
) { pStrm
->Seek( nPos
); }
91 long tell() { return pStrm
->Tell(); }
92 long filesize(); // Dateigroesse
93 void flush() { pStrm
->Flush(); }
96 int good() { return ( pStrm
->GetError() == SVSTREAM_OK
); }
97 int bad() { return ( pStrm
->GetError() != SVSTREAM_OK
); }
98 int operator!() { return ( pStrm
->GetError() != SVSTREAM_OK
); }
99 int eof() { return pStrm
->IsEof(); }
102 void get( void* p
, USHORT n
) { pStrm
->Read( (sal_Char
*) p
, n
); }
104 inline swstreambase
& operator>>( sal_Char
& );
105 inline swstreambase
& operator>>( BYTE
& );
106 inline swstreambase
& operator>>( short& );
107 inline swstreambase
& operator>>( USHORT
& );
108 swstreambase
& operator>>( long& );
109 inline swstreambase
& operator>>( ULONG
& );
112 inline swstreambase
& swstreambase::operator>>( sal_Char
& c
)
114 *pStrm
>> c
; return *this;
117 inline swstreambase
& swstreambase::operator>>( BYTE
& c
)
119 *pStrm
>> c
; return *this;
122 inline swstreambase
& swstreambase::operator>>( short& c
)
124 *pStrm
>> c
; return *this;
127 inline swstreambase
& swstreambase::operator>>( USHORT
& c
)
129 *pStrm
>> c
; return *this;
132 inline swstreambase
& swstreambase::operator>>( ULONG
& c
)
134 return *this >> (long&) c
;
137 class swistream
: public swstreambase
{
138 BYTE cType
; // Record-Typ
139 ULONG nOffset
; // Record-Offset-Portion
141 swistream( SvStream
& );
143 BYTE
peek(); // 1 Byte testen
144 BYTE
next(); // Blockstart
145 BYTE
cur() { return cType
; } // aktueller Block
146 BYTE
skipnext(); // Record ueberspringen
147 void undonext(); // next() rueckgaengig machen
148 long getskip() { return nOffset
; }
149 void skip( long = -1L ); // Block ueberspringen
150 sal_Char
* text(); // Textstring lesen (nach BEGIN)
151 long size(); // aktuelle Record-Laenge
154 swistream( const swistream
& );
155 int operator=( const swistream
& );
159 } //namespace binfilter