Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #ifndef INCLUDED_BASIC_SOURCE_INC_IOSYS_HXX
21 : #define INCLUDED_BASIC_SOURCE_INC_IOSYS_HXX
22 :
23 : #include <tools/stream.hxx>
24 : #include <basic/sberrors.hxx>
25 :
26 : class SvStream;
27 :
28 : // Global files (channel numbers 256 to 511) are not
29 : // implemented at the moment.
30 :
31 : #define CHANNELS 256
32 :
33 : #define SBSTRM_INPUT 0x0001
34 : #define SBSTRM_OUTPUT 0x0002
35 : #define SBSTRM_RANDOM 0x0004
36 : #define SBSTRM_APPEND 0x0008
37 : #define SBSTRM_BINARY 0x0010
38 :
39 : class SbiStream
40 : {
41 : SvStream* pStrm;
42 : sal_uIntPtr nExpandOnWriteTo; // during writing access expand the stream to this size
43 : OString aLine;
44 : sal_uIntPtr nLine;
45 : short nLen; // buffer length
46 : short nMode;
47 : short nChan;
48 : SbError nError;
49 : void MapError();
50 :
51 : public:
52 : SbiStream();
53 : ~SbiStream();
54 : SbError Open( short, const OString&, short, short, short );
55 : SbError Close();
56 : SbError Read(OString&, sal_uInt16 = 0, bool bForceReadingPerByte=false);
57 : SbError Read( char& );
58 : SbError Write( const OString&, sal_uInt16 = 0 );
59 :
60 334 : bool IsText() const { return (nMode & SBSTRM_BINARY) == 0; }
61 0 : bool IsRandom() const { return (nMode & SBSTRM_RANDOM) != 0; }
62 24 : bool IsBinary() const { return (nMode & SBSTRM_BINARY) != 0; }
63 0 : bool IsSeq() const { return (nMode & SBSTRM_RANDOM) == 0; }
64 382 : bool IsAppend() const { return (nMode & SBSTRM_APPEND) != 0; }
65 0 : short GetBlockLen() const { return nLen; }
66 0 : short GetMode() const { return nMode; }
67 0 : sal_uIntPtr GetLine() const { return nLine; }
68 0 : void SetExpandOnWriteTo( sal_uIntPtr n ) { nExpandOnWriteTo = n; }
69 : void ExpandFile();
70 0 : SvStream* GetStrm() { return pStrm; }
71 : };
72 :
73 : class SbiIoSystem
74 : {
75 : SbiStream* pChan[ CHANNELS ];
76 : OString aPrompt;
77 : OString aIn;
78 : OUString aOut;
79 : short nChan;
80 : SbError nError;
81 : void ReadCon(OString&);
82 : void WriteCon(const OUString&);
83 : public:
84 : SbiIoSystem();
85 : ~SbiIoSystem();
86 : SbError GetError();
87 : void Shutdown();
88 0 : void SetPrompt(const OString& r) { aPrompt = r; }
89 190 : void SetChannel( short n ) { nChan = n; }
90 0 : short GetChannel() const { return nChan;}
91 168 : void ResetChannel() { nChan = 0; }
92 : void Open( short, const OString&, short, short, short );
93 : void Close();
94 : void Read(OString&, short = 0);
95 : char Read();
96 : void Write(const OUString&, short = 0);
97 : // 0 == bad channel or no SvStream (nChannel=0..CHANNELS-1)
98 : SbiStream* GetStream( short nChannel ) const;
99 : void CloseAll(); // JSM
100 : };
101 :
102 : #endif
103 :
104 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|