Kaydet (Commit) 46ae6392 authored tarafından Ian's avatar Ian Kaydeden (comit) Noel Grandin

tdf#90222: Removed ScaFuncDataList type

This type was a special case of a custom implemented list, and was used
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: Idd450f4a908ff503cb02e8e363ddbe3512903f47
Reviewed-on: https://gerrit.libreoffice.org/17579Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarNoel Grandin <noelgrandin@gmail.com>
üst 678bb513
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include <rtl/ustrbuf.hxx> #include <rtl/ustrbuf.hxx>
#include <tools/rcid.h> #include <tools/rcid.h>
#include <tools/resmgr.hxx> #include <tools/resmgr.hxx>
#include <utility>
using namespace ::com::sun::star; using namespace ::com::sun::star;
...@@ -118,35 +119,14 @@ sal_uInt16 ScaFuncData::GetStrIndex( sal_uInt16 nParam ) const ...@@ -118,35 +119,14 @@ sal_uInt16 ScaFuncData::GetStrIndex( sal_uInt16 nParam ) const
} }
ScaFuncDataList::ScaFuncDataList( ResMgr& rResMgr ) : void InitScaFuncDataMap( ScaFuncDataMap& rMap, ResMgr& rResMgr )
nLast( 0xFFFFFFFF )
{ {
for( sal_uInt16 nIndex = 0; nIndex < SAL_N_ELEMENTS(pFuncDataArr); nIndex++ ) 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 ); rMap.insert( std::make_pair(
if( pCurr->Is( rProgrammaticName ) ) OUString::createFromAscii(pFuncDataArr[ nIndex ].pIntName),
{ ScaFuncData( pFuncDataArr[ nIndex ], rResMgr ) ) );
const_cast< ScaFuncDataList* >( this )->aLastName = rProgrammaticName;
const_cast< ScaFuncDataList* >( this )->nLast = nIndex;
return pCurr;
}
} }
return NULL;
} }
ScaFuncRes::ScaFuncRes( ResId& rResId, ResMgr& rResMgr, sal_uInt16 nIndex, OUString& rRet ) : ScaFuncRes::ScaFuncRes( ResId& rResId, ResMgr& rResMgr, sal_uInt16 nIndex, OUString& rRet ) :
...@@ -195,13 +175,13 @@ SAL_DLLPUBLIC_EXPORT void * SAL_CALL date_component_getFactory( ...@@ -195,13 +175,13 @@ SAL_DLLPUBLIC_EXPORT void * SAL_CALL date_component_getFactory(
ScaDateAddIn::ScaDateAddIn() : ScaDateAddIn::ScaDateAddIn() :
pDefLocales( NULL ), pDefLocales( NULL ),
pResMgr( NULL ), pResMgr( NULL ),
pFuncDataList( NULL ) pFuncDataMap( NULL )
{ {
} }
ScaDateAddIn::~ScaDateAddIn() ScaDateAddIn::~ScaDateAddIn()
{ {
delete pFuncDataList; delete pFuncDataMap;
delete pResMgr; delete pResMgr;
delete[] pDefLocales; delete[] pDefLocales;
} }
...@@ -244,9 +224,17 @@ void ScaDateAddIn::InitData() ...@@ -244,9 +224,17 @@ void ScaDateAddIn::InitData()
{ {
delete pResMgr; delete pResMgr;
pResMgr = ResMgr::CreateResMgr("date", LanguageTag(aFuncLoc)); pResMgr = ResMgr::CreateResMgr("date", 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 ) if( pDefLocales )
{ {
...@@ -335,11 +323,12 @@ OUString SAL_CALL ScaDateAddIn::getDisplayFunctionName( const OUString& aProgram ...@@ -335,11 +323,12 @@ OUString SAL_CALL ScaDateAddIn::getDisplayFunctionName( const OUString& aProgram
{ {
OUString aRet; OUString aRet;
const ScaFuncData* pFData = pFuncDataList->Get( aProgrammaticName ); auto fDataIt = pFuncDataMap->find( aProgrammaticName );
if( pFData ) if( fDataIt != pFuncDataMap->end() )
{ {
aRet = GetDisplFuncStr( pFData->GetUINameID() ); ScaFuncData& fData = fDataIt->second;
if( pFData->IsDouble() ) aRet = GetDisplFuncStr( fData.GetUINameID() );
if( fData.IsDouble() )
aRet += STR_FROM_ANSI( "_ADD" ); aRet += STR_FROM_ANSI( "_ADD" );
} }
else else
...@@ -355,9 +344,9 @@ OUString SAL_CALL ScaDateAddIn::getFunctionDescription( const OUString& aProgram ...@@ -355,9 +344,9 @@ OUString SAL_CALL ScaDateAddIn::getFunctionDescription( const OUString& aProgram
{ {
OUString aRet; OUString aRet;
const ScaFuncData* pFData = pFuncDataList->Get( aProgrammaticName ); auto fDataIt = pFuncDataMap->find( aProgrammaticName );
if( pFData ) if( fDataIt != pFuncDataMap->end() )
aRet = GetFuncDescrStr( pFData->GetDescrID(), 1 ); aRet = GetFuncDescrStr( fDataIt->second.GetDescrID(), 1 );
return aRet; return aRet;
} }
...@@ -367,12 +356,13 @@ OUString SAL_CALL ScaDateAddIn::getDisplayArgumentName( ...@@ -367,12 +356,13 @@ OUString SAL_CALL ScaDateAddIn::getDisplayArgumentName(
{ {
OUString aRet; OUString aRet;
const ScaFuncData* pFData = pFuncDataList->Get( aProgrammaticName ); auto fDataIt = pFuncDataMap->find( aProgrammaticName );
if( pFData && (nArgument <= 0xFFFF) ) if( fDataIt != pFuncDataMap->end() && (nArgument <= 0xFFFF) )
{ {
sal_uInt16 nStr = pFData->GetStrIndex( static_cast< sal_uInt16 >( nArgument ) ); auto fData = fDataIt->second;
sal_uInt16 nStr = fData.GetStrIndex( static_cast< sal_uInt16 >( nArgument ) );
if( nStr ) if( nStr )
aRet = GetFuncDescrStr( pFData->GetDescrID(), nStr ); aRet = GetFuncDescrStr( fData.GetDescrID(), nStr );
else else
aRet = STR_FROM_ANSI( "internal" ); aRet = STR_FROM_ANSI( "internal" );
} }
...@@ -385,12 +375,13 @@ OUString SAL_CALL ScaDateAddIn::getArgumentDescription( ...@@ -385,12 +375,13 @@ OUString SAL_CALL ScaDateAddIn::getArgumentDescription(
{ {
OUString aRet; OUString aRet;
const ScaFuncData* pFData = pFuncDataList->Get( aProgrammaticName ); auto fDataIt = pFuncDataMap->find( aProgrammaticName );
if( pFData && (nArgument <= 0xFFFF) ) if( fDataIt != pFuncDataMap->end() && (nArgument <= 0xFFFF) )
{ {
sal_uInt16 nStr = pFData->GetStrIndex( static_cast< sal_uInt16 >( nArgument ) ); auto fData = fDataIt->second;
sal_uInt16 nStr = fData.GetStrIndex( static_cast< sal_uInt16 >( nArgument ) );
if( nStr ) if( nStr )
aRet = GetFuncDescrStr( pFData->GetDescrID(), nStr + 1 ); aRet = GetFuncDescrStr( fData.GetDescrID(), nStr + 1 );
else else
aRet = STR_FROM_ANSI( "for internal use only" ); aRet = STR_FROM_ANSI( "for internal use only" );
} }
...@@ -403,10 +394,10 @@ OUString SAL_CALL ScaDateAddIn::getProgrammaticCategoryName( ...@@ -403,10 +394,10 @@ OUString SAL_CALL ScaDateAddIn::getProgrammaticCategoryName(
{ {
OUString aRet; OUString aRet;
const ScaFuncData* pFData = pFuncDataList->Get( aProgrammaticName ); auto fDataIt = pFuncDataMap->find( aProgrammaticName );
if( pFData ) if( fDataIt != pFuncDataMap->end() )
{ {
switch( pFData->GetCategory() ) switch( fDataIt->second.GetCategory() )
{ {
case ScaCat_DateTime: aRet = STR_FROM_ANSI( "Date&Time" ); break; case ScaCat_DateTime: aRet = STR_FROM_ANSI( "Date&Time" ); break;
case ScaCat_Text: aRet = STR_FROM_ANSI( "Text" ); break; case ScaCat_Text: aRet = STR_FROM_ANSI( "Text" ); break;
...@@ -435,11 +426,11 @@ OUString SAL_CALL ScaDateAddIn::getDisplayCategoryName( ...@@ -435,11 +426,11 @@ OUString SAL_CALL ScaDateAddIn::getDisplayCategoryName(
uno::Sequence< sheet::LocalizedName > SAL_CALL ScaDateAddIn::getCompatibilityNames( uno::Sequence< sheet::LocalizedName > SAL_CALL ScaDateAddIn::getCompatibilityNames(
const OUString& aProgrammaticName ) throw( uno::RuntimeException, std::exception ) const OUString& aProgrammaticName ) throw( uno::RuntimeException, std::exception )
{ {
const ScaFuncData* pFData = pFuncDataList->Get( aProgrammaticName ); auto fDataIt = pFuncDataMap->find( aProgrammaticName );
if( !pFData ) if( fDataIt == pFuncDataMap->end() )
return uno::Sequence< sheet::LocalizedName >( 0 ); 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(); sal_uInt32 nCount = rStrList.size();
uno::Sequence< sheet::LocalizedName > aRet( nCount ); uno::Sequence< sheet::LocalizedName > aRet( nCount );
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include <string.h> #include <string.h>
#include <vector> #include <vector>
#include <map>
#include <com/sun/star/lang/XServiceName.hpp> #include <com/sun/star/lang/XServiceName.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp> #include <com/sun/star/lang/XMultiServiceFactory.hpp>
...@@ -171,7 +172,7 @@ struct ScaFuncDataBase ...@@ -171,7 +172,7 @@ struct ScaFuncDataBase
class ScaFuncData class ScaFuncData
{ {
private: private:
OUString aIntName; // internal name (get***) OUString aIntName; // internal name (get***)
sal_uInt16 nUINameID; // resource ID to UI name sal_uInt16 nUINameID; // resource ID to UI name
sal_uInt16 nDescrID; // leads also to parameter descriptions! sal_uInt16 nDescrID; // leads also to parameter descriptions!
sal_uInt16 nCompListID; // resource ID to list of valid names sal_uInt16 nCompListID; // resource ID to list of valid names
...@@ -197,43 +198,9 @@ public: ...@@ -197,43 +198,9 @@ public:
inline const std::vector<OUString>& GetCompNameList() const { return aCompList; } inline const std::vector<OUString>& GetCompNameList() const { return aCompList; }
}; };
typedef std::map<OUString, ScaFuncData> ScaFuncDataMap;
class ScaFuncDataList : private ScaList void InitScaFuncDataMap ( ScaFuncDataMap& rMap, ResMgr& rResMgr );
{
OUString aLastName;
sal_uInt32 nLast;
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() );
}
::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL DateFunctionAddIn_CreateInstance( ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL DateFunctionAddIn_CreateInstance(
...@@ -253,8 +220,8 @@ class ScaDateAddIn : public ::cppu::WeakImplHelper6< ...@@ -253,8 +220,8 @@ class ScaDateAddIn : public ::cppu::WeakImplHelper6<
private: private:
::com::sun::star::lang::Locale aFuncLoc; ::com::sun::star::lang::Locale aFuncLoc;
::com::sun::star::lang::Locale* pDefLocales; ::com::sun::star::lang::Locale* pDefLocales;
ResMgr* pResMgr; ResMgr* pResMgr;
ScaFuncDataList* pFuncDataList; ScaFuncDataMap* pFuncDataMap;
void InitDefLocales(); void InitDefLocales();
......
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