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