tdf#90222: Removed ScaFuncDataList type
This repeats the same change in the pricing addin as already carried out in datefunc. This type was a special case of a custom implemented list, and wasused like a map. I have replaced it with a std::map typedef'd as ScaFuncDataMap. Since the map key also exists in the value object, there are more memory-efficient ways to implement this with a vector and a predicate functor for searching at the cost of some code complexity. I opted for the simpler code afforded by using a std::map implementation. Change-Id: I7d28e0bc58f713cf4f4e962302e09788b3ac4218 Reviewed-on: https://gerrit.libreoffice.org/17651 Reviewed-by: David Tardon <dtardon@redhat.com> Tested-by: David Tardon <dtardon@redhat.com>
This commit is contained in:
parent
0a726cb299
commit
a5cebd1bfc
@ -122,36 +122,14 @@ sal_uInt16 ScaFuncData::GetStrIndex( sal_uInt16 nParam ) const
|
||||
return (nParam > nParamCount) ? (nParamCount * 2) : (nParam * 2);
|
||||
}
|
||||
|
||||
ScaFuncDataList::ScaFuncDataList( ResMgr& rResMgr ) :
|
||||
nLast( 0xFFFFFFFF )
|
||||
void sca::pricing::InitScaFuncDataMap( ScaFuncDataMap& rMap, ResMgr& rResMgr )
|
||||
{
|
||||
for( sal_uInt16 nIndex = 0; nIndex < SAL_N_ELEMENTS(pFuncDataArr); nIndex++ )
|
||||
Append( new ScaFuncData( pFuncDataArr[ nIndex ], rResMgr ) );
|
||||
}
|
||||
|
||||
ScaFuncDataList::~ScaFuncDataList()
|
||||
{
|
||||
for( ScaFuncData* pFData = First(); pFData; pFData = Next() )
|
||||
delete pFData;
|
||||
}
|
||||
|
||||
const ScaFuncData* ScaFuncDataList::Get( const OUString& rProgrammaticName ) const
|
||||
{
|
||||
if( aLastName == rProgrammaticName ){
|
||||
return Get( nLast );
|
||||
}
|
||||
|
||||
for( sal_uInt32 nIndex = 0; nIndex < Count(); nIndex++ )
|
||||
{
|
||||
const ScaFuncData* pCurr = Get( nIndex );
|
||||
if( pCurr->Is( rProgrammaticName ) )
|
||||
{
|
||||
const_cast< ScaFuncDataList* >( this )->aLastName = rProgrammaticName;
|
||||
const_cast< ScaFuncDataList* >( this )->nLast = nIndex;
|
||||
return pCurr;
|
||||
}
|
||||
rMap.insert( std::make_pair(
|
||||
OUString::createFromAscii(pFuncDataArr[ nIndex ].pIntName),
|
||||
ScaFuncData( pFuncDataArr[ nIndex ], rResMgr ) ) );
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ScaFuncRes::ScaFuncRes( ResId& rResId, ResMgr& rResMgr, sal_uInt16 nIndex, OUString& rRet ) :
|
||||
@ -200,13 +178,13 @@ SAL_DLLPUBLIC_EXPORT void * SAL_CALL pricing_component_getFactory(
|
||||
ScaPricingAddIn::ScaPricingAddIn() :
|
||||
pDefLocales( NULL ),
|
||||
pResMgr( NULL ),
|
||||
pFuncDataList( NULL )
|
||||
pFuncDataMap( NULL )
|
||||
{
|
||||
}
|
||||
|
||||
ScaPricingAddIn::~ScaPricingAddIn()
|
||||
{
|
||||
delete pFuncDataList;
|
||||
delete pFuncDataMap;
|
||||
delete pResMgr;
|
||||
delete[] pDefLocales;
|
||||
}
|
||||
@ -249,9 +227,17 @@ void ScaPricingAddIn::InitData()
|
||||
{
|
||||
delete pResMgr;
|
||||
pResMgr = ResMgr::CreateResMgr("pricing", LanguageTag( aFuncLoc) );
|
||||
delete pFuncDataList;
|
||||
delete pFuncDataMap;
|
||||
|
||||
pFuncDataList = pResMgr ? new ScaFuncDataList( *pResMgr ) : NULL;
|
||||
if(pResMgr)
|
||||
{
|
||||
pFuncDataMap = new ScaFuncDataMap;
|
||||
InitScaFuncDataMap( *pFuncDataMap, *pResMgr );
|
||||
}
|
||||
else
|
||||
{
|
||||
pFuncDataMap = nullptr;
|
||||
}
|
||||
|
||||
if( pDefLocales )
|
||||
{
|
||||
@ -342,11 +328,12 @@ OUString SAL_CALL ScaPricingAddIn::getDisplayFunctionName( const OUString& aProg
|
||||
{
|
||||
OUString aRet;
|
||||
|
||||
const ScaFuncData* pFData = pFuncDataList->Get( aProgrammaticName );
|
||||
if( pFData )
|
||||
auto fDataIt = pFuncDataMap->find( aProgrammaticName );
|
||||
if(fDataIt != pFuncDataMap->end() )
|
||||
{
|
||||
aRet = GetDisplFuncStr( pFData->GetUINameID() );
|
||||
if( pFData->IsDouble() )
|
||||
auto data = fDataIt->second;
|
||||
aRet = GetDisplFuncStr( data.GetUINameID() );
|
||||
if( data.IsDouble() )
|
||||
aRet += STR_FROM_ANSI( "_ADD" );
|
||||
}
|
||||
else
|
||||
@ -362,9 +349,9 @@ OUString SAL_CALL ScaPricingAddIn::getFunctionDescription( const OUString& aProg
|
||||
{
|
||||
OUString aRet;
|
||||
|
||||
const ScaFuncData* pFData = pFuncDataList->Get( aProgrammaticName );
|
||||
if( pFData )
|
||||
aRet = GetFuncDescrStr( pFData->GetDescrID(), 1 );
|
||||
auto fDataIt = pFuncDataMap->find( aProgrammaticName );
|
||||
if( fDataIt != pFuncDataMap->end() )
|
||||
aRet = GetFuncDescrStr( fDataIt->second.GetDescrID(), 1 );
|
||||
|
||||
return aRet;
|
||||
}
|
||||
@ -374,12 +361,13 @@ OUString SAL_CALL ScaPricingAddIn::getDisplayArgumentName(
|
||||
{
|
||||
OUString aRet;
|
||||
|
||||
const ScaFuncData* pFData = pFuncDataList->Get( aProgrammaticName );
|
||||
if( pFData && (nArgument <= 0xFFFF) )
|
||||
auto fDataIt = pFuncDataMap->find( aProgrammaticName );
|
||||
if( fDataIt != pFuncDataMap->end() && (nArgument <= 0xFFFF) )
|
||||
{
|
||||
sal_uInt16 nStr = pFData->GetStrIndex( static_cast< sal_uInt16 >( nArgument ) );
|
||||
auto data = fDataIt->second;
|
||||
sal_uInt16 nStr = data.GetStrIndex( static_cast< sal_uInt16 >( nArgument ) );
|
||||
if( nStr )
|
||||
aRet = GetFuncDescrStr( pFData->GetDescrID(), nStr );
|
||||
aRet = GetFuncDescrStr( data.GetDescrID(), nStr );
|
||||
else
|
||||
aRet = STR_FROM_ANSI( "internal" );
|
||||
}
|
||||
@ -392,12 +380,13 @@ OUString SAL_CALL ScaPricingAddIn::getArgumentDescription(
|
||||
{
|
||||
OUString aRet;
|
||||
|
||||
const ScaFuncData* pFData = pFuncDataList->Get( aProgrammaticName );
|
||||
if( pFData && (nArgument <= 0xFFFF) )
|
||||
auto fDataIt = pFuncDataMap->find( aProgrammaticName );
|
||||
if( fDataIt != pFuncDataMap->end() && (nArgument <= 0xFFFF) )
|
||||
{
|
||||
sal_uInt16 nStr = pFData->GetStrIndex( static_cast< sal_uInt16 >( nArgument ) );
|
||||
auto data = fDataIt->second;
|
||||
sal_uInt16 nStr = data.GetStrIndex( static_cast< sal_uInt16 >( nArgument ) );
|
||||
if( nStr )
|
||||
aRet = GetFuncDescrStr( pFData->GetDescrID(), nStr + 1 );
|
||||
aRet = GetFuncDescrStr( data.GetDescrID(), nStr + 1 );
|
||||
else
|
||||
aRet = STR_FROM_ANSI( "for internal use only" );
|
||||
}
|
||||
@ -410,10 +399,10 @@ OUString SAL_CALL ScaPricingAddIn::getProgrammaticCategoryName(
|
||||
{
|
||||
OUString aRet;
|
||||
|
||||
const ScaFuncData* pFData = pFuncDataList->Get( aProgrammaticName );
|
||||
if( pFData )
|
||||
auto fDataIt = pFuncDataMap->find( aProgrammaticName );
|
||||
if( fDataIt != pFuncDataMap->end() )
|
||||
{
|
||||
switch( pFData->GetCategory() )
|
||||
switch( fDataIt->second.GetCategory() )
|
||||
{
|
||||
case ScaCat_DateTime: aRet = STR_FROM_ANSI( "Date&Time" ); break;
|
||||
case ScaCat_Text: aRet = STR_FROM_ANSI( "Text" ); break;
|
||||
@ -442,11 +431,11 @@ OUString SAL_CALL ScaPricingAddIn::getDisplayCategoryName(
|
||||
uno::Sequence< sheet::LocalizedName > SAL_CALL ScaPricingAddIn::getCompatibilityNames(
|
||||
const OUString& aProgrammaticName ) throw( uno::RuntimeException, std::exception )
|
||||
{
|
||||
const ScaFuncData* pFData = pFuncDataList->Get( aProgrammaticName );
|
||||
if( !pFData )
|
||||
auto fDataIt = pFuncDataMap->find( aProgrammaticName );
|
||||
if( fDataIt == pFuncDataMap->end() )
|
||||
return uno::Sequence< sheet::LocalizedName >( 0 );
|
||||
|
||||
const std::vector<OUString>& rStrList = pFData->GetCompNameList();
|
||||
const std::vector<OUString>& rStrList = fDataIt->second.GetCompNameList();
|
||||
sal_uInt32 nCount = rStrList.size();
|
||||
|
||||
uno::Sequence< sheet::LocalizedName > aRet( nCount );
|
||||
|
@ -30,6 +30,7 @@
|
||||
|
||||
#include <string.h>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <com/sun/star/lang/XServiceName.hpp>
|
||||
#include <com/sun/star/lang/XServiceInfo.hpp>
|
||||
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
|
||||
@ -210,41 +211,9 @@ public:
|
||||
};
|
||||
|
||||
|
||||
class ScaFuncDataList : private ScaList
|
||||
{
|
||||
OUString aLastName;
|
||||
sal_uInt32 nLast;
|
||||
typedef std::map<OUString, ScaFuncData> ScaFuncDataMap;
|
||||
|
||||
public:
|
||||
ScaFuncDataList( ResMgr& rResMgr );
|
||||
virtual ~ScaFuncDataList();
|
||||
|
||||
using ScaList::Count;
|
||||
|
||||
inline const ScaFuncData* Get( sal_uInt32 nIndex ) const;
|
||||
const ScaFuncData* Get( const OUString& rProgrammaticName ) const;
|
||||
inline ScaFuncData* First();
|
||||
inline ScaFuncData* Next();
|
||||
|
||||
using ScaList::Append;
|
||||
inline void Append( ScaFuncData* pNew ) { ScaList::Append( pNew ); }
|
||||
};
|
||||
|
||||
|
||||
inline const ScaFuncData* ScaFuncDataList::Get( sal_uInt32 nIndex ) const
|
||||
{
|
||||
return static_cast< const ScaFuncData* >( ScaList::GetObject( nIndex ) );
|
||||
}
|
||||
|
||||
inline ScaFuncData* ScaFuncDataList::First()
|
||||
{
|
||||
return static_cast< ScaFuncData* >( ScaList::First() );
|
||||
}
|
||||
|
||||
inline ScaFuncData* ScaFuncDataList::Next()
|
||||
{
|
||||
return static_cast< ScaFuncData* >( ScaList::Next() );
|
||||
}
|
||||
void InitScaFuncDataMap ( ScaFuncDataMap& rMap, ResMgr& rResMgr );
|
||||
|
||||
} // namespace pricing
|
||||
} // namespace sca
|
||||
@ -269,7 +238,7 @@ private:
|
||||
css::lang::Locale aFuncLoc;
|
||||
css::lang::Locale* pDefLocales;
|
||||
ResMgr* pResMgr;
|
||||
sca::pricing::ScaFuncDataList* pFuncDataList;
|
||||
sca::pricing::ScaFuncDataMap* pFuncDataMap;
|
||||
|
||||
|
||||
void InitDefLocales();
|
||||
|
Loading…
x
Reference in New Issue
Block a user