basic: Simplify SbxArray
Change-Id: Idcc1e35d0a1d80591e2cebdae37a70cf029b022e Reviewed-on: https://gerrit.libreoffice.org/28147 Reviewed-by: Noel Grandin <noelgrandin@gmail.com> Tested-by: Noel Grandin <noelgrandin@gmail.com>
This commit is contained in:
committed by
Noel Grandin
parent
127f70d66a
commit
93de766121
@@ -39,7 +39,6 @@ struct SbxVarEntry
|
|||||||
|
|
||||||
SbxArray::SbxArray( SbxDataType t ) : SbxBase()
|
SbxArray::SbxArray( SbxDataType t ) : SbxBase()
|
||||||
{
|
{
|
||||||
mpVarEntries = new VarEntriesType;
|
|
||||||
eType = t;
|
eType = t;
|
||||||
if( t != SbxVARIANT )
|
if( t != SbxVARIANT )
|
||||||
SetFlag( SbxFlagBits::Fixed );
|
SetFlag( SbxFlagBits::Fixed );
|
||||||
@@ -48,7 +47,6 @@ SbxArray::SbxArray( SbxDataType t ) : SbxBase()
|
|||||||
SbxArray::SbxArray( const SbxArray& rArray ) :
|
SbxArray::SbxArray( const SbxArray& rArray ) :
|
||||||
SvRefBase( rArray ), SbxBase()
|
SvRefBase( rArray ), SbxBase()
|
||||||
{
|
{
|
||||||
mpVarEntries = new VarEntriesType;
|
|
||||||
if( rArray.eType != SbxVARIANT )
|
if( rArray.eType != SbxVARIANT )
|
||||||
SetFlag( SbxFlagBits::Fixed );
|
SetFlag( SbxFlagBits::Fixed );
|
||||||
*this = rArray;
|
*this = rArray;
|
||||||
@@ -60,7 +58,7 @@ SbxArray& SbxArray::operator=( const SbxArray& rArray )
|
|||||||
{
|
{
|
||||||
eType = rArray.eType;
|
eType = rArray.eType;
|
||||||
Clear();
|
Clear();
|
||||||
for( const auto& rpSrcRef : *rArray.mpVarEntries )
|
for( const auto& rpSrcRef : rArray.mVarEntries )
|
||||||
{
|
{
|
||||||
SbxVariableRef pSrc_ = rpSrcRef.mpVar;
|
SbxVariableRef pSrc_ = rpSrcRef.mpVar;
|
||||||
if( !pSrc_ )
|
if( !pSrc_ )
|
||||||
@@ -74,7 +72,7 @@ SbxArray& SbxArray::operator=( const SbxArray& rArray )
|
|||||||
pSrc_->Convert(eType);
|
pSrc_->Convert(eType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mpVarEntries->push_back( rpSrcRef );
|
mVarEntries.push_back( rpSrcRef );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
@@ -82,7 +80,6 @@ SbxArray& SbxArray::operator=( const SbxArray& rArray )
|
|||||||
|
|
||||||
SbxArray::~SbxArray()
|
SbxArray::~SbxArray()
|
||||||
{
|
{
|
||||||
delete mpVarEntries;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SbxDataType SbxArray::GetType() const
|
SbxDataType SbxArray::GetType() const
|
||||||
@@ -97,17 +94,17 @@ SbxClassType SbxArray::GetClass() const
|
|||||||
|
|
||||||
void SbxArray::Clear()
|
void SbxArray::Clear()
|
||||||
{
|
{
|
||||||
mpVarEntries->clear();
|
mVarEntries.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
sal_uInt32 SbxArray::Count32() const
|
sal_uInt32 SbxArray::Count32() const
|
||||||
{
|
{
|
||||||
return mpVarEntries->size();
|
return mVarEntries.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
sal_uInt16 SbxArray::Count() const
|
sal_uInt16 SbxArray::Count() const
|
||||||
{
|
{
|
||||||
sal_uInt32 nCount = mpVarEntries->size();
|
sal_uInt32 nCount = mVarEntries.size();
|
||||||
DBG_ASSERT( nCount <= SBX_MAXINDEX, "SBX: Array-Index > SBX_MAXINDEX" );
|
DBG_ASSERT( nCount <= SBX_MAXINDEX, "SBX: Array-Index > SBX_MAXINDEX" );
|
||||||
return (sal_uInt16)nCount;
|
return (sal_uInt16)nCount;
|
||||||
}
|
}
|
||||||
@@ -122,11 +119,10 @@ SbxVariableRef& SbxArray::GetRef32( sal_uInt32 nIdx )
|
|||||||
SetError( ERRCODE_SBX_BOUNDS );
|
SetError( ERRCODE_SBX_BOUNDS );
|
||||||
nIdx = 0;
|
nIdx = 0;
|
||||||
}
|
}
|
||||||
while( mpVarEntries->size() <= nIdx )
|
if ( mVarEntries.size() <= nIdx )
|
||||||
{
|
mVarEntries.resize(nIdx+1);
|
||||||
mpVarEntries->emplace_back();
|
|
||||||
}
|
return mVarEntries[nIdx].mpVar;
|
||||||
return (*mpVarEntries)[nIdx].mpVar;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SbxVariableRef& SbxArray::GetRef( sal_uInt16 nIdx )
|
SbxVariableRef& SbxArray::GetRef( sal_uInt16 nIdx )
|
||||||
@@ -139,11 +135,10 @@ SbxVariableRef& SbxArray::GetRef( sal_uInt16 nIdx )
|
|||||||
SetError( ERRCODE_SBX_BOUNDS );
|
SetError( ERRCODE_SBX_BOUNDS );
|
||||||
nIdx = 0;
|
nIdx = 0;
|
||||||
}
|
}
|
||||||
while( mpVarEntries->size() <= nIdx )
|
if ( mVarEntries.size() <= nIdx )
|
||||||
{
|
mVarEntries.resize(nIdx+1);
|
||||||
mpVarEntries->emplace_back();
|
|
||||||
}
|
return mVarEntries[nIdx].mpVar;
|
||||||
return (*mpVarEntries)[nIdx].mpVar;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SbxVariable* SbxArray::Get32( sal_uInt32 nIdx )
|
SbxVariable* SbxArray::Get32( sal_uInt32 nIdx )
|
||||||
@@ -208,7 +203,7 @@ void SbxArray::Put( SbxVariable* pVar, sal_uInt16 nIdx )
|
|||||||
if( eType != SbxOBJECT || pVar->GetClass() != SbxClassType::Object )
|
if( eType != SbxOBJECT || pVar->GetClass() != SbxClassType::Object )
|
||||||
pVar->Convert( eType );
|
pVar->Convert( eType );
|
||||||
SbxVariableRef& rRef = GetRef( nIdx );
|
SbxVariableRef& rRef = GetRef( nIdx );
|
||||||
if( static_cast<SbxVariable*>(rRef) != pVar )
|
if(rRef.get() != pVar )
|
||||||
{
|
{
|
||||||
rRef = pVar;
|
rRef = pVar;
|
||||||
SetFlag( SbxFlagBits::Modified );
|
SetFlag( SbxFlagBits::Modified );
|
||||||
@@ -246,14 +241,14 @@ void SbxArray::PutAlias( const OUString& rAlias, sal_uInt16 nIdx )
|
|||||||
|
|
||||||
void SbxArray::Insert32( SbxVariable* pVar, sal_uInt32 nIdx )
|
void SbxArray::Insert32( SbxVariable* pVar, sal_uInt32 nIdx )
|
||||||
{
|
{
|
||||||
DBG_ASSERT( mpVarEntries->size() <= SBX_MAXINDEX32, "SBX: Array gets too big" );
|
DBG_ASSERT( mVarEntries.size() <= SBX_MAXINDEX32, "SBX: Array gets too big" );
|
||||||
if( mpVarEntries->size() > SBX_MAXINDEX32 )
|
if( mVarEntries.size() > SBX_MAXINDEX32 )
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
SbxVarEntry p;
|
SbxVarEntry p;
|
||||||
p.mpVar = pVar;
|
p.mpVar = pVar;
|
||||||
size_t nSize = mpVarEntries->size();
|
size_t nSize = mVarEntries.size();
|
||||||
if( nIdx > nSize )
|
if( nIdx > nSize )
|
||||||
{
|
{
|
||||||
nIdx = nSize;
|
nIdx = nSize;
|
||||||
@@ -264,19 +259,19 @@ void SbxArray::Insert32( SbxVariable* pVar, sal_uInt32 nIdx )
|
|||||||
}
|
}
|
||||||
if( nIdx == nSize )
|
if( nIdx == nSize )
|
||||||
{
|
{
|
||||||
mpVarEntries->push_back( p );
|
mVarEntries.push_back( p );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mpVarEntries->insert( mpVarEntries->begin() + nIdx, p );
|
mVarEntries.insert( mVarEntries.begin() + nIdx, p );
|
||||||
}
|
}
|
||||||
SetFlag( SbxFlagBits::Modified );
|
SetFlag( SbxFlagBits::Modified );
|
||||||
}
|
}
|
||||||
|
|
||||||
void SbxArray::Insert( SbxVariable* pVar, sal_uInt16 nIdx )
|
void SbxArray::Insert( SbxVariable* pVar, sal_uInt16 nIdx )
|
||||||
{
|
{
|
||||||
DBG_ASSERT( mpVarEntries->size() <= 0x3FF0, "SBX: Array gets too big" );
|
DBG_ASSERT( mVarEntries.size() <= 0x3FF0, "SBX: Array gets too big" );
|
||||||
if( mpVarEntries->size() > 0x3FF0 )
|
if( mVarEntries.size() > 0x3FF0 )
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -285,9 +280,9 @@ void SbxArray::Insert( SbxVariable* pVar, sal_uInt16 nIdx )
|
|||||||
|
|
||||||
void SbxArray::Remove( sal_uInt32 nIdx )
|
void SbxArray::Remove( sal_uInt32 nIdx )
|
||||||
{
|
{
|
||||||
if( nIdx < mpVarEntries->size() )
|
if( nIdx < mVarEntries.size() )
|
||||||
{
|
{
|
||||||
mpVarEntries->erase( mpVarEntries->begin() + nIdx );
|
mVarEntries.erase( mVarEntries.begin() + nIdx );
|
||||||
SetFlag( SbxFlagBits::Modified );
|
SetFlag( SbxFlagBits::Modified );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -296,9 +291,9 @@ void SbxArray::Remove( SbxVariable* pVar )
|
|||||||
{
|
{
|
||||||
if( pVar )
|
if( pVar )
|
||||||
{
|
{
|
||||||
for( size_t i = 0; i < mpVarEntries->size(); i++ )
|
for( size_t i = 0; i < mVarEntries.size(); i++ )
|
||||||
{
|
{
|
||||||
if (&(*mpVarEntries)[i].mpVar == pVar)
|
if (&mVarEntries[i].mpVar == pVar)
|
||||||
{
|
{
|
||||||
Remove( i ); break;
|
Remove( i ); break;
|
||||||
}
|
}
|
||||||
@@ -314,7 +309,7 @@ void SbxArray::Merge( SbxArray* p )
|
|||||||
if (!p)
|
if (!p)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (auto& rEntry1: *p->mpVarEntries)
|
for (auto& rEntry1: p->mVarEntries)
|
||||||
{
|
{
|
||||||
if (!rEntry1.mpVar)
|
if (!rEntry1.mpVar)
|
||||||
continue;
|
continue;
|
||||||
@@ -324,7 +319,7 @@ void SbxArray::Merge( SbxArray* p )
|
|||||||
|
|
||||||
// Is the element by the same name already inside?
|
// Is the element by the same name already inside?
|
||||||
// Then overwrite!
|
// Then overwrite!
|
||||||
for (auto& rEntry2: *mpVarEntries)
|
for (auto& rEntry2: mVarEntries)
|
||||||
{
|
{
|
||||||
if (!rEntry2.mpVar)
|
if (!rEntry2.mpVar)
|
||||||
continue;
|
continue;
|
||||||
@@ -346,7 +341,7 @@ void SbxArray::Merge( SbxArray* p )
|
|||||||
aNewEntry.mpVar = rEntry1.mpVar;
|
aNewEntry.mpVar = rEntry1.mpVar;
|
||||||
if (rEntry1.maAlias)
|
if (rEntry1.maAlias)
|
||||||
aNewEntry.maAlias.reset(*rEntry1.maAlias);
|
aNewEntry.maAlias.reset(*rEntry1.maAlias);
|
||||||
mpVarEntries->push_back(aNewEntry);
|
mVarEntries.push_back(aNewEntry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -357,7 +352,7 @@ void SbxArray::Merge( SbxArray* p )
|
|||||||
SbxVariable* SbxArray::FindUserData( sal_uInt32 nData )
|
SbxVariable* SbxArray::FindUserData( sal_uInt32 nData )
|
||||||
{
|
{
|
||||||
SbxVariable* p = nullptr;
|
SbxVariable* p = nullptr;
|
||||||
for (auto& rEntry : *mpVarEntries)
|
for (auto& rEntry : mVarEntries)
|
||||||
{
|
{
|
||||||
if (!rEntry.mpVar)
|
if (!rEntry.mpVar)
|
||||||
continue;
|
continue;
|
||||||
@@ -407,11 +402,11 @@ SbxVariable* SbxArray::FindUserData( sal_uInt32 nData )
|
|||||||
SbxVariable* SbxArray::Find( const OUString& rName, SbxClassType t )
|
SbxVariable* SbxArray::Find( const OUString& rName, SbxClassType t )
|
||||||
{
|
{
|
||||||
SbxVariable* p = nullptr;
|
SbxVariable* p = nullptr;
|
||||||
if( mpVarEntries->empty() )
|
if( mVarEntries.empty() )
|
||||||
return nullptr;
|
return nullptr;
|
||||||
bool bExtSearch = IsSet( SbxFlagBits::ExtSearch );
|
bool bExtSearch = IsSet( SbxFlagBits::ExtSearch );
|
||||||
sal_uInt16 nHash = SbxVariable::MakeHashCode( rName );
|
sal_uInt16 nHash = SbxVariable::MakeHashCode( rName );
|
||||||
for (auto& rEntry : *mpVarEntries)
|
for (auto& rEntry : mVarEntries)
|
||||||
{
|
{
|
||||||
if (!rEntry.mpVar || !rEntry.mpVar->IsVisible())
|
if (!rEntry.mpVar || !rEntry.mpVar->IsVisible())
|
||||||
continue;
|
continue;
|
||||||
@@ -492,15 +487,15 @@ bool SbxArray::StoreData( SvStream& rStrm ) const
|
|||||||
{
|
{
|
||||||
sal_uInt32 nElem = 0;
|
sal_uInt32 nElem = 0;
|
||||||
// Which elements are even defined?
|
// Which elements are even defined?
|
||||||
for( auto& rEntry: *mpVarEntries )
|
for( auto& rEntry: mVarEntries )
|
||||||
{
|
{
|
||||||
if (rEntry.mpVar && !(rEntry.mpVar->GetFlags() & SbxFlagBits::DontStore))
|
if (rEntry.mpVar && !(rEntry.mpVar->GetFlags() & SbxFlagBits::DontStore))
|
||||||
nElem++;
|
nElem++;
|
||||||
}
|
}
|
||||||
rStrm.WriteUInt16( nElem );
|
rStrm.WriteUInt16( nElem );
|
||||||
for( size_t n = 0; n < mpVarEntries->size(); n++ )
|
for( size_t n = 0; n < mVarEntries.size(); n++ )
|
||||||
{
|
{
|
||||||
SbxVarEntry& rEntry = (*mpVarEntries)[n];
|
const SbxVarEntry& rEntry = mVarEntries[n];
|
||||||
if (rEntry.mpVar && !(rEntry.mpVar->GetFlags() & SbxFlagBits::DontStore))
|
if (rEntry.mpVar && !(rEntry.mpVar->GetFlags() & SbxFlagBits::DontStore))
|
||||||
{
|
{
|
||||||
rStrm.WriteUInt16( n );
|
rStrm.WriteUInt16( n );
|
||||||
|
@@ -118,15 +118,13 @@ struct SbxVarEntry;
|
|||||||
|
|
||||||
class BASIC_DLLPUBLIC SbxArray : public SbxBase
|
class BASIC_DLLPUBLIC SbxArray : public SbxBase
|
||||||
{
|
{
|
||||||
typedef std::vector<SbxVarEntry> VarEntriesType;
|
|
||||||
|
|
||||||
// #100883 Method to set method directly to parameter array
|
// #100883 Method to set method directly to parameter array
|
||||||
friend class SbMethod;
|
friend class SbMethod;
|
||||||
friend class SbClassModuleObject;
|
friend class SbClassModuleObject;
|
||||||
friend SbxObject* cloneTypeObjectImpl( const SbxObject& rTypeObj );
|
friend SbxObject* cloneTypeObjectImpl( const SbxObject& rTypeObj );
|
||||||
BASIC_DLLPRIVATE void PutDirect( SbxVariable* pVar, sal_uInt32 nIdx );
|
BASIC_DLLPRIVATE void PutDirect( SbxVariable* pVar, sal_uInt32 nIdx );
|
||||||
|
|
||||||
VarEntriesType* mpVarEntries; // The variables
|
std::vector<SbxVarEntry> mVarEntries; // The variables
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
SbxDataType eType; // Data type of the array
|
SbxDataType eType; // Data type of the array
|
||||||
|
Reference in New Issue
Block a user