Kaydet (Commit) c2ac8569 authored tarafından Noel Grandin's avatar Noel Grandin

convert SBSTRM constants to scoped enum

Change-Id: I478a9c7eca6509baf3e9a3dd3ce3dd8f3060f842
üst 6484b2fd
......@@ -174,19 +174,19 @@ void SbiParser::Open()
SbiToken eTok;
TestToken( FOR );
StreamMode nMode = StreamMode::NONE;
short nFlags = 0;
SbiStreamFlags nFlags = SbiStreamFlags::NONE;
switch( Next() )
{
case INPUT:
nMode = StreamMode::READ; nFlags |= SBSTRM_INPUT; break;
nMode = StreamMode::READ; nFlags |= SbiStreamFlags::Input; break;
case OUTPUT:
nMode = StreamMode::WRITE | StreamMode::TRUNC; nFlags |= SBSTRM_OUTPUT; break;
nMode = StreamMode::WRITE | StreamMode::TRUNC; nFlags |= SbiStreamFlags::Output; break;
case APPEND:
nMode = StreamMode::WRITE; nFlags |= SBSTRM_APPEND; break;
nMode = StreamMode::WRITE; nFlags |= SbiStreamFlags::Append; break;
case RANDOM:
nMode = StreamMode::READ | StreamMode::WRITE; nFlags |= SBSTRM_RANDOM; break;
nMode = StreamMode::READ | StreamMode::WRITE; nFlags |= SbiStreamFlags::Random; break;
case BINARY:
nMode = StreamMode::READ | StreamMode::WRITE; nFlags |= SBSTRM_BINARY; break;
nMode = StreamMode::READ | StreamMode::WRITE; nFlags |= SbiStreamFlags::Binary; break;
default:
Error( ERRCODE_BASIC_SYNTAX );
}
......@@ -262,7 +262,7 @@ void SbiParser::Open()
if( pChan )
pChan->Gen();
aFileName.Gen();
aGen.Gen( _OPEN, static_cast<sal_uInt32>(nMode), nFlags );
aGen.Gen( _OPEN, static_cast<sal_uInt32>(nMode), static_cast<sal_uInt32>(nFlags) );
bInStatement = false;
}
......
......@@ -22,6 +22,7 @@
#include <tools/stream.hxx>
#include <basic/sberrors.hxx>
#include <o3tl/typed_flags_set.hxx>
class SvStream;
......@@ -30,11 +31,19 @@ class SvStream;
#define CHANNELS 256
#define SBSTRM_INPUT 0x0001
#define SBSTRM_OUTPUT 0x0002
#define SBSTRM_RANDOM 0x0004
#define SBSTRM_APPEND 0x0008
#define SBSTRM_BINARY 0x0010
enum class SbiStreamFlags
{
NONE = 0x0000,
Input = 0x0001,
Output = 0x0002,
Random = 0x0004,
Append = 0x0008,
Binary = 0x0010,
};
namespace o3tl
{
template<> struct typed_flags<SbiStreamFlags> : is_typed_flags<SbiStreamFlags, 0x1f> {};
}
class SbiStream
{
......@@ -43,7 +52,7 @@ class SbiStream
OString aLine;
sal_uIntPtr nLine;
short nLen; // buffer length
short nMode;
SbiStreamFlags nMode;
short nChan;
SbError nError;
void MapError();
......@@ -51,19 +60,19 @@ class SbiStream
public:
SbiStream();
~SbiStream();
SbError Open( short, const OString&, StreamMode, short, short );
SbError Open( short, const OString&, StreamMode, SbiStreamFlags, short );
SbError Close();
SbError Read(OString&, sal_uInt16 = 0, bool bForceReadingPerByte=false);
SbError Read( char& );
SbError Write( const OString&, sal_uInt16 = 0 );
bool IsText() const { return (nMode & SBSTRM_BINARY) == 0; }
bool IsRandom() const { return (nMode & SBSTRM_RANDOM) != 0; }
bool IsBinary() const { return (nMode & SBSTRM_BINARY) != 0; }
bool IsSeq() const { return (nMode & SBSTRM_RANDOM) == 0; }
bool IsAppend() const { return (nMode & SBSTRM_APPEND) != 0; }
bool IsText() const { return !bool(nMode & SbiStreamFlags::Binary); }
bool IsRandom() const { return bool(nMode & SbiStreamFlags::Random); }
bool IsBinary() const { return bool(nMode & SbiStreamFlags::Binary); }
bool IsSeq() const { return !bool(nMode & SbiStreamFlags::Random); }
bool IsAppend() const { return bool(nMode & SbiStreamFlags::Append); }
short GetBlockLen() const { return nLen; }
short GetMode() const { return nMode; }
SbiStreamFlags GetMode() const { return nMode; }
sal_uIntPtr GetLine() const { return nLine; }
void SetExpandOnWriteTo( sal_uIntPtr n ) { nExpandOnWriteTo = n; }
void ExpandFile();
......@@ -89,7 +98,7 @@ public:
void SetChannel( short n ) { nChan = n; }
short GetChannel() const { return nChan;}
void ResetChannel() { nChan = 0; }
void Open( short, const OString&, StreamMode, short, short );
void Open( short, const OString&, StreamMode, SbiStreamFlags, short );
void Close();
void Read(OString&, short = 0);
char Read();
......
......@@ -137,7 +137,7 @@ SbiStream::SbiStream()
, nExpandOnWriteTo(0)
, nLine(0)
, nLen(0)
, nMode(0)
, nMode(SbiStreamFlags::NONE)
, nChan(0)
, nError(0)
{
......@@ -569,7 +569,7 @@ void UCBStream::SetSize( sal_uInt64 nSize )
SbError SbiStream::Open
( short nCh, const OString& rName, StreamMode nStrmMode, short nFlags, short nL )
( short nCh, const OString& rName, StreamMode nStrmMode, SbiStreamFlags nFlags, short nL )
{
nMode = nFlags;
nLen = nL;
......@@ -794,7 +794,7 @@ SbError SbiIoSystem::GetError()
return n;
}
void SbiIoSystem::Open(short nCh, const OString& rName, StreamMode nMode, short nFlags, short nLen)
void SbiIoSystem::Open(short nCh, const OString& rName, StreamMode nMode, SbiStreamFlags nFlags, short nLen)
{
nError = 0;
if( nCh >= CHANNELS || !nCh )
......
......@@ -1248,7 +1248,7 @@ void PutGet( SbxArray& rPar, bool bPut )
SbiIoSystem* pIO = GetSbData()->pInst->GetIoSystem();
SbiStream* pSbStrm = pIO->GetStream( nFileNo );
if ( !pSbStrm || !(pSbStrm->GetMode() & (SBSTRM_BINARY | SBSTRM_RANDOM)) )
if ( !pSbStrm || !(pSbStrm->GetMode() & (SbiStreamFlags::Binary | SbiStreamFlags::Random)) )
{
StarBASIC::Error( ERRCODE_BASIC_BAD_CHANNEL );
return;
......@@ -3263,7 +3263,7 @@ RTLFUNC(Input)
SbiIoSystem* pIosys = GetSbData()->pInst->GetIoSystem();
SbiStream* pSbStrm = pIosys->GetStream( nFileNumber );
if ( !pSbStrm || !(pSbStrm->GetMode() & (SBSTRM_BINARY | SBSTRM_INPUT)) )
if ( !pSbStrm || !(pSbStrm->GetMode() & (SbiStreamFlags::Binary | SbiStreamFlags::Input)) )
{
StarBASIC::Error( ERRCODE_BASIC_BAD_CHANNEL );
return;
......
......@@ -4308,7 +4308,7 @@ void SbiRuntime::StepOPEN( sal_uInt32 nOp1, sal_uInt32 nOp2 )
short nChan = pChan->GetInteger();
OString aName(OUStringToOString(pName->GetOUString(), osl_getThreadTextEncoding()));
pIosys->Open( nChan, aName, static_cast<StreamMode>( nOp1 ),
static_cast<short>( nOp2 ), nBlkLen );
static_cast<SbiStreamFlags>( nOp2 ), nBlkLen );
Error( pIosys->GetError() );
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment