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

Arnaud Versini (via logerrit) logerrit at kemper.freedesktop.org
Sun Aug 29 06:53:20 UTC 2021


 basic/source/basmgr/basmgr.cxx |  107 ++++++++++++++++-------------------------
 include/basic/basmgr.hxx       |   11 ++--
 2 files changed, 49 insertions(+), 69 deletions(-)

New commits:
commit 34cba9eefa710b053da817dd2642d2376691824e
Author:     Arnaud Versini <arnaud.versini at libreoffice.org>
AuthorDate: Sun Aug 22 14:48:38 2021 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Sun Aug 29 08:52:48 2021 +0200

    basic : remove BasicManagerImpl
    
    Change-Id: Ia2b2c5fdf7d61e0853f181a38840c5ae263f5c9f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/105141
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/basic/source/basmgr/basmgr.cxx b/basic/source/basmgr/basmgr.cxx
index 1cbd407f2171..03fe6ef6597c 100644
--- a/basic/source/basmgr/basmgr.cxx
+++ b/basic/source/basmgr/basmgr.cxx
@@ -95,19 +95,6 @@ constexpr OStringLiteral szCryptingKey = "CryptedBasic";
 const StreamMode eStreamReadMode = StreamMode::READ | StreamMode::NOCREATE | StreamMode::SHARE_DENYALL;
 const StreamMode eStorageReadMode = StreamMode::READ | StreamMode::SHARE_DENYWRITE;
 
-
-// BasicManager impl data
-struct BasicManagerImpl
-{
-    LibraryContainerInfo    maContainerInfo;
-
-    std::vector<std::unique_ptr<BasicLibInfo>> aLibs;
-    OUString         aBasicLibPath;
-
-    BasicManagerImpl()
-    {}
-};
-
 // BasMgrContainerListenerImpl
 
 
@@ -435,11 +422,9 @@ BasicLibInfo* BasicLibInfo::Create( SotStorageStream& rSStream )
 
 BasicManager::BasicManager( SotStorage& rStorage, const OUString& rBaseURL, StarBASIC* pParentFromStdLib, OUString const * pLibPath, bool bDocMgr ) : mbDocMgr( bDocMgr )
 {
-    Init();
-
     if( pLibPath )
     {
-        mpImpl->aBasicLibPath = *pLibPath;
+        aBasicLibPath = *pLibPath;
     }
     OUString aStorName( rStorage.GetName() );
     maStorageName = INetURLObject(aStorName, INetProtocol::File).GetMainURL( INetURLObject::DecodeMechanism::NONE );
@@ -457,10 +442,10 @@ BasicManager::BasicManager( SotStorage& rStorage, const OUString& rBaseURL, Star
             // Should never happen, but if it happens we won't crash...
             pStdLib = new StarBASIC( nullptr, mbDocMgr );
 
-            if (mpImpl->aLibs.empty())
+            if (maLibs.empty())
                 CreateLibInfo();
 
-            BasicLibInfo& rStdLibInfo = *mpImpl->aLibs.front();
+            BasicLibInfo& rStdLibInfo = *maLibs.front();
 
             rStdLibInfo.SetLib( pStdLib );
             StarBASICRef xStdLib = rStdLibInfo.GetLib();
@@ -526,19 +511,19 @@ static void copyToLibraryContainer( StarBASIC* pBasic, const LibraryContainerInf
 
 const uno::Reference< script::XPersistentLibraryContainer >& BasicManager::GetDialogLibraryContainer()  const
 {
-    return mpImpl->maContainerInfo.mxDialogCont;
+    return maContainerInfo.mxDialogCont;
 }
 
 const uno::Reference< script::XPersistentLibraryContainer >& BasicManager::GetScriptLibraryContainer()  const
 {
-    return mpImpl->maContainerInfo.mxScriptCont;
+    return maContainerInfo.mxScriptCont;
 }
 
 void BasicManager::SetLibraryContainerInfo( const LibraryContainerInfo& rInfo )
 {
-    mpImpl->maContainerInfo = rInfo;
+    maContainerInfo = rInfo;
 
-    uno::Reference< script::XLibraryContainer > xScriptCont( mpImpl->maContainerInfo.mxScriptCont );
+    uno::Reference< script::XLibraryContainer > xScriptCont( maContainerInfo.mxScriptCont );
     if( xScriptCont.is() )
     {
         // Register listener for lib container
@@ -566,7 +551,7 @@ void BasicManager::SetLibraryContainerInfo( const LibraryContainerInfo& rInfo )
         else
         {
             // No libs? Maybe an 5.2 document already loaded
-            for (auto const& rpBasLibInfo : mpImpl->aLibs)
+            for (auto const& rpBasLibInfo : maLibs)
             {
                 StarBASIC* pLib = rpBasLibInfo->GetLib().get();
                 if( !pLib )
@@ -577,11 +562,11 @@ void BasicManager::SetLibraryContainerInfo( const LibraryContainerInfo& rInfo )
                 }
                 if( pLib )
                 {
-                    copyToLibraryContainer( pLib, mpImpl->maContainerInfo );
+                    copyToLibraryContainer( pLib, maContainerInfo );
                     if (rpBasLibInfo->HasPassword())
                     {
                         OldBasicPassword* pOldBasicPassword =
-                            mpImpl->maContainerInfo.mpOldBasicPassword;
+                            maContainerInfo.mpOldBasicPassword;
                         if( pOldBasicPassword )
                         {
                             pOldBasicPassword->setLibraryPassword(
@@ -593,18 +578,17 @@ void BasicManager::SetLibraryContainerInfo( const LibraryContainerInfo& rInfo )
         }
     }
 
-    SetGlobalUNOConstant( "BasicLibraries", uno::Any( mpImpl->maContainerInfo.mxScriptCont ) );
-    SetGlobalUNOConstant( "DialogLibraries", uno::Any( mpImpl->maContainerInfo.mxDialogCont ) );
+    SetGlobalUNOConstant( "BasicLibraries", uno::Any( maContainerInfo.mxScriptCont ) );
+    SetGlobalUNOConstant( "DialogLibraries", uno::Any( maContainerInfo.mxDialogCont ) );
 }
 
 BasicManager::BasicManager( StarBASIC* pSLib, OUString const * pLibPath, bool bDocMgr ) : mbDocMgr( bDocMgr )
 {
-    Init();
     DBG_ASSERT( pSLib, "BasicManager cannot be created with a NULL-Pointer!" );
 
     if( pLibPath )
     {
-        mpImpl->aBasicLibPath = *pLibPath;
+        aBasicLibPath = *pLibPath;
     }
     BasicLibInfo* pStdLibInfo = CreateLibInfo();
     pStdLibInfo->SetLib( pSLib );
@@ -709,7 +693,7 @@ void BasicManager::LoadBasicManager( SotStorage& rStorage, const OUString& rBase
 
             //*** TODO: Replace if still necessary
             //*** TODO-End
-            if ( ! mpImpl->aBasicLibPath.isEmpty() )
+            if ( ! aBasicLibPath.isEmpty() )
             {
                 // Search lib in path
                 OUString aSearchFile = pInfo->GetRelStorageName();
@@ -722,7 +706,7 @@ void BasicManager::LoadBasicManager( SotStorage& rStorage, const OUString& rBase
             }
         }
 
-        mpImpl->aLibs.push_back(std::unique_ptr<BasicLibInfo>(pInfo));
+        maLibs.push_back(std::unique_ptr<BasicLibInfo>(pInfo));
         // Libs from external files should be loaded only when necessary.
         // But references are loaded at once, otherwise some big customers get into trouble
         if ( pInfo->DoLoad() &&
@@ -759,7 +743,7 @@ void BasicManager::LoadOldBasicManager( SotStorage& rStorage )
     DBG_ASSERT( !xManagerStream->GetError(), "Invalid Manager-Stream!" );
 
     xManagerStream->Seek( nBasicStartOff );
-    if (!ImplLoadBasic( *xManagerStream, mpImpl->aLibs.front()->GetLibRef() ))
+    if (!ImplLoadBasic( *xManagerStream, maLibs.front()->GetLibRef() ))
     {
         StringErrorInfo* pErrInf = new StringErrorInfo( ERRCODE_BASMGR_MGROPEN, aStorName, DialogMask::ButtonsOk );
         aErrors.emplace_back(*pErrInf, BasicErrorReason::OPENMGRSTREAM);
@@ -837,15 +821,10 @@ bool BasicManager::HasExeCode( std::u16string_view sLib )
     return false;
 }
 
-void BasicManager::Init()
-{
-    mpImpl.reset( new BasicManagerImpl );
-}
-
 BasicLibInfo* BasicManager::CreateLibInfo()
 {
-    mpImpl->aLibs.push_back(std::make_unique<BasicLibInfo>());
-    return mpImpl->aLibs.back().get();
+    maLibs.push_back(std::make_unique<BasicLibInfo>());
+    return maLibs.back().get();
 }
 
 bool BasicManager::ImpLoadLibrary( BasicLibInfo* pLibInfo, SotStorage* pCurStorage )
@@ -987,7 +966,7 @@ bool BasicManager::ImplLoadBasic( SvStream& rStrm, StarBASICRef& rOldBasic ) con
             rOldBasic = pNew;
 
             // Fill new library container (5.2 -> 6.0)
-            copyToLibraryContainer( pNew, mpImpl->maContainerInfo );
+            copyToLibraryContainer( pNew, maContainerInfo );
 
             pNew->SetModified( false );
             bLoaded = true;
@@ -1043,7 +1022,7 @@ StarBASIC* BasicManager::AddLib( SotStorage& rStorage, const OUString& rLibName,
     // Use original name otherwise ImpLoadLibrary fails...
     pLibInfo->SetLibName( rLibName );
     // but doesn't work this way if name exists twice
-    sal_uInt16 nLibId = static_cast<sal_uInt16>(mpImpl->aLibs.size()) - 1;
+    sal_uInt16 nLibId = static_cast<sal_uInt16>(maLibs.size()) - 1;
 
     // Set StorageName before load because it is compared with pCurStorage
     pLibInfo->SetStorageName( aStorageName );
@@ -1079,10 +1058,10 @@ StarBASIC* BasicManager::AddLib( SotStorage& rStorage, const OUString& rLibName,
 
 bool BasicManager::IsReference( sal_uInt16 nLib )
 {
-    DBG_ASSERT( nLib < mpImpl->aLibs.size(), "Lib does not exist!" );
-    if ( nLib < mpImpl->aLibs.size() )
+    DBG_ASSERT( nLib < maLibs.size(), "Lib does not exist!" );
+    if ( nLib < maLibs.size() )
     {
-        return mpImpl->aLibs[nLib]->IsReference();
+        return maLibs[nLib]->IsReference();
     }
     return false;
 }
@@ -1097,16 +1076,16 @@ bool BasicManager::RemoveLib( sal_uInt16 nLib, bool bDelBasicFromStorage )
 {
     DBG_ASSERT( nLib, "Standard-Lib cannot be removed!" );
 
-    DBG_ASSERT( !nLib || nLib  < mpImpl->aLibs.size(), "Lib not found!" );
+    DBG_ASSERT( !nLib || nLib  < maLibs.size(), "Lib not found!" );
 
-    if( !nLib || nLib  < mpImpl->aLibs.size() )
+    if( !nLib || nLib  < maLibs.size() )
     {
         StringErrorInfo* pErrInf = new StringErrorInfo( ERRCODE_BASMGR_REMOVELIB, OUString(), DialogMask::ButtonsOk );
         aErrors.emplace_back(*pErrInf, BasicErrorReason::STDLIB);
         return false;
     }
 
-    auto const itLibInfo = mpImpl->aLibs.begin() + nLib;
+    auto const itLibInfo = maLibs.begin() + nLib;
 
     // If one of the streams cannot be opened, this is not an error,
     // because BASIC was never written before...
@@ -1174,21 +1153,21 @@ bool BasicManager::RemoveLib( sal_uInt16 nLib, bool bDelBasicFromStorage )
     {
         GetStdLib()->Remove( (*itLibInfo)->GetLib().get() );
     }
-    mpImpl->aLibs.erase(itLibInfo);
+    maLibs.erase(itLibInfo);
     return true;    // Remove was successful, del unimportant
 }
 
 sal_uInt16 BasicManager::GetLibCount() const
 {
-    return static_cast<sal_uInt16>(mpImpl->aLibs.size());
+    return static_cast<sal_uInt16>(maLibs.size());
 }
 
 StarBASIC* BasicManager::GetLib( sal_uInt16 nLib ) const
 {
-    DBG_ASSERT( nLib < mpImpl->aLibs.size(), "Lib does not exist!" );
-    if ( nLib < mpImpl->aLibs.size() )
+    DBG_ASSERT( nLib < maLibs.size(), "Lib does not exist!" );
+    if ( nLib < maLibs.size() )
     {
-        return mpImpl->aLibs[nLib]->GetLib().get();
+        return maLibs[nLib]->GetLib().get();
     }
     return nullptr;
 }
@@ -1201,7 +1180,7 @@ StarBASIC* BasicManager::GetStdLib() const
 
 StarBASIC* BasicManager::GetLib( std::u16string_view rName ) const
 {
-    for (auto const& rpLib : mpImpl->aLibs)
+    for (auto const& rpLib : maLibs)
     {
         if (rpLib->GetLibName().equalsIgnoreAsciiCase(rName)) // Check if available...
         {
@@ -1213,9 +1192,9 @@ StarBASIC* BasicManager::GetLib( std::u16string_view rName ) const
 
 sal_uInt16 BasicManager::GetLibId( std::u16string_view rName ) const
 {
-    for (size_t i = 0; i < mpImpl->aLibs.size(); i++)
+    for (size_t i = 0; i < maLibs.size(); i++)
     {
-        if (mpImpl->aLibs[i]->GetLibName().equalsIgnoreAsciiCase( rName ))
+        if (maLibs[i]->GetLibName().equalsIgnoreAsciiCase( rName ))
         {
             return static_cast<sal_uInt16>(i);
         }
@@ -1225,7 +1204,7 @@ sal_uInt16 BasicManager::GetLibId( std::u16string_view rName ) const
 
 bool BasicManager::HasLib( std::u16string_view rName ) const
 {
-    for (const auto& rpLib : mpImpl->aLibs)
+    for (const auto& rpLib : maLibs)
     {
         if (rpLib->GetLibName().equalsIgnoreAsciiCase(rName)) // Check if available...
         {
@@ -1237,10 +1216,10 @@ bool BasicManager::HasLib( std::u16string_view rName ) const
 
 OUString BasicManager::GetLibName( sal_uInt16 nLib )
 {
-    DBG_ASSERT(  nLib < mpImpl->aLibs.size(), "Lib?!" );
-    if ( nLib < mpImpl->aLibs.size() )
+    DBG_ASSERT(  nLib < maLibs.size(), "Lib?!" );
+    if ( nLib < maLibs.size() )
     {
-        return mpImpl->aLibs[nLib]->GetLibName();
+        return maLibs[nLib]->GetLibName();
     }
     return OUString();
 }
@@ -1248,10 +1227,10 @@ OUString BasicManager::GetLibName( sal_uInt16 nLib )
 bool BasicManager::LoadLib( sal_uInt16 nLib )
 {
     bool bDone = false;
-    DBG_ASSERT( nLib < mpImpl->aLibs.size() , "Lib?!" );
-    if ( nLib < mpImpl->aLibs.size() )
+    DBG_ASSERT( nLib < maLibs.size() , "Lib?!" );
+    if ( nLib < maLibs.size() )
     {
-        BasicLibInfo& rLibInfo = *mpImpl->aLibs[nLib];
+        BasicLibInfo& rLibInfo = *maLibs[nLib];
         uno::Reference< script::XLibraryContainer > xLibContainer = rLibInfo.GetLibraryContainer();
         if( xLibContainer.is() )
         {
@@ -1353,7 +1332,7 @@ StarBASIC* BasicManager::CreateLibForLibContainer( const OUString& rLibName,
 
 BasicLibInfo* BasicManager::FindLibInfo( StarBASIC const * pBasic )
 {
-    for (auto const& rpLib : mpImpl->aLibs)
+    for (auto const& rpLib : maLibs)
     {
         if (rpLib->GetLib().get() == pBasic)
         {
@@ -1366,7 +1345,7 @@ BasicLibInfo* BasicManager::FindLibInfo( StarBASIC const * pBasic )
 
 bool BasicManager::IsBasicModified() const
 {
-    for (auto const& rpLib : mpImpl->aLibs)
+    for (auto const& rpLib : maLibs)
     {
         if (rpLib->GetLib().is() && rpLib->GetLib()->IsModified())
         {
diff --git a/include/basic/basmgr.hxx b/include/basic/basmgr.hxx
index 55f582ae6496..32011eb70df6 100644
--- a/include/basic/basmgr.hxx
+++ b/include/basic/basmgr.hxx
@@ -99,9 +99,6 @@ struct LibraryContainerInfo
     {}
 };
 
-struct BasicManagerImpl;
-
-
 #define LIB_NOTFOUND    0xFFFF
 
 class BASIC_DLLPUBLIC BasicManager final : public SfxBroadcaster
@@ -118,9 +115,10 @@ private:
     OUString            maStorageName;
     bool                mbDocMgr;
 
-    std::unique_ptr<BasicManagerImpl>   mpImpl;
+    LibraryContainerInfo    maContainerInfo;
+    std::vector<std::unique_ptr<BasicLibInfo>> maLibs;
+    OUString         aBasicLibPath;
 
-    BASIC_DLLPRIVATE void Init();
     bool            ImpLoadLibrary( BasicLibInfo* pLibInfo, SotStorage* pCurStorage );
     void            ImpCreateStdLib( StarBASIC* pParentFromStdLib );
     void            ImpMgrNotLoaded(  const OUString& rStorageName  );
@@ -135,6 +133,7 @@ private:
 public:
                     BasicManager( SotStorage& rStorage, const OUString& rBaseURL, StarBASIC* pParentFromStdLib = nullptr, OUString const * pLibPath = nullptr, bool bDocMgr = false );
                     BasicManager( StarBASIC* pStdLib, OUString const * pLibPath = nullptr, bool bDocMgr = false );
+
     virtual ~BasicManager() override;
 
     void            SetStorageName( const OUString& rName )   { maStorageName = rName; }
@@ -208,6 +207,8 @@ private:
     BASIC_DLLPRIVATE StarBASIC* CreateLib( const OUString& rLibName );
     BASIC_DLLPRIVATE StarBASIC* CreateLib( const OUString& rLibName, const OUString& Password,
                                            const OUString& LinkTargetURL );
+    BasicManager& operator=(BasicManager const &) = delete; //MSVC2015 workaround
+    BasicManager( BasicManager const&) = delete; //MSVC2015 workaround
 };
 
 #endif // INCLUDED_BASIC_BASMGR_HXX


More information about the Libreoffice-commits mailing list