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

View File

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