LibreOffice Module basic (master) 1
iosys.hxx
Go to the documentation of this file.
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#pragma once
21
22#include <memory>
23#include <string_view>
24
25#include <tools/stream.hxx>
27
28class SvStream;
29
30// Global files (channel numbers 256 to 511) are not
31// implemented at the moment.
32
33#define CHANNELS 256
34
36{
37 NONE = 0x0000,
38 Input = 0x0001,
39 Output = 0x0002,
40 Random = 0x0004,
41 Append = 0x0008,
42 Binary = 0x0010,
43};
44namespace o3tl
45{
46 template<> struct typed_flags<SbiStreamFlags> : is_typed_flags<SbiStreamFlags, 0x1f> {};
47}
48
50{
51 std::unique_ptr<SvStream> pStrm;
52 sal_uInt64 nExpandOnWriteTo; // during writing access expand the stream to this size
53 OString aLine;
54 sal_uInt64 nLine;
55 short nLen; // buffer length
58 void MapError();
59
60public:
61 SbiStream();
62 ~SbiStream();
63 ErrCode const & Open( std::string_view, StreamMode, SbiStreamFlags, short );
64 ErrCode const & Close();
65 ErrCode Read(OString&, sal_uInt16 = 0, bool bForceReadingPerByte=false);
66 ErrCode const & Read( char& );
67 ErrCode Write( const OString& );
68
69 bool IsText() const { return !bool(nMode & SbiStreamFlags::Binary); }
70 bool IsRandom() const { return bool(nMode & SbiStreamFlags::Random); }
71 bool IsBinary() const { return bool(nMode & SbiStreamFlags::Binary); }
72 bool IsSeq() const { return !bool(nMode & SbiStreamFlags::Random); }
73 bool IsAppend() const { return bool(nMode & SbiStreamFlags::Append); }
74 short GetBlockLen() const { return nLen; }
75 SbiStreamFlags GetMode() const { return nMode; }
76 sal_uInt64 GetLine() const { return nLine; }
77 void SetExpandOnWriteTo( sal_uInt64 n ) { nExpandOnWriteTo = n; }
78 void ExpandFile();
79 SvStream* GetStrm() { return pStrm.get(); }
80};
81
83{
85 OString aPrompt;
86 OString aIn;
87 OUString aOut;
88 short nChan;
90 void ReadCon(OString&);
91 void WriteCon(std::u16string_view);
92public:
94 ~SbiIoSystem() COVERITY_NOEXCEPT_FALSE;
96 void Shutdown();
97 void SetPrompt(const OString& 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, std::string_view, StreamMode, SbiStreamFlags, short );
102 void Close();
103 void Read(OString&);
104 char Read();
105 void Write(std::u16string_view);
106 // 0 == bad channel or no SvStream (nChannel=0..CHANNELS-1)
107 SbiStream* GetStream( short nChannel ) const;
108 void CloseAll(); // JSM
109};
110
111/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
~SbiIoSystem() COVERITY_NOEXCEPT_FALSE
Definition: iosys.cxx:617
void Write(std::u16string_view)
Definition: iosys.cxx:741
char Read()
Definition: iosys.cxx:717
ErrCode nError
Definition: iosys.hxx:89
OString aIn
Definition: iosys.hxx:86
SbiIoSystem()
Definition: iosys.cxx:607
SbiStream * GetStream(short nChannel) const
Definition: iosys.cxx:759
void SetPrompt(const OString &r)
Definition: iosys.hxx:97
short GetChannel() const
Definition: iosys.hxx:99
short nChan
Definition: iosys.hxx:88
OUString aOut
Definition: iosys.hxx:87
void SetChannel(short n)
Definition: iosys.hxx:98
void WriteCon(std::u16string_view)
Definition: iosys.cxx:803
ErrCode GetError()
Definition: iosys.cxx:622
void Shutdown()
Definition: iosys.cxx:674
void Open(short, std::string_view, StreamMode, SbiStreamFlags, short)
Definition: iosys.cxx:629
void CloseAll()
Definition: iosys.cxx:769
void Close()
Definition: iosys.cxx:654
SbiStream * pChan[CHANNELS]
Definition: iosys.hxx:84
OString aPrompt
Definition: iosys.hxx:85
void ResetChannel()
Definition: iosys.hxx:100
void ReadCon(OString &)
Definition: iosys.cxx:786
~SbiStream()
Definition: iosys.cxx:100
sal_uInt64 nExpandOnWriteTo
Definition: iosys.hxx:52
bool IsRandom() const
Definition: iosys.hxx:70
bool IsText() const
Definition: iosys.hxx:69
short nLen
Definition: iosys.hxx:55
SbiStreamFlags GetMode() const
Definition: iosys.hxx:75
bool IsAppend() const
Definition: iosys.hxx:73
SbiStreamFlags nMode
Definition: iosys.hxx:56
ErrCode const & Close()
Definition: iosys.cxx:484
short GetBlockLen() const
Definition: iosys.hxx:74
OString aLine
Definition: iosys.hxx:53
ErrCode nError
Definition: iosys.hxx:57
SbiStream()
Definition: iosys.cxx:91
ErrCode const & Open(std::string_view, StreamMode, SbiStreamFlags, short)
Definition: iosys.cxx:419
SvStream * GetStrm()
Definition: iosys.hxx:79
bool IsBinary() const
Definition: iosys.hxx:71
void MapError()
Definition: iosys.cxx:106
bool IsSeq() const
Definition: iosys.hxx:72
void ExpandFile()
Definition: iosys.cxx:539
sal_uInt64 nLine
Definition: iosys.hxx:54
ErrCode Read(OString &, sal_uInt16=0, bool bForceReadingPerByte=false)
Definition: iosys.cxx:494
sal_uInt64 GetLine() const
Definition: iosys.hxx:76
ErrCode Write(const OString &)
Definition: iosys.cxx:570
std::unique_ptr< SvStream > pStrm
Definition: iosys.hxx:51
void SetExpandOnWriteTo(sal_uInt64 n)
Definition: iosys.hxx:77
SbiStreamFlags
Definition: iosys.hxx:36
#define CHANNELS
Definition: iosys.hxx:33
sal_Int64 n
def Input(s)
NONE
StreamMode