Version 7.1.7.1, tag libreoffice-7.1.7.1
[LibreOffice.git] / basic / source / inc / iosys.hxx
blob9f60c4f29c50f4bc8e8e6760cacb8d6fc94834b1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #pragma once
22 #include <memory>
23 #include <tools/stream.hxx>
24 #include <o3tl/typed_flags_set.hxx>
26 class SvStream;
28 // Global files (channel numbers 256 to 511) are not
29 // implemented at the moment.
31 #define CHANNELS 256
33 enum class SbiStreamFlags
35 NONE = 0x0000,
36 Input = 0x0001,
37 Output = 0x0002,
38 Random = 0x0004,
39 Append = 0x0008,
40 Binary = 0x0010,
42 namespace o3tl
44 template<> struct typed_flags<SbiStreamFlags> : is_typed_flags<SbiStreamFlags, 0x1f> {};
47 class SbiStream
49 std::unique_ptr<SvStream> pStrm;
50 sal_uInt64 nExpandOnWriteTo; // during writing access expand the stream to this size
51 OString aLine;
52 sal_uInt64 nLine;
53 short nLen; // buffer length
54 SbiStreamFlags nMode;
55 ErrCode nError;
56 void MapError();
58 public:
59 SbiStream();
60 ~SbiStream();
61 ErrCode const & Open( const OString&, StreamMode, SbiStreamFlags, short );
62 ErrCode const & Close();
63 ErrCode Read(OString&, sal_uInt16 = 0, bool bForceReadingPerByte=false);
64 ErrCode const & Read( char& );
65 ErrCode Write( const OString& );
67 bool IsText() const { return !bool(nMode & SbiStreamFlags::Binary); }
68 bool IsRandom() const { return bool(nMode & SbiStreamFlags::Random); }
69 bool IsBinary() const { return bool(nMode & SbiStreamFlags::Binary); }
70 bool IsSeq() const { return !bool(nMode & SbiStreamFlags::Random); }
71 bool IsAppend() const { return bool(nMode & SbiStreamFlags::Append); }
72 short GetBlockLen() const { return nLen; }
73 SbiStreamFlags GetMode() const { return nMode; }
74 sal_uInt64 GetLine() const { return nLine; }
75 void SetExpandOnWriteTo( sal_uInt64 n ) { nExpandOnWriteTo = n; }
76 void ExpandFile();
77 SvStream* GetStrm() { return pStrm.get(); }
80 class SbiIoSystem
82 SbiStream* pChan[ CHANNELS ];
83 OString aPrompt;
84 OString aIn;
85 OUString aOut;
86 short nChan;
87 ErrCode nError;
88 void ReadCon(OString&);
89 void WriteCon(const OUString&);
90 public:
91 SbiIoSystem();
92 ~SbiIoSystem() COVERITY_NOEXCEPT_FALSE;
93 ErrCode GetError();
94 void Shutdown();
95 void SetPrompt(const OString& r) { aPrompt = r; }
96 void SetChannel( short n ) { nChan = n; }
97 short GetChannel() const { return nChan;}
98 void ResetChannel() { nChan = 0; }
99 void Open( short, const OString&, StreamMode, SbiStreamFlags, short );
100 void Close();
101 void Read(OString&);
102 char Read();
103 void Write(const OUString&);
104 // 0 == bad channel or no SvStream (nChannel=0..CHANNELS-1)
105 SbiStream* GetStream( short nChannel ) const;
106 void CloseAll(); // JSM
109 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */