Kaydet (Commit) ec1636fa authored tarafından Kohei Yoshida's avatar Kohei Yoshida

Remove this weird inheritance from smart-pointer-wrapped class.

SbxVarEntry is now its own class.

Change-Id: I5c5ce1990fa83930acced1d507f5b0de60bf221e
üst e14abb13
...@@ -32,10 +32,10 @@ struct SbxDim { // an array-dimension: ...@@ -32,10 +32,10 @@ struct SbxDim { // an array-dimension:
sal_Int32 nSize; // Number of elements sal_Int32 nSize; // Number of elements
}; };
class SbxVarEntry : public SbxVariableRef { struct SbxVarEntry
public: {
SbxVariableRef mpVar;
boost::optional<OUString> maAlias; boost::optional<OUString> maAlias;
SbxVarEntry() : SbxVariableRef() {}
}; };
TYPEINIT1(SbxArray,SbxBase) TYPEINIT1(SbxArray,SbxBase)
...@@ -70,11 +70,11 @@ SbxArray& SbxArray::operator=( const SbxArray& rArray ) ...@@ -70,11 +70,11 @@ SbxArray& SbxArray::operator=( const SbxArray& rArray )
for( sal_uInt32 i = 0; i < pSrc->size(); i++ ) for( sal_uInt32 i = 0; i < pSrc->size(); i++ )
{ {
SbxVarEntry* pSrcRef = (*pSrc)[i]; SbxVarEntry* pSrcRef = (*pSrc)[i];
const SbxVariable* pSrc_ = *pSrcRef; SbxVariableRef pSrc_ = pSrcRef->mpVar;
if( !pSrc_ ) if( !pSrc_ )
continue; continue;
SbxVarEntry* pDstRef = new SbxVarEntry; SbxVarEntry* pDstRef = new SbxVarEntry;
*((SbxVariableRef*) pDstRef) = *((SbxVariableRef*) pSrcRef); pDstRef->mpVar = pSrcRef->mpVar;
if (pSrcRef->maAlias) if (pSrcRef->maAlias)
pDstRef->maAlias.reset(*pSrcRef->maAlias); pDstRef->maAlias.reset(*pSrcRef->maAlias);
...@@ -84,7 +84,7 @@ SbxArray& SbxArray::operator=( const SbxArray& rArray ) ...@@ -84,7 +84,7 @@ SbxArray& SbxArray::operator=( const SbxArray& rArray )
// Convert no objects // Convert no objects
if( eType != SbxOBJECT || pSrc_->GetClass() != SbxCLASS_OBJECT ) if( eType != SbxOBJECT || pSrc_->GetClass() != SbxCLASS_OBJECT )
{ {
((SbxVariable*) pSrc_)->Convert( eType ); pSrc_->Convert(eType);
} }
} }
mpVarEntries->push_back( pDstRef ); mpVarEntries->push_back( pDstRef );
...@@ -146,7 +146,7 @@ SbxVariableRef& SbxArray::GetRef32( sal_uInt32 nIdx ) ...@@ -146,7 +146,7 @@ SbxVariableRef& SbxArray::GetRef32( sal_uInt32 nIdx )
{ {
mpVarEntries->push_back(new SbxVarEntry); mpVarEntries->push_back(new SbxVarEntry);
} }
return *((*mpVarEntries)[nIdx]); return (*mpVarEntries)[nIdx]->mpVar;
} }
SbxVariableRef& SbxArray::GetRef( sal_uInt16 nIdx ) SbxVariableRef& SbxArray::GetRef( sal_uInt16 nIdx )
...@@ -163,7 +163,7 @@ SbxVariableRef& SbxArray::GetRef( sal_uInt16 nIdx ) ...@@ -163,7 +163,7 @@ SbxVariableRef& SbxArray::GetRef( sal_uInt16 nIdx )
{ {
mpVarEntries->push_back(new SbxVarEntry); mpVarEntries->push_back(new SbxVarEntry);
} }
return *((*mpVarEntries)[nIdx]); return (*mpVarEntries)[nIdx]->mpVar;
} }
SbxVariable* SbxArray::Get32( sal_uInt32 nIdx ) SbxVariable* SbxArray::Get32( sal_uInt32 nIdx )
...@@ -280,7 +280,7 @@ void SbxArray::Insert32( SbxVariable* pVar, sal_uInt32 nIdx ) ...@@ -280,7 +280,7 @@ void SbxArray::Insert32( SbxVariable* pVar, sal_uInt32 nIdx )
} }
if( eType != SbxVARIANT && pVar ) if( eType != SbxVARIANT && pVar )
{ {
(*p)->Convert( eType ); p->mpVar->Convert(eType);
} }
if( nIdx == nSize ) if( nIdx == nSize )
{ {
...@@ -307,7 +307,7 @@ void SbxArray::Remove32( sal_uInt32 nIdx ) ...@@ -307,7 +307,7 @@ void SbxArray::Remove32( sal_uInt32 nIdx )
{ {
if( nIdx < mpVarEntries->size() ) if( nIdx < mpVarEntries->size() )
{ {
SbxVariableRef* pRef = (*mpVarEntries)[nIdx]; SbxVarEntry* pRef = (*mpVarEntries)[nIdx];
mpVarEntries->erase( mpVarEntries->begin() + nIdx ); mpVarEntries->erase( mpVarEntries->begin() + nIdx );
delete pRef; delete pRef;
SetFlag( SBX_MODIFIED ); SetFlag( SBX_MODIFIED );
...@@ -318,7 +318,7 @@ void SbxArray::Remove( sal_uInt16 nIdx ) ...@@ -318,7 +318,7 @@ void SbxArray::Remove( sal_uInt16 nIdx )
{ {
if( nIdx < mpVarEntries->size() ) if( nIdx < mpVarEntries->size() )
{ {
SbxVariableRef* pRef = (*mpVarEntries)[nIdx]; SbxVarEntry* pRef = (*mpVarEntries)[nIdx];
mpVarEntries->erase( mpVarEntries->begin() + nIdx ); mpVarEntries->erase( mpVarEntries->begin() + nIdx );
delete pRef; delete pRef;
SetFlag( SBX_MODIFIED ); SetFlag( SBX_MODIFIED );
...@@ -331,8 +331,8 @@ void SbxArray::Remove( SbxVariable* pVar ) ...@@ -331,8 +331,8 @@ void SbxArray::Remove( SbxVariable* pVar )
{ {
for( sal_uInt32 i = 0; i < mpVarEntries->size(); i++ ) for( sal_uInt32 i = 0; i < mpVarEntries->size(); i++ )
{ {
SbxVariableRef* pRef = (*mpVarEntries)[i]; SbxVarEntry* pRef = (*mpVarEntries)[i];
if( *pRef == pVar ) if (&pRef->mpVar == pVar)
{ {
Remove32( i ); break; Remove32( i ); break;
} }
...@@ -345,40 +345,44 @@ void SbxArray::Remove( SbxVariable* pVar ) ...@@ -345,40 +345,44 @@ void SbxArray::Remove( SbxVariable* pVar )
void SbxArray::Merge( SbxArray* p ) void SbxArray::Merge( SbxArray* p )
{ {
if( p ) if (!p)
{ return;
sal_uInt32 nSize = p->Count();
for( sal_uInt32 i = 0; i < nSize; i++ ) for (sal_uInt16 i = 0; i < p->Count(); ++i)
{ {
SbxVarEntry* pRef1 = (*(p->mpVarEntries))[i]; SbxVarEntry* pEntry1 = (*p->mpVarEntries)[i];
// Is the element by name already inside? if (!pEntry1->mpVar)
continue;
OUString aName = pEntry1->mpVar->GetName();
sal_uInt16 nHash = pEntry1->mpVar->GetHashCode();
// Is the element by the same name already inside?
// Then overwrite! // Then overwrite!
SbxVariable* pVar = *pRef1; for (size_t j = 0; j < mpVarEntries->size(); ++j)
if( pVar )
{ {
OUString aName = pVar->GetName(); SbxVarEntry* pEntry2 = (*mpVarEntries)[j];
sal_uInt16 nHash = pVar->GetHashCode(); if (!pEntry2->mpVar)
for( sal_uInt32 j = 0; j < mpVarEntries->size(); j++ ) continue;
{
SbxVariableRef* pRef2 = (*mpVarEntries)[j]; if (pEntry2->mpVar->GetHashCode() == nHash &&
if( (*pRef2)->GetHashCode() == nHash pEntry2->mpVar->GetName().equalsIgnoreAsciiCase(aName))
&& (*pRef2)->GetName().equalsIgnoreAsciiCase( aName ) )
{ {
*pRef2 = pVar; pRef1 = NULL; // Take this element and clear the original.
pEntry2->mpVar = pEntry1->mpVar;
pEntry1->mpVar.Clear();
break; break;
} }
} }
if( pRef1 )
{ if (pEntry1->mpVar)
SbxVarEntry* pRef = new SbxVarEntry;
mpVarEntries->push_back(pRef);
*((SbxVariableRef*) pRef) = *((SbxVariableRef*) pRef1);
if (pRef1->maAlias)
{ {
pRef->maAlias.reset(*pRef1->maAlias); // We don't have element with the same name. Add a new entry.
} SbxVarEntry* pNewEntry = new SbxVarEntry;
} mpVarEntries->push_back(pNewEntry);
} pNewEntry->mpVar = pEntry1->mpVar;
if (pEntry1->maAlias)
pNewEntry->maAlias.reset(*pEntry1->maAlias);
} }
} }
} }
...@@ -389,45 +393,48 @@ void SbxArray::Merge( SbxArray* p ) ...@@ -389,45 +393,48 @@ void SbxArray::Merge( SbxArray* p )
SbxVariable* SbxArray::FindUserData( sal_uInt32 nData ) SbxVariable* SbxArray::FindUserData( sal_uInt32 nData )
{ {
SbxVariable* p = NULL; SbxVariable* p = NULL;
for( sal_uInt32 i = 0; i < mpVarEntries->size(); i++ ) for (size_t i = 0; i < mpVarEntries->size(); ++i)
{
SbxVariableRef* pRef = (*mpVarEntries)[i];
SbxVariable* pVar = *pRef;
if( pVar )
{ {
if( pVar->IsVisible() && pVar->GetUserData() == nData ) SbxVarEntry* pEntry = (*mpVarEntries)[i];
if (!pEntry->mpVar)
continue;
if (pEntry->mpVar->IsVisible() && pEntry->mpVar->GetUserData() == nData)
{ {
p = pVar; p = &pEntry->mpVar;
p->ResetFlag( SBX_EXTFOUND ); p->ResetFlag( SBX_EXTFOUND );
break; // JSM 1995-10-06 break; // JSM 1995-10-06
} }
// Did we have an array/object with extended search? // Did we have an array/object with extended search?
else if( pVar->IsSet( SBX_EXTSEARCH ) ) if (pEntry->mpVar->IsSet(SBX_EXTSEARCH))
{ {
switch( pVar->GetClass() ) switch (pEntry->mpVar->GetClass())
{ {
case SbxCLASS_OBJECT: case SbxCLASS_OBJECT:
{ {
// Objects are not allowed to scan their parent. // Objects are not allowed to scan their parent.
sal_uInt16 nOld = pVar->GetFlags(); sal_uInt16 nOld = pEntry->mpVar->GetFlags();
pVar->ResetFlag( SBX_GBLSEARCH ); pEntry->mpVar->ResetFlag(SBX_GBLSEARCH);
p = ((SbxObject*) pVar)->FindUserData( nData ); p = static_cast<SbxObject&>(*pEntry->mpVar).FindUserData(nData);
pVar->SetFlags( nOld ); pEntry->mpVar->SetFlags(nOld);
break;
} }
break;
case SbxCLASS_ARRAY: case SbxCLASS_ARRAY:
p = ((SbxArray*) pVar)->FindUserData( nData ); // Casting SbxVariable to SbxArray? Really?
p = reinterpret_cast<SbxArray&>(*pEntry->mpVar).FindUserData(nData);
break; break;
default: break; default:
;
} }
if( p )
if (p)
{ {
p->SetFlag( SBX_EXTFOUND ); p->SetFlag(SBX_EXTFOUND);
break; break;
} }
} }
} }
}
return p; return p;
} }
...@@ -444,47 +451,50 @@ SbxVariable* SbxArray::Find( const OUString& rName, SbxClassType t ) ...@@ -444,47 +451,50 @@ SbxVariable* SbxArray::Find( const OUString& rName, SbxClassType t )
sal_uInt16 nHash = SbxVariable::MakeHashCode( rName ); sal_uInt16 nHash = SbxVariable::MakeHashCode( rName );
for( sal_uInt32 i = 0; i < nCount; i++ ) for( sal_uInt32 i = 0; i < nCount; i++ )
{ {
SbxVariableRef* pRef = (*mpVarEntries)[i]; SbxVarEntry* pEntry = (*mpVarEntries)[i];
SbxVariable* pVar = *pRef; if (!pEntry->mpVar || !pEntry->mpVar->IsVisible())
if( pVar && pVar->IsVisible() ) continue;
{
// The very secure search works as well, if there is no hashcode! // The very secure search works as well, if there is no hashcode!
sal_uInt16 nVarHash = pVar->GetHashCode(); sal_uInt16 nVarHash = pEntry->mpVar->GetHashCode();
if( ( !nVarHash || nVarHash == nHash ) if ( (!nVarHash || nVarHash == nHash)
&& ( t == SbxCLASS_DONTCARE || pVar->GetClass() == t ) && (t == SbxCLASS_DONTCARE || pEntry->mpVar->GetClass() == t)
&& ( pVar->GetName().equalsIgnoreAsciiCase( rName ) ) ) && (pEntry->mpVar->GetName().equalsIgnoreAsciiCase(rName)))
{ {
p = pVar; p = &pEntry->mpVar;
p->ResetFlag( SBX_EXTFOUND ); p->ResetFlag(SBX_EXTFOUND);
break; break;
} }
// Did we have an array/object with extended search? // Did we have an array/object with extended search?
else if( bExtSearch && pVar->IsSet( SBX_EXTSEARCH ) ) if (bExtSearch && pEntry->mpVar->IsSet(SBX_EXTSEARCH))
{ {
switch( pVar->GetClass() ) switch (pEntry->mpVar->GetClass())
{ {
case SbxCLASS_OBJECT: case SbxCLASS_OBJECT:
{ {
// Objects are not allowed to scan their parent. // Objects are not allowed to scan their parent.
sal_uInt16 nOld = pVar->GetFlags(); sal_uInt16 nOld = pEntry->mpVar->GetFlags();
pVar->ResetFlag( SBX_GBLSEARCH ); pEntry->mpVar->ResetFlag(SBX_GBLSEARCH);
p = ((SbxObject*) pVar)->Find( rName, t ); p = static_cast<SbxObject&>(*pEntry->mpVar).Find(rName, t);
pVar->SetFlags( nOld ); pEntry->mpVar->SetFlags(nOld);
break;
} }
break;
case SbxCLASS_ARRAY: case SbxCLASS_ARRAY:
p = ((SbxArray*) pVar)->Find( rName, t ); // Casting SbxVariable to SbxArray? Really?
p = reinterpret_cast<SbxArray&>(*pEntry->mpVar).Find(rName, t);
break; break;
default: break; default:
;
} }
if( p )
if (p)
{ {
p->SetFlag( SBX_EXTFOUND ); p->SetFlag(SBX_EXTFOUND);
break; break;
} }
} }
} }
}
return p; return p;
} }
...@@ -526,20 +536,18 @@ bool SbxArray::StoreData( SvStream& rStrm ) const ...@@ -526,20 +536,18 @@ bool SbxArray::StoreData( SvStream& rStrm ) const
// Which elements are even defined? // Which elements are even defined?
for( n = 0; n < mpVarEntries->size(); n++ ) for( n = 0; n < mpVarEntries->size(); n++ )
{ {
SbxVariableRef* pRef = (*mpVarEntries)[n]; SbxVarEntry* pEntry = (*mpVarEntries)[n];
SbxVariable* p = *pRef; if (pEntry->mpVar && !(pEntry->mpVar->GetFlags() & SBX_DONTSTORE))
if( p && !( p->GetFlags() & SBX_DONTSTORE ) )
nElem++; nElem++;
} }
rStrm.WriteUInt16( (sal_uInt16) nElem ); rStrm.WriteUInt16( (sal_uInt16) nElem );
for( n = 0; n < mpVarEntries->size(); n++ ) for( n = 0; n < mpVarEntries->size(); n++ )
{ {
SbxVariableRef* pRef = (*mpVarEntries)[n]; SbxVarEntry* pEntry = (*mpVarEntries)[n];
SbxVariable* p = *pRef; if (pEntry->mpVar && !(pEntry->mpVar->GetFlags() & SBX_DONTSTORE))
if( p && !( p->GetFlags() & SBX_DONTSTORE ) )
{ {
rStrm.WriteUInt16( (sal_uInt16) n ); rStrm.WriteUInt16( (sal_uInt16) n );
if( !p->Store( rStrm ) ) if (!pEntry->mpVar->Store(rStrm))
return false; return false;
} }
} }
......
...@@ -115,7 +115,7 @@ public: ...@@ -115,7 +115,7 @@ public:
// The variables convert from SbxVariablen. Put()/Insert() into the // The variables convert from SbxVariablen. Put()/Insert() into the
// declared datatype, if they are not SbxVARIANT. // declared datatype, if they are not SbxVARIANT.
class SbxVarEntry; struct SbxVarEntry;
class BASIC_DLLPUBLIC SbxArray : public SbxBase class BASIC_DLLPUBLIC SbxArray : public SbxBase
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment