xref: /aoo4110/main/sw/inc/swgstr.hxx (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 #ifndef _SWGSTR_HXX
24 #define _SWGSTR_HXX
25 
26 #include <tools/stream.hxx>
27 
28 typedef long long3;						// Zur Dokumentation: 3-byte-Longs
29 
30 #define MAX_BEGIN 64					// Maximale Blockschachtelung
31 #define PASSWDLEN 16					// Maximale Passwortlaenge
32 
33 // Neue Version mit SvStreams
34 
35 // Passwort- und Codierungs-Funktionalitaet
36 
37 class swcrypter {
38 protected:
39 	sal_Char   cPasswd[ PASSWDLEN ];	// Passwort-Puffer
40 	sal_Bool   bPasswd;						// sal_True wenn mit Passwort
41 	void   encode( sal_Char*, sal_uInt16 );	// Puffer codieren/decodieren
42 public:
43 	swcrypter();
44 	sal_Bool setpasswd( const String& );	// Passwort setzen
45 	void copypasswd( const sal_Char* );	// Passwort direkt setzen
getpasswd()46 	const sal_Char* getpasswd() { return cPasswd; }
47 };
48 
49 // Reader/Writer-Stream-Basisklasse mit Pufferverwaltung fuer Texte
50 // und Spezial-I/O fuer 3-Byte-Longs
51 
52 class swstreambase : public swcrypter {
53 protected:
54 	SvStream* pStrm;					// eigentlicher Stream
55 	sal_Char*  pBuf; 						// Zwischenpuffer
56 	sal_uInt16 nBuflen;						// Laenge des Zwischenpuffers
57 	short  nLong;						// Long-Laenge (3 oder 4)
58 	sal_Bool   bTempStrm;					// sal_True: Stream loeschen
59 	void   checkbuf( sal_uInt16 );			// Testen der Pufferlaenge
60 
61 	swstreambase( SvStream& );
62 
63 	swstreambase( const swstreambase& );
64 	int operator=( const swstreambase& );
65 public:
66 	~swstreambase();
Strm()67 	SvStream& Strm()					{ return *pStrm; }
68 	void clear();						// Puffer loeschen
69 
70 	// Zusatzfunktionen zur I/O von LONGs als 3-Byte-Zahlen
71 
long3()72 	void long3() 						{ nLong = 3; }
long4()73 	void long4() 						{ nLong = 4; }
74 
75     // Alias- und Hilfsfunktionen
76 
seek(long nPos)77 	void seek( long nPos )				{ pStrm->Seek( nPos );  }
tell()78 	long tell()							{ return pStrm->Tell(); }
79 	long filesize(); 					// Dateigroesse
80 
81 	void setbad();
good()82 	int good()                          { return ( pStrm->GetError() == SVSTREAM_OK ); }
operator !()83     int operator!()                     { return ( pStrm->GetError() != SVSTREAM_OK ); }
eof()84 	int eof()                           { return pStrm->IsEof(); }
85 
86 	sal_uInt8 get();
get(void * p,sal_uInt16 n)87 	void get( void* p, sal_uInt16 n )		{ pStrm->Read( (sal_Char*) p, n ); }
88 
89 	inline swstreambase& operator>>( sal_Char& );
90 	inline swstreambase& operator>>( sal_uInt8& );
91 	inline swstreambase& operator>>( short& );
92 	inline swstreambase& operator>>( sal_uInt16& );
93 		   swstreambase& operator>>( long& );
94 	inline swstreambase& operator>>( sal_uLong& );
95 };
96 
operator >>(sal_Char & c)97 inline swstreambase& swstreambase::operator>>( sal_Char& c )
98 {
99 	*pStrm >> c; return *this;
100 }
101 
operator >>(sal_uInt8 & c)102 inline swstreambase& swstreambase::operator>>( sal_uInt8& c )
103 {
104 	*pStrm >> c; return *this;
105 }
106 
operator >>(short & c)107 inline swstreambase& swstreambase::operator>>( short& c )
108 {
109 	*pStrm >> c; return *this;
110 }
111 
operator >>(sal_uInt16 & c)112 inline swstreambase& swstreambase::operator>>( sal_uInt16& c )
113 {
114 	*pStrm >> c; return *this;
115 }
116 
operator >>(sal_uLong & c)117 inline swstreambase& swstreambase::operator>>( sal_uLong& c )
118 {
119 	return *this >> (long&) c;
120 }
121 
122 class swistream : public swstreambase {
123 	sal_uInt8   cType;						// Record-Typ
124 	sal_uLong  nOffset;						// Record-Offset-Portion
125 public:
126 	swistream( SvStream& );
127 
128 	sal_uInt8 peek();						// 1 Byte testen
129 	sal_uInt8 next();						// Blockstart
cur()130 	sal_uInt8 cur() { return cType; }		// aktueller Block
131 	sal_uInt8 skipnext();					// Record ueberspringen
132 	void undonext();					// next() rueckgaengig machen
getskip()133 	long getskip()						{ return nOffset; }
134 	void skip( long = -1L );			// Block ueberspringen
135 	sal_Char* text();					// Textstring lesen (nach BEGIN)
136 	long size();						// aktuelle Record-Laenge
137 
138 private:
139 	swistream( const swistream& );
140 	int operator=( const swistream& );
141 };
142 
143 
144 #endif
145