[Libreoffice-commits] core.git: basic/source

Noel Grandin noel at peralex.com
Wed Jul 29 03:11:12 PDT 2015


 basic/source/comp/io.cxx          |   14 +++++++-------
 basic/source/inc/iosys.hxx        |   37 +++++++++++++++++++++++--------------
 basic/source/runtime/iosys.cxx    |    6 +++---
 basic/source/runtime/methods1.cxx |    4 ++--
 basic/source/runtime/runtime.cxx  |    2 +-
 5 files changed, 36 insertions(+), 27 deletions(-)

New commits:
commit c2ac8569dea545d75376a7840ed9d8d0792f2aec
Author: Noel Grandin <noel at peralex.com>
Date:   Tue Jul 28 15:04:53 2015 +0200

    convert SBSTRM constants to scoped enum
    
    Change-Id: I478a9c7eca6509baf3e9a3dd3ce3dd8f3060f842

diff --git a/basic/source/comp/io.cxx b/basic/source/comp/io.cxx
index 45b3caf..4a2f2db 100644
--- a/basic/source/comp/io.cxx
+++ b/basic/source/comp/io.cxx
@@ -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;
 }
 
diff --git a/basic/source/inc/iosys.hxx b/basic/source/inc/iosys.hxx
index 85c29ca..a7e7398 100644
--- a/basic/source/inc/iosys.hxx
+++ b/basic/source/inc/iosys.hxx
@@ -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();
diff --git a/basic/source/runtime/iosys.cxx b/basic/source/runtime/iosys.cxx
index 7b1288e..ccc7b16 100644
--- a/basic/source/runtime/iosys.cxx
+++ b/basic/source/runtime/iosys.cxx
@@ -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 )
diff --git a/basic/source/runtime/methods1.cxx b/basic/source/runtime/methods1.cxx
index b6c88c0..5be77d5a 100644
--- a/basic/source/runtime/methods1.cxx
+++ b/basic/source/runtime/methods1.cxx
@@ -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;
diff --git a/basic/source/runtime/runtime.cxx b/basic/source/runtime/runtime.cxx
index cca71b0..303910f 100644
--- a/basic/source/runtime/runtime.cxx
+++ b/basic/source/runtime/runtime.cxx
@@ -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() );
 }
 


More information about the Libreoffice-commits mailing list