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

Steven Guo steventimothyguo at gmail.com
Mon Mar 7 09:06:33 UTC 2016


 basic/source/inc/runtime.hxx     |   17 ++++++++++++-----
 basic/source/runtime/methods.cxx |   36 ++++++++++++++++++------------------
 basic/source/runtime/runtime.cxx |    2 +-
 3 files changed, 31 insertions(+), 24 deletions(-)

New commits:
commit 472d900e81722fd1ce3808c3f46160abcd265f77
Author: Steven Guo <steventimothyguo at gmail.com>
Date:   Sun Mar 6 04:40:30 2016 -0800

    tdf84938 Replaced Sb_Attr_ defined constants with enum class in runtime.hxx
    
    Replaced the #define Sb_Attr_* constants with SbAttributes enum class in runtime.hxx and adjusted uses in methods.cxx.
    
    Change-Id: Ic7f6f6452849ffc9675ffd697ffc130276082318
    Reviewed-on: https://gerrit.libreoffice.org/22948
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noelgrandin at gmail.com>
    Tested-by: Noel Grandin <noelgrandin at gmail.com>

diff --git a/basic/source/inc/runtime.hxx b/basic/source/inc/runtime.hxx
index 2508d9e..aef620b 100644
--- a/basic/source/inc/runtime.hxx
+++ b/basic/source/inc/runtime.hxx
@@ -35,6 +35,7 @@
 #include <com/sun/star/lang/XComponent.hpp>
 #include <com/sun/star/container/XEnumeration.hpp>
 #include <unotools/localedatawrapper.hxx>
+#include <o3tl/typed_flags_set.hxx>
 
 class SbiInstance;                  // active StarBASIC process
 class SbiRuntime;                   // active StarBASIC procedure instance
@@ -94,11 +95,17 @@ struct SbiGosubStack {              // GOSUB-Stack:
     sal_uInt16 nStartForLvl;        // #118235: For Level in moment of gosub
 };
 
+enum class SbAttributes {
+    NONE          = 0x0000,
+    READONLY      = 0x0001,
+    HIDDEN        = 0x0002,
+    DIRECTORY     = 0x0010
+};
 
-#define Sb_ATTR_READONLY    0x0001
-#define Sb_ATTR_HIDDEN      0x0002
-#define Sb_ATTR_DIRECTORY   0x0010
-
+namespace o3tl
+{
+    template<> struct typed_flags<SbAttributes> : is_typed_flags<SbAttributes, 0x13> {};
+}
 
 class WildCard;
 
@@ -107,7 +114,7 @@ class SbiRTLData
 public:
 
     ::osl::Directory* pDir;
-    sal_Int16   nDirFlags;
+    SbAttributes nDirFlags;
     short   nCurDirPos;
 
     OUString sFullNameToBeChecked;
diff --git a/basic/source/runtime/methods.cxx b/basic/source/runtime/methods.cxx
index 85aca7d..97e1eca 100644
--- a/basic/source/runtime/methods.cxx
+++ b/basic/source/runtime/methods.cxx
@@ -2886,17 +2886,17 @@ RTLFUNC(Dir)
                             rPar.Get(0)->PutString( "" );
                         }
 
-                        sal_uInt16 nFlags = 0;
+                        SbAttributes nFlags = SbAttributes::NONE;
                         if ( nParCount > 2 )
                         {
-                            pRTLData->nDirFlags = nFlags = rPar.Get(2)->GetInteger();
+                            pRTLData->nDirFlags = nFlags = static_cast<SbAttributes>(rPar.Get(2)->GetInteger());
                         }
                         else
                         {
-                            pRTLData->nDirFlags = 0;
+                            pRTLData->nDirFlags = SbAttributes::NONE;
                         }
                         // Read directory
-                        bool bIncludeFolders = ((nFlags & Sb_ATTR_DIRECTORY) != 0);
+                        bool bIncludeFolders = bool(nFlags & SbAttributes::DIRECTORY);
                         pRTLData->aDirSeq = xSFI->getFolderContents( aDirURLStr, bIncludeFolders );
                         pRTLData->nCurDirPos = 0;
 
@@ -2923,7 +2923,7 @@ RTLFUNC(Dir)
 
                 if( pRTLData->aDirSeq.getLength() > 0 )
                 {
-                    bool bFolderFlag = ((pRTLData->nDirFlags & Sb_ATTR_DIRECTORY) != 0);
+                    bool bFolderFlag = bool(pRTLData->nDirFlags & SbAttributes::DIRECTORY);
 
                     SbiInstance* pInst = GetSbData()->pInst;
                     bool bCompatibility = ( pInst && pInst->IsCompatibility() );
@@ -3000,18 +3000,18 @@ RTLFUNC(Dir)
 
                 OUString aDirURL = implSetupWildcard( aFileParam, pRTLData );
 
-                sal_uInt16 nFlags = 0;
+                SbAttributes nFlags = SbAttributes::NONE;
                 if ( nParCount > 2 )
                 {
-                    pRTLData->nDirFlags = nFlags = rPar.Get(2)->GetInteger();
+                    pRTLData->nDirFlags = nFlags = static_cast<SbAttributes>( rPar.Get(2)->GetInteger() );
                 }
                 else
                 {
-                    pRTLData->nDirFlags = 0;
+                    pRTLData->nDirFlags = SbAttributes::NONE;
                 }
 
                 // Read directory
-                bool bIncludeFolders = ((nFlags & Sb_ATTR_DIRECTORY) != 0);
+                bool bIncludeFolders = bool(nFlags & SbAttributes::DIRECTORY);
                 pRTLData->pDir = new Directory( aDirURL );
                 FileBase::RC nRet = pRTLData->pDir->open();
                 if( nRet != FileBase::E_None )
@@ -3042,7 +3042,7 @@ RTLFUNC(Dir)
 
             if( pRTLData->pDir )
             {
-                bool bFolderFlag = ((pRTLData->nDirFlags & Sb_ATTR_DIRECTORY) != 0);
+                bool bFolderFlag = bool(pRTLData->nDirFlags & SbAttributes::DIRECTORY);
                 for( ;; )
                 {
                     if( pRTLData->nCurDirPos < 0 )
@@ -3165,15 +3165,15 @@ RTLFUNC(GetAttr)
                     bool bDirectory = xSFI->isFolder( aPath );
                     if( bReadOnly )
                     {
-                        nFlags |= Sb_ATTR_READONLY;
+                        nFlags |= (sal_uInt16)SbAttributes::READONLY;
                     }
                     if( bHidden )
                     {
-                        nFlags |= Sb_ATTR_HIDDEN;
+                        nFlags |= (sal_uInt16)SbAttributes::HIDDEN;
                     }
                     if( bDirectory )
                     {
-                        nFlags |= Sb_ATTR_DIRECTORY;
+                        nFlags |= (sal_uInt16)SbAttributes::DIRECTORY;
                     }
                 }
                 catch(const Exception & )
@@ -3195,11 +3195,11 @@ RTLFUNC(GetAttr)
             bool bDirectory = isFolder( aType );
             if( bReadOnly )
             {
-                nFlags |= Sb_ATTR_READONLY;
+                nFlags |= (sal_uInt16)SbAttributes::READONLY;
             }
             if( bDirectory )
             {
-                nFlags |= Sb_ATTR_DIRECTORY;
+                nFlags |= (sal_uInt16)SbAttributes::DIRECTORY;
             }
         }
         rPar.Get(0)->PutInteger( nFlags );
@@ -4687,7 +4687,7 @@ RTLFUNC(SetAttr)
     if ( rPar.Count() == 3 )
     {
         OUString aStr = rPar.Get(1)->GetOUString();
-        sal_Int16 nFlags = rPar.Get(2)->GetInteger();
+        SbAttributes nFlags = static_cast<SbAttributes>( rPar.Get(2)->GetInteger() );
 
         if( hasUno() )
         {
@@ -4696,9 +4696,9 @@ RTLFUNC(SetAttr)
             {
                 try
                 {
-                    bool bReadOnly = (nFlags & Sb_ATTR_READONLY) != 0;
+                    bool bReadOnly = bool(nFlags & SbAttributes::READONLY);
                     xSFI->setReadOnly( aStr, bReadOnly );
-                    bool bHidden   = (nFlags & Sb_ATTR_HIDDEN) != 0;
+                    bool bHidden   = bool(nFlags & SbAttributes::HIDDEN);
                     xSFI->setHidden( aStr, bHidden );
                 }
                 catch(const Exception & )
diff --git a/basic/source/runtime/runtime.cxx b/basic/source/runtime/runtime.cxx
index caf5727..e6dfa20 100644
--- a/basic/source/runtime/runtime.cxx
+++ b/basic/source/runtime/runtime.cxx
@@ -252,7 +252,7 @@ SbiRuntime::pStep2 SbiRuntime::aStep2[] = {// all opcodes with two operands
 SbiRTLData::SbiRTLData()
 {
     pDir        = nullptr;
-    nDirFlags   = 0;
+    nDirFlags   = SbAttributes::NONE;
     nCurDirPos  = 0;
     pWildCard   = nullptr;
 }


More information about the Libreoffice-commits mailing list