diff options
author | Ian <ian.gilham@gmail.com> | 2015-08-12 16:06:46 +0100 |
---|---|---|
committer | David Tardon <dtardon@redhat.com> | 2015-08-13 12:04:24 +0000 |
commit | 3f4482ebc2c3b260d42422efbee92c4210e35767 (patch) | |
tree | 71c9e4232a32e507e18a4986ff1001aa6211862a /scaddins | |
parent | b556f14fab25ddccbe9a54fe53450a641dbc5a49 (diff) |
Removed another FuncDataList collection
This time the existing collection used a vector internally and mapped
operations onto its standard interface.
Removing it in favour of a raw typedef'd vector and find_if reduces the
volume of code and simplifies the lookup mechanism.
Change-Id: I86fdb85773577019073803c2fc249d04196afe31
Reviewed-on: https://gerrit.libreoffice.org/17680
Reviewed-by: David Tardon <dtardon@redhat.com>
Tested-by: David Tardon <dtardon@redhat.com>
Diffstat (limited to 'scaddins')
-rw-r--r-- | scaddins/source/analysis/analysis.cxx | 57 | ||||
-rw-r--r-- | scaddins/source/analysis/analysis.hxx | 1 | ||||
-rw-r--r-- | scaddins/source/analysis/analysishelper.cxx | 35 | ||||
-rw-r--r-- | scaddins/source/analysis/analysishelper.hxx | 34 |
4 files changed, 41 insertions, 86 deletions
diff --git a/scaddins/source/analysis/analysis.cxx b/scaddins/source/analysis/analysis.cxx index 08ac8620e7d7..5bece71a4283 100644 --- a/scaddins/source/analysis/analysis.cxx +++ b/scaddins/source/analysis/analysis.cxx @@ -31,6 +31,7 @@ #include <string.h> #include <tools/resmgr.hxx> #include <tools/rcid.h> +#include <algorithm> #include <cmath> #define ADDIN_SERVICE "com.sun.star.sheet.AddIn" @@ -127,9 +128,14 @@ void AnalysisAddIn::InitData() delete pFD; if( pResMgr ) - pFD = new FuncDataList( *pResMgr ); + { + pFD = new FuncDataList; + InitFuncDataList( *pFD, *pResMgr ); + } else + { pFD = NULL; + } if( pDefLocales ) { @@ -278,11 +284,11 @@ OUString SAL_CALL AnalysisAddIn::getDisplayFunctionName( const OUString& aProgra { OUString aRet; - const FuncData* p = pFD->Get( aProgrammaticName ); - if( p ) + auto it = std::find_if(pFD->begin(), pFD->end(), FindFuncData( aProgrammaticName ) ); + if( it != pFD->end() ) { - aRet = GetDisplFuncStr( p->GetUINameID() ); - if( p->IsDouble() ) + aRet = GetDisplFuncStr( it->GetUINameID() ); + if( it->IsDouble() ) aRet += "_ADD"; } else @@ -297,9 +303,9 @@ OUString SAL_CALL AnalysisAddIn::getFunctionDescription( const OUString& aProgra { OUString aRet; - const FuncData* p = pFD->Get( aProgrammaticName ); - if( p ) - aRet = GetFuncDescrStr( p->GetDescrID(), 1 ); + auto it = std::find_if(pFD->begin(), pFD->end(), FindFuncData( aProgrammaticName ) ); + if( it != pFD->end() ) + aRet = GetFuncDescrStr( it->GetDescrID(), 1 ); return aRet; } @@ -308,12 +314,12 @@ OUString SAL_CALL AnalysisAddIn::getDisplayArgumentName( const OUString& aName, { OUString aRet; - const FuncData* p = pFD->Get( aName ); - if( p && nArg <= 0xFFFF ) + auto it = std::find_if(pFD->begin(), pFD->end(), FindFuncData( aName ) ); + if( it != pFD->end() && nArg <= 0xFFFF ) { - sal_uInt16 nStr = p->GetStrIndex( sal_uInt16( nArg ) ); + sal_uInt16 nStr = it->GetStrIndex( sal_uInt16( nArg ) ); if( nStr ) - aRet = GetFuncDescrStr( p->GetDescrID(), nStr ); + aRet = GetFuncDescrStr( it->GetDescrID(), nStr ); else aRet = "internal"; } @@ -325,12 +331,12 @@ OUString SAL_CALL AnalysisAddIn::getArgumentDescription( const OUString& aName, { OUString aRet; - const FuncData* p = pFD->Get( aName ); - if( p && nArg <= 0xFFFF ) + auto it = std::find_if(pFD->begin(), pFD->end(), FindFuncData( aName ) ); + if( it != pFD->end() && nArg <= 0xFFFF ) { - sal_uInt16 nStr = p->GetStrIndex( sal_uInt16( nArg ) ); + sal_uInt16 nStr = it->GetStrIndex( sal_uInt16( nArg ) ); if( nStr ) - aRet = GetFuncDescrStr( p->GetDescrID(), nStr + 1 ); + aRet = GetFuncDescrStr( it->GetDescrID(), nStr + 1 ); else aRet = "for internal use only"; } @@ -344,11 +350,11 @@ OUString SAL_CALL AnalysisAddIn::getProgrammaticCategoryName( const OUString& aN { // return non-translated strings // return OUString( "Add-In" ); - const FuncData* p = pFD->Get( aName ); + auto it = std::find_if(pFD->begin(), pFD->end(), FindFuncData( aName ) ); OUString aRet; - if( p ) + if( it != pFD->end() ) { - switch( p->GetCategory() ) + switch( it->GetCategory() ) { case FDCat_DateTime: aRet = "Date&Time"; break; case FDCat_Finance: aRet = "Financial"; break; @@ -369,11 +375,11 @@ OUString SAL_CALL AnalysisAddIn::getDisplayCategoryName( const OUString& aProgra { // return translated strings, not used for predefined categories // return OUString( "Add-In" ); - const FuncData* p = pFD->Get( aProgrammaticFunctionName ); + auto it = std::find_if(pFD->begin(), pFD->end(), FindFuncData( aProgrammaticFunctionName ) ); OUString aRet; - if( p ) + if( it != pFD->end() ) { - switch( p->GetCategory() ) + switch( it->GetCategory() ) { case FDCat_DateTime: aRet = "Date&Time"; break; case FDCat_Finance: aRet = "Financial"; break; @@ -418,12 +424,11 @@ inline const lang::Locale& AnalysisAddIn::GetLocale( sal_uInt32 nInd ) uno::Sequence< sheet::LocalizedName > SAL_CALL AnalysisAddIn::getCompatibilityNames( const OUString& aProgrammaticName ) throw( uno::RuntimeException, std::exception ) { - const FuncData* p = pFD->Get( aProgrammaticName ); - - if( !p ) + auto it = std::find_if(pFD->begin(), pFD->end(), FindFuncData( aProgrammaticName ) ); + if( it == pFD->end() ) return uno::Sequence< sheet::LocalizedName >( 0 ); - const std::vector<OUString>& r = p->GetCompNameList(); + const std::vector<OUString>& r = it->GetCompNameList(); sal_uInt32 nCount = r.size(); uno::Sequence< sheet::LocalizedName > aRet( nCount ); diff --git a/scaddins/source/analysis/analysis.hxx b/scaddins/source/analysis/analysis.hxx index 79cd750ba183..f8b4593c2f4c 100644 --- a/scaddins/source/analysis/analysis.hxx +++ b/scaddins/source/analysis/analysis.hxx @@ -36,7 +36,6 @@ #include "analysishelper.hxx" namespace sca { namespace analysis { - class FuncDataList; class ConvertDataList; } } class ResMgr; diff --git a/scaddins/source/analysis/analysishelper.cxx b/scaddins/source/analysis/analysishelper.cxx index 8c1e8913c8c8..1300c8ebcd00 100644 --- a/scaddins/source/analysis/analysishelper.cxx +++ b/scaddins/source/analysis/analysishelper.cxx @@ -1430,41 +1430,10 @@ sal_uInt16 FuncData::GetStrIndex( sal_uInt16 nParamNum ) const } -FuncDataList::FuncDataList( ResMgr& rResMgr ) - : nLast(0) +void InitFuncDataList( FuncDataList& rList, ResMgr& rResMgr ) { for( sal_uInt16 n = 0 ; n < SAL_N_ELEMENTS(pFuncDatas) ; n++ ) - Append( new FuncData( pFuncDatas[ n ], rResMgr ) ); -} - - -FuncDataList::~FuncDataList() -{ - for( std::vector<FuncData*>::iterator it = maVector.begin(); it != maVector.end(); ++it ) - delete *it; -} - - -const FuncData* FuncDataList::Get( const OUString& aProgrammaticName ) const -{ - if( aLastName == aProgrammaticName ) - return Get( nLast ); - - const_cast<FuncDataList*>(this)->aLastName = aProgrammaticName; - - sal_uInt32 nE = Count(); - for( sal_uInt32 n = 0 ; n < nE ; n++ ) - { - const FuncData* p = Get( n ); - if( p->Is( aProgrammaticName ) ) - { - const_cast<FuncDataList*>(this)->nLast = n; - return p; - } - } - - const_cast<FuncDataList*>(this)->nLast = 0xFFFFFFFF; - return NULL; + rList.push_back( FuncData( pFuncDatas[ n ], rResMgr ) ); } diff --git a/scaddins/source/analysis/analysishelper.hxx b/scaddins/source/analysis/analysishelper.hxx index d82af307a9c5..c44ca470132b 100644 --- a/scaddins/source/analysis/analysishelper.hxx +++ b/scaddins/source/analysis/analysishelper.hxx @@ -201,22 +201,16 @@ public: inline FDCategory GetCategory() const; }; +typedef std::vector< FuncData > FuncDataList; -class FuncDataList -{ - OUString aLastName; - sal_uInt32 nLast; - std::vector<FuncData*> maVector; -public: - FuncDataList( ResMgr& ); - virtual ~FuncDataList(); - - inline void Append( FuncData* pNew ); - inline const FuncData* Get( sal_uInt32 nIndex ) const; - inline sal_uInt32 Count() const - { return maVector.size(); } +void InitFuncDataList ( FuncDataList& rList, ResMgr& rResMgr ); - const FuncData* Get( const OUString& aProgrammaticName ) const; +// Predicate for use with std::find_if +struct FindFuncData +{ + const OUString& m_rId; + explicit FindFuncData( const OUString& rId ) : m_rId(rId) {} + bool operator() ( FuncData& rCandidate ) const { return rCandidate.Is(m_rId); } }; class AnalysisResId : public ResId @@ -589,18 +583,6 @@ inline FDCategory FuncData::GetCategory() const } -inline void FuncDataList::Append( FuncData* p ) -{ - maVector.push_back( p ); -} - - -inline const FuncData* FuncDataList::Get( sal_uInt32 n ) const -{ - return maVector[n]; -} - - inline Complex::Complex( double fReal, double fImag, sal_Unicode cC ) : r( fReal ), i( fImag ), c( cC ) { |