xref: /trunk/main/basic/source/inc/iosys.hxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
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 #ifndef _SBIOSYS_HXX
29 #define _SBIOSYS_HXX
30 
31 #include <tools/stream.hxx>
32 #ifndef _SBERRORS_HXX
33 #include <basic/sberrors.hxx>
34 #endif
35 
36 class SvStream;
37 
38 // Zur Zeit sind globale Dateien (Kanalnummern 256 bis 511)
39 // nicht implementiert.
40 
41 #define CHANNELS 256
42 #define CONSOLE  0
43 
44 #define SBSTRM_INPUT    0x0001      // Input
45 #define SBSTRM_OUTPUT   0x0002      // Output
46 #define SBSTRM_RANDOM   0x0004      // Random
47 #define SBSTRM_APPEND   0x0008      // Append
48 #define SBSTRM_BINARY   0x0010      // Binary
49 
50 class SbiStream {
51     SvStream* pStrm;                // der Stream
52     sal_uIntPtr  nExpandOnWriteTo;      // bei Schreibzugriff, den Stream
53                                     // bis zu dieser Groesse aufblasen
54     ByteString aLine;               // aktuelle Zeile
55     sal_uIntPtr  nLine;                 // aktuelle Zeilennummer
56     short  nLen;                    // Pufferlaenge
57     short  nMode;                   // Bits:
58     short  nChan;                   // aktueller Kanal
59     SbError nError;                 // letzter Fehlercode
60     void   MapError();              // Fehlercode mappen
61 
62 public:
63     SbiStream();
64    ~SbiStream();
65     SbError Open( short, const ByteString&, short, short, short );
66     SbError Close();
67     SbError Read( ByteString&, sal_uInt16 = 0, bool bForceReadingPerByte=false );
68     SbError Read( char& );
69     SbError Write( const ByteString&, sal_uInt16 = 0 );
70 
71     bool IsText() const     { return (nMode & SBSTRM_BINARY) == 0; }
72     bool IsRandom() const   { return (nMode & SBSTRM_RANDOM) != 0; }
73     bool IsBinary() const   { return (nMode & SBSTRM_BINARY) != 0; }
74     bool IsSeq() const      { return (nMode & SBSTRM_RANDOM) == 0; }
75     bool IsAppend() const   { return (nMode & SBSTRM_APPEND) != 0; }
76     short GetBlockLen() const          { return nLen;           }
77     short GetMode() const              { return nMode;          }
78     sal_uIntPtr GetLine() const            { return nLine;          }
79     void SetExpandOnWriteTo( sal_uIntPtr n ) { nExpandOnWriteTo = n;    }
80     void ExpandFile();
81     SvStream* GetStrm()                { return pStrm;          }
82 };
83 
84 class SbiIoSystem {
85     SbiStream* pChan[ CHANNELS ];
86     ByteString  aPrompt;            // Input-Prompt
87     ByteString  aIn, aOut;          // Console-Buffer
88     short     nChan;                // aktueller Kanal
89     SbError   nError;               // letzter Fehlercode
90     void      ReadCon( ByteString& );
91     void      WriteCon( const ByteString& );
92 public:
93     SbiIoSystem();
94    ~SbiIoSystem();
95     SbError GetError();
96     void  Shutdown();
97     void  SetPrompt( const ByteString& r ) { aPrompt = r; }
98     void  SetChannel( short n  )       { nChan = n;   }
99     short GetChannel() const           { return nChan;}
100     void  ResetChannel()               { nChan = 0;   }
101     void  Open( short, const ByteString&, short, short, short );
102     void  Close();
103     void  Read( ByteString&, short = 0 );
104     char  Read();
105     void  Write( const ByteString&, short = 0 );
106     short NextChannel();
107     // 0 == bad channel or no SvStream (nChannel=0..CHANNELS-1)
108     SbiStream* GetStream( short nChannel ) const;
109     void  CloseAll(); // JSM
110 };
111 
112 #endif
113 
114