Use boost::optional to store alias name.

Change-Id: I809b21ea156061a265c0d83d58534df10bc273bc
This commit is contained in:
Kohei Yoshida
2014-06-25 12:38:14 -04:00
parent ff0ecb2621
commit e14abb13dc
3 changed files with 24 additions and 33 deletions

View File

@@ -3717,10 +3717,10 @@ void SbiRuntime::SetupArgs( SbxVariable* p, sal_uInt32 nOp1 )
for( i = 1 ; i < nArgCount ; i++ )
{
SbxVariable* pVar = refArgv->Get( i );
const OUString& rName = refArgv->GetAlias( i );
if( !rName.isEmpty() )
OUString aName = refArgv->GetAlias(i);
if (!aName.isEmpty())
{
pNames[i] = rName;
pNames[i] = aName;
}
pArg->Put( pVar, nCurPar++ );
}
@@ -3774,15 +3774,15 @@ void SbiRuntime::SetupArgs( SbxVariable* p, sal_uInt32 nOp1 )
for( i = 1 ; i < nArgCount ; i++ )
{
SbxVariable* pVar = refArgv->Get( i );
const OUString& rName = refArgv->GetAlias( i );
if( !rName.isEmpty() )
OUString aName = refArgv->GetAlias(i);
if (!aName.isEmpty())
{
// nCurPar is set to the found parameter
sal_uInt16 j = 1;
const SbxParamInfo* pParam = pInfo->GetParam( j );
while( pParam )
{
if( pParam->aName.equalsIgnoreAsciiCase( rName ) )
if( pParam->aName.equalsIgnoreAsciiCase( aName ) )
{
nCurPar = j;
break;

View File

@@ -21,6 +21,9 @@
#include <basic/sbx.hxx>
#include "runtime.hxx"
#include <vector>
#include <boost/optional.hpp>
using namespace std;
struct SbxDim { // an array-dimension:
@@ -31,9 +34,8 @@ struct SbxDim { // an array-dimension:
class SbxVarEntry : public SbxVariableRef {
public:
OUString* pAlias;
SbxVarEntry() : SbxVariableRef(), pAlias( NULL ) {}
~SbxVarEntry() { delete pAlias; }
boost::optional<OUString> maAlias;
SbxVarEntry() : SbxVariableRef() {}
};
TYPEINIT1(SbxArray,SbxBase)
@@ -73,10 +75,10 @@ SbxArray& SbxArray::operator=( const SbxArray& rArray )
continue;
SbxVarEntry* pDstRef = new SbxVarEntry;
*((SbxVariableRef*) pDstRef) = *((SbxVariableRef*) pSrcRef);
if( pSrcRef->pAlias )
{
pDstRef->pAlias = new OUString( *pSrcRef->pAlias );
}
if (pSrcRef->maAlias)
pDstRef->maAlias.reset(*pSrcRef->maAlias);
if( eType != SbxVARIANT )
{
// Convert no objects
@@ -234,23 +236,19 @@ void SbxArray::Put( SbxVariable* pVar, sal_uInt16 nIdx )
}
}
const OUString& SbxArray::GetAlias( sal_uInt16 nIdx )
OUString SbxArray::GetAlias( sal_uInt16 nIdx )
{
static const OUString sEmpty("");
if( !CanRead() )
{
SetError( SbxERR_PROP_WRITEONLY );
return sEmpty;
return OUString();
}
SbxVarEntry& rRef = (SbxVarEntry&) GetRef( nIdx );
if ( !rRef.pAlias )
{
return sEmpty;
}
if (!rRef.maAlias)
return OUString();
return *rRef.pAlias;
return *rRef.maAlias;
}
void SbxArray::PutAlias( const OUString& rAlias, sal_uInt16 nIdx )
@@ -262,14 +260,7 @@ void SbxArray::PutAlias( const OUString& rAlias, sal_uInt16 nIdx )
else
{
SbxVarEntry& rRef = (SbxVarEntry&) GetRef( nIdx );
if( !rRef.pAlias )
{
rRef.pAlias = new OUString( rAlias );
}
else
{
*rRef.pAlias = rAlias;
}
rRef.maAlias.reset(rAlias);
}
}
@@ -382,9 +373,9 @@ void SbxArray::Merge( SbxArray* p )
SbxVarEntry* pRef = new SbxVarEntry;
mpVarEntries->push_back(pRef);
*((SbxVariableRef*) pRef) = *((SbxVariableRef*) pRef1);
if( pRef1->pAlias )
if (pRef1->maAlias)
{
pRef->pAlias = new OUString( *pRef1->pAlias );
pRef->maAlias.reset(*pRef1->maAlias);
}
}
}

View File

@@ -152,7 +152,7 @@ public:
void Remove( sal_uInt16 );
void Remove( SbxVariable* );
void Merge( SbxArray* );
const OUString& GetAlias( sal_uInt16 );
OUString GetAlias( sal_uInt16 );
void PutAlias( const OUString&, sal_uInt16 );
SbxVariable* FindUserData( sal_uInt32 nUserData );
virtual SbxVariable* Find( const OUString&, SbxClassType );