[Libreoffice-commits] .: basic/source
Joseph Powers
jpowers at kemper.freedesktop.org
Thu Dec 16 20:38:33 PST 2010
basic/source/basmgr/basmgr.cxx | 199 +++++++++++++++++++++++++++++------------
1 file changed, 144 insertions(+), 55 deletions(-)
New commits:
commit b3d1a95152736c8b41c8fb422ca6f9935c465e9b
Author: Joseph Powers <jpowers27 at cox.net>
Date: Thu Dec 16 20:16:27 2010 -0800
remove DECLARE_LIST(BasErrorLst,BasicError*) and (BasicLibsBase,BasicLibInfo*)
diff --git a/basic/source/basmgr/basmgr.cxx b/basic/source/basmgr/basmgr.cxx
index 882fa8b..14fa693 100644
--- a/basic/source/basmgr/basmgr.cxx
+++ b/basic/source/basmgr/basmgr.cxx
@@ -51,6 +51,7 @@
#include "sbintern.hxx"
#include <sb.hrc>
+#include <vector>
#define LIB_SEP 0x01
#define LIBINFO_SEP 0x02
@@ -74,6 +75,8 @@
#include <cppuhelper/implbase1.hxx>
using com::sun::star::uno::Reference;
+using ::std::vector;
+using ::std::advance;
using namespace com::sun::star::container;
using namespace com::sun::star::uno;
using namespace com::sun::star::lang;
@@ -85,7 +88,7 @@ typedef WeakImplHelper1< XStarBasicModuleInfo > ModuleInfoHelper;
typedef WeakImplHelper1< XStarBasicDialogInfo > DialogInfoHelper;
typedef WeakImplHelper1< XStarBasicLibraryInfo > LibraryInfoHelper;
typedef WeakImplHelper1< XStarBasicAccess > StarBasicAccessHelper;
-
+typedef vector< BasicError* > BasErrorLst;
#define CURR_VER 2
@@ -115,8 +118,6 @@ DBG_NAME( BasicManager );
StreamMode eStreamReadMode = STREAM_READ | STREAM_NOCREATE | STREAM_SHARE_DENYALL;
StreamMode eStorageReadMode = STREAM_READ | STREAM_SHARE_DENYWRITE;
-DECLARE_LIST( BasErrorLst, BasicError* )
-
//----------------------------------------------------------------------------
// BasicManager impl data
struct BasicManagerImpl
@@ -388,18 +389,24 @@ class BasicErrorManager
{
private:
BasErrorLst aErrorList;
+ size_t CurrentError;
public:
+ BasicErrorManager();
~BasicErrorManager();
- void Reset();
- void InsertError( const BasicError& rError );
+ void Reset();
+ void InsertError( const BasicError& rError );
- BOOL HasErrors() { return (BOOL)aErrorList.Count(); }
- BasicError* GetFirstError() { return aErrorList.First(); }
- BasicError* GetNextError() { return aErrorList.Next(); }
+ bool HasErrors() { return !aErrorList.empty(); }
+ BasicError* GetFirstError();
+ BasicError* GetNextError();
};
+BasicErrorManager::BasicErrorManager()
+ : CurrentError( 0 )
+{
+}
BasicErrorManager::~BasicErrorManager()
{
@@ -408,20 +415,36 @@ BasicErrorManager::~BasicErrorManager()
void BasicErrorManager::Reset()
{
- BasicError* pError = (BasicError*)aErrorList.First();
- while ( pError )
- {
- delete pError;
- pError = (BasicError*)aErrorList.Next();
- }
- aErrorList.Clear();
+ for ( size_t i = 0, n = aErrorList.size(); i < n; ++i )
+ delete aErrorList[ i ];
+ aErrorList.clear();
}
void BasicErrorManager::InsertError( const BasicError& rError )
{
- aErrorList.Insert( new BasicError( rError ), LIST_APPEND );
+ aErrorList.push_back( new BasicError( rError ) );
}
+BasicError* BasicErrorManager::GetFirstError()
+{
+ CurrentError = 0;
+ return aErrorList.empty() ? NULL : aErrorList[ CurrentError ];
+}
+
+BasicError* BasicErrorManager::GetNextError()
+{
+ if ( !aErrorList.empty()
+ && CurrentError < ( aErrorList.size() - 1)
+ )
+ {
+ ++CurrentError;
+ return aErrorList[ CurrentError ];
+ }
+ return NULL;
+}
+
+
+//=====================================================================
BasicError::BasicError()
{
@@ -444,6 +467,8 @@ BasicError::BasicError( const BasicError& rErr ) :
}
+//=====================================================================
+
class BasicLibInfo
{
private:
@@ -512,14 +537,111 @@ public:
{ mxScriptCont = xScriptCont; }
};
-DECLARE_LIST( BasicLibsBase, BasicLibInfo* )
-class BasicLibs : public BasicLibsBase
+//=====================================================================
+
+class BasicLibs
{
+private:
+ vector< BasicLibInfo* > aList;
+ size_t CurrentLib;
+
public:
- String aBasicLibPath; // TODO: Should be member of manager, but currently not incompatible
+ ~BasicLibs();
+ String aBasicLibPath; // TODO: Should be member of manager, but currently not incompatible
+ BasicLibInfo* GetObject( size_t i );
+ BasicLibInfo* First();
+ BasicLibInfo* Last();
+ BasicLibInfo* Prev();
+ BasicLibInfo* Next();
+ size_t GetPos( BasicLibInfo* LibInfo );
+ size_t Count() const { return aList.size(); };
+ size_t GetCurPos() const { return CurrentLib; };
+ void Insert( BasicLibInfo* LibInfo );
+ BasicLibInfo* Remove( BasicLibInfo* LibInfo );
};
+BasicLibs::~BasicLibs() {
+ for ( size_t i = 0, n = aList.size(); i < n; ++i )
+ delete aList[ i ];
+ aList.clear();
+}
+
+BasicLibInfo* BasicLibs::GetObject( size_t i )
+{
+ if ( aList.empty()
+ || aList.size() <= i
+ )
+ return NULL;
+ CurrentLib = i;
+ return aList[ CurrentLib ];
+}
+
+BasicLibInfo* BasicLibs::First()
+{
+ if ( aList.empty() )
+ return NULL;
+ CurrentLib = 0;
+ return aList[ CurrentLib ];
+}
+
+BasicLibInfo* BasicLibs::Last()
+{
+ if ( aList.empty() )
+ return NULL;
+ CurrentLib = aList.size() - 1;
+ return aList[ CurrentLib ];
+}
+
+BasicLibInfo* BasicLibs::Prev()
+{
+ if ( aList.empty()
+ || CurrentLib == 0
+ )
+ return NULL;
+ --CurrentLib;
+ return aList[ CurrentLib ];
+}
+
+BasicLibInfo* BasicLibs::Next()
+{
+ if ( aList.empty()
+ || CurrentLib < ( aList.size() - 1 )
+ )
+ return NULL;
+ ++CurrentLib;
+ return aList[ CurrentLib ];
+}
+
+size_t BasicLibs::GetPos( BasicLibInfo* LibInfo )
+{
+ for ( size_t i = 0, n = aList.size(); i < n; ++i )
+ if ( aList[ i ] == LibInfo )
+ return i;
+ return size_t( -1 );
+}
+
+void BasicLibs::Insert( BasicLibInfo* LibInfo )
+{
+ aList.push_back( LibInfo );
+ CurrentLib = aList.size() - 1;
+}
+
+BasicLibInfo* BasicLibs::Remove( BasicLibInfo* LibInfo )
+{
+ size_t i = GetPos( LibInfo );
+ if ( i < aList.size() )
+ {
+ vector< BasicLibInfo* >::iterator it = aList.begin();
+ advance( it , i );
+ it = aList.erase( it );
+ }
+ return LibInfo;
+}
+
+
+//=====================================================================
+
BasicLibInfo::BasicLibInfo()
{
bReference = FALSE;
@@ -1012,7 +1134,7 @@ void BasicManager::LoadBasicManager( SotStorage& rStorage, const String& rBaseUR
}
}
- pLibs->Insert( pInfo, LIST_APPEND );
+ pLibs->Insert( 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 ( bLoadLibs && pInfo->DoLoad() &&
@@ -1056,8 +1178,6 @@ void BasicManager::LoadOldBasicManager( SotStorage& rStorage )
xManagerStream->Seek( nBasicStartOff );
if( !ImplLoadBasic( *xManagerStream, pLibs->GetObject(0)->GetLibRef() ) )
{
-// String aErrorText( BasicResId( IDS_SBERR_MGROPEN ) );
-// aErrorText.SearchAndReplace( "XX", aStorName );
StringErrorInfo* pErrInf = new StringErrorInfo( ERRCODE_BASMGR_MGROPEN, aStorName, ERRCODE_BUTTON_OK );
pErrorMgr->InsertError( BasicError( *pErrInf, BASERR_REASON_OPENMGRSTREAM, aStorName ) );
// and it proceeds ...
@@ -1104,8 +1224,6 @@ void BasicManager::LoadOldBasicManager( SotStorage& rStorage )
AddLib( *xStorageRef, aLibName, FALSE );
else
{
-// String aErrorText( BasicResId( IDS_SBERR_LIBLOAD ) );
-// aErrorText.SearchAndReplace( "XX", aLibName );
StringErrorInfo* pErrInf = new StringErrorInfo( ERRCODE_BASMGR_LIBLOAD, aStorName, ERRCODE_BUTTON_OK );
pErrorMgr->InsertError( BasicError( *pErrInf, BASERR_REASON_STORAGENOTFOUND, aStorName ) );
}
@@ -1122,13 +1240,6 @@ BasicManager::~BasicManager()
// Destroy Basic-Infos...
// In reverse order
- BasicLibInfo* pInf = pLibs->Last();
- while ( pInf )
- {
- delete pInf;
- pInf = pLibs->Prev();
- }
- pLibs->Clear();
delete pLibs;
delete pErrorMgr;
delete mpImpl;
@@ -1174,7 +1285,7 @@ BasicLibInfo* BasicManager::CreateLibInfo()
DBG_CHKTHIS( BasicManager, 0 );
BasicLibInfo* pInf = new BasicLibInfo;
- pLibs->Insert( pInf, LIST_APPEND );
+ pLibs->Insert( pInf );
return pInf;
}
@@ -1321,13 +1432,6 @@ BOOL BasicManager::ImplLoadBasic( SvStream& rStrm, StarBASICRef& rOldBasic ) con
// Fill new libray container (5.2 -> 6.0)
copyToLibraryContainer( pNew, mpImpl->maContainerInfo );
-/*
- if( rOldBasic->GetParent() )
- {
- rOldBasic->GetParent()->Insert( rOldBasic );
- rOldBasic->SetFlag( SBX_EXTSEARCH );
- }
-*/
pNew->SetModified( FALSE );
bLoaded = TRUE;
}
@@ -1379,7 +1483,6 @@ StarBASIC* BasicManager::AddLib( SotStorage& rStorage, const String& rLibName, B
// Use original name otherwise ImpLoadLibary failes...
pLibInfo->SetLibName( rLibName );
// Funktioniert so aber nicht, wenn Name doppelt
-// USHORT nLibId = GetLibId( rLibName );
USHORT nLibId = (USHORT) pLibs->GetPos( pLibInfo );
// Set StorageName before load because it is compared with pCurStorage
@@ -1395,7 +1498,6 @@ StarBASIC* BasicManager::AddLib( SotStorage& rStorage, const String& rLibName, B
{
pLibInfo->GetLib()->SetModified( FALSE ); // Don't save in this case
pLibInfo->SetRelStorageName( String() );
-// pLibInfo->CalcRelStorageName( GetStorageName() );
pLibInfo->IsReference() = TRUE;
}
else
@@ -1469,7 +1571,6 @@ BOOL BasicManager::RemoveLib( USHORT nLib, BOOL bDelBasicFromStorage )
if ( !xBasicStorage.Is() || xBasicStorage->GetError() )
{
-// String aErrorText( BasicResId( IDS_SBERR_REMOVELIB ) );
StringErrorInfo* pErrInf = new StringErrorInfo( ERRCODE_BASMGR_REMOVELIB, String(), ERRCODE_BUTTON_OK );
pErrorMgr->InsertError( BasicError( *pErrInf, BASERR_REASON_OPENLIBSTORAGE, pLibInfo->GetLibName() ) );
}
@@ -1632,7 +1733,6 @@ BOOL BasicManager::LoadLib( USHORT nLib )
StarBASIC* pLib = GetLib( nLib );
if ( pLib )
{
- // pLib->SetParent( GetStdLib() );
GetStdLib()->Insert( pLib );
pLib->SetFlag( SBX_EXTSEARCH );
}
@@ -1640,8 +1740,6 @@ BOOL BasicManager::LoadLib( USHORT nLib )
}
else
{
-// String aErrorText( BasicResId( IDS_SBERR_LIBLOAD ) );
-// aErrorText.SearchAndReplace( "XX", "" );
StringErrorInfo* pErrInf = new StringErrorInfo( ERRCODE_BASMGR_LIBLOAD, String(), ERRCODE_BUTTON_OK );
pErrorMgr->InsertError( BasicError( *pErrInf, BASERR_REASON_LIBNOTFOUND, String::CreateFromInt32(nLib) ) );
}
@@ -1678,16 +1776,7 @@ StarBASIC* BasicManager::CreateLib
if( !xStorage->GetError() )
{
pLib = AddLib( *xStorage, rLibName, TRUE );
-
- //if( !pLibInfo )
- //pLibInfo = FindLibInfo( pLib );
- //pLibInfo->SetStorageName( LinkTargetURL );
- //pLibInfo->GetLib()->SetModified( FALSE ); // Then don't save
- //pLibInfo->SetRelStorageName( String() );
- //pLibInfo->IsReference() = TRUE;
}
- //else
- //Message?
DBG_ASSERT( pLib, "XML Import: Linked basic library could not be loaded");
}
@@ -1850,7 +1939,7 @@ bool BasicManager::LegacyPsswdBinaryLimitExceeded( ::com::sun::star::uno::Sequen
const ::rtl::OUString* pNamesEnd = aNames.getConstArray() + aNames.getLength();
for ( ; pNames != pNamesEnd; ++pNames )
{
- if( /*pLib->mbSharedIndexFile ||*/ !xPassword->isLibraryPasswordProtected( *pNames ) )
+ if( !xPassword->isLibraryPasswordProtected( *pNames ) )
continue;
StarBASIC* pBasicLib = GetLib( *pNames );
More information about the Libreoffice-commits
mailing list