Kaydet (Commit) 1f3eed97 authored tarafından Noel Grandin's avatar Noel Grandin

convert custom list implementation ScaDoubleList to std::vector

Change-Id: I98865a54f675ebdb7724327305f9f9a5eeccfeb4
üst 20c4de49
...@@ -683,9 +683,10 @@ AnalysisAddIn::getMultinomial( const uno::Reference< beans::XPropertySet >& xOpt ...@@ -683,9 +683,10 @@ AnalysisAddIn::getMultinomial( const uno::Reference< beans::XPropertySet >& xOpt
double nZ = 0; double nZ = 0;
double fRet = 1.0; double fRet = 1.0;
for( const double *p = aValList.First(); p; p = aValList.Next() ) for( sal_uInt32 i = 0; i < aValList.Count(); ++i )
{ {
double n = (*p >= 0.0) ? rtl::math::approxFloor( *p ) : rtl::math::approxCeil( *p ); const double d = aValList.Get(i);
double n = (d >= 0.0) ? rtl::math::approxFloor( d ) : rtl::math::approxCeil( d );
if ( n < 0.0 ) if ( n < 0.0 )
throw lang::IllegalArgumentException(); throw lang::IllegalArgumentException();
...@@ -787,15 +788,10 @@ double SAL_CALL AnalysisAddIn::getGcd( const uno::Reference< beans::XPropertySet ...@@ -787,15 +788,10 @@ double SAL_CALL AnalysisAddIn::getGcd( const uno::Reference< beans::XPropertySet
if( aValList.Count() == 0 ) if( aValList.Count() == 0 )
return 0.0; return 0.0;
const double* p = aValList.First(); double f = aValList.Get(0);
double f = *p; for( sal_uInt32 i = 1; i < aValList.Count(); ++i )
p = aValList.Next();
while( p )
{ {
f = GetGcd( *p, f ); f = GetGcd( aValList.Get(i), f );
p = aValList.Next();
} }
RETURN_FINITE( f ); RETURN_FINITE( f );
...@@ -812,22 +808,18 @@ double SAL_CALL AnalysisAddIn::getLcm( const uno::Reference< beans::XPropertySet ...@@ -812,22 +808,18 @@ double SAL_CALL AnalysisAddIn::getLcm( const uno::Reference< beans::XPropertySet
if( aValList.Count() == 0 ) if( aValList.Count() == 0 )
return 0.0; return 0.0;
const double* p = aValList.First(); double f = aValList.Get(0);
double f = *p;
if( f == 0.0 ) if( f == 0.0 )
return f; return f;
p = aValList.Next(); for( sal_uInt32 i = 1; i < aValList.Count(); ++i )
while( p )
{ {
double fTmp = *p; double fTmp = aValList.Get(i);
if( f == 0.0 ) if( f == 0.0 )
return f; return f;
else else
f = fTmp * f / GetGcd( fTmp, f ); f = fTmp * f / GetGcd( fTmp, f );
p = aValList.Next();
} }
RETURN_FINITE( f ); RETURN_FINITE( f );
......
...@@ -1660,13 +1660,6 @@ void SortedIndividualInt32List::InsertHolidayList( ...@@ -1660,13 +1660,6 @@ void SortedIndividualInt32List::InsertHolidayList(
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
ScaDoubleList::~ScaDoubleList()
{
for( double* pDbl = const_cast< double* >( First() ); pDbl; pDbl = const_cast< double* >( Next() ) )
delete pDbl;
}
void ScaDoubleList::Append( void ScaDoubleList::Append(
const uno::Sequence< uno::Sequence< double > >& rValueSeq ) throw( uno::RuntimeException, lang::IllegalArgumentException ) const uno::Sequence< uno::Sequence< double > >& rValueSeq ) throw( uno::RuntimeException, lang::IllegalArgumentException )
{ {
......
...@@ -331,12 +331,13 @@ public: ...@@ -331,12 +331,13 @@ public:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
class ScaDoubleList : protected MyList class ScaDoubleList
{ {
private:
std::vector<double> maVector;
protected: protected:
inline void ListAppend( double fValue ) { MyList::Append( new double( fValue ) ); } inline void ListAppend( double fValue ) { maVector.push_back(fValue); }
using MyList::Append;
inline void Append( double fValue ) throw( css::uno::RuntimeException, css::lang::IllegalArgumentException ) inline void Append( double fValue ) throw( css::uno::RuntimeException, css::lang::IllegalArgumentException )
{ if( CheckInsert( fValue ) ) ListAppend( fValue ); } { if( CheckInsert( fValue ) ) ListAppend( fValue ); }
...@@ -362,14 +363,12 @@ protected: ...@@ -362,14 +363,12 @@ protected:
sal_Bool bIgnoreEmpty ) throw( css::uno::RuntimeException, css::lang::IllegalArgumentException ); sal_Bool bIgnoreEmpty ) throw( css::uno::RuntimeException, css::lang::IllegalArgumentException );
public: public:
virtual ~ScaDoubleList(); virtual ~ScaDoubleList() {}
using MyList::Count;
inline const double* Get( sal_uInt32 nIndex ) const
{ return static_cast< const double* >( MyList::GetObject( nIndex ) ); }
inline const double* First() { return static_cast< const double* >( MyList::First() ); } inline sal_uInt32 Count() const
inline const double* Next() { return static_cast< const double* >( MyList::Next() ); } { return maVector.size(); }
inline double Get( sal_uInt32 n ) const
{ return maVector[n]; }
void Append( const css::uno::Sequence< css::uno::Sequence< double > >& rValueArr ) void Append( const css::uno::Sequence< css::uno::Sequence< double > >& rValueArr )
throw( css::uno::RuntimeException, css::lang::IllegalArgumentException ); throw( css::uno::RuntimeException, css::lang::IllegalArgumentException );
......
...@@ -461,8 +461,8 @@ double SAL_CALL AnalysisAddIn::getOddlyield( const css::uno::Reference< css::bea ...@@ -461,8 +461,8 @@ double SAL_CALL AnalysisAddIn::getOddlyield( const css::uno::Reference< css::bea
// ============================================================================ // ============================================================================
// XIRR helper functions // XIRR helper functions
#define V_(i) (*rValues.Get(i)) #define V_(i) (rValues.Get(i))
#define D_(i) (*rDates.Get(i)) #define D_(i) (rDates.Get(i))
/** Calculates the resulting amount for the passed interest rate and the given XIRR parameters. */ /** Calculates the resulting amount for the passed interest rate and the given XIRR parameters. */
static double lcl_sca_XirrResult( const ScaDoubleList& rValues, const ScaDoubleList& rDates, double fRate ) static double lcl_sca_XirrResult( const ScaDoubleList& rValues, const ScaDoubleList& rDates, double fRate )
...@@ -579,11 +579,11 @@ double SAL_CALL AnalysisAddIn::getXnpv( ...@@ -579,11 +579,11 @@ double SAL_CALL AnalysisAddIn::getXnpv(
throw css::lang::IllegalArgumentException(); throw css::lang::IllegalArgumentException();
double fRet = 0.0; double fRet = 0.0;
double fNull = *aDateList.Get( 0 ); double fNull = aDateList.Get( 0 );
fRate++; fRate++;
for( sal_Int32 i = 0 ; i < nNum ; i++ ) for( sal_Int32 i = 0 ; i < nNum ; i++ )
fRet += *aValList.Get( i ) / ( pow( fRate, ( *aDateList.Get( i ) - fNull ) / 365.0 ) ); fRet += aValList.Get( i ) / ( pow( fRate, ( aDateList.Get( i ) - fNull ) / 365.0 ) );
RETURN_FINITE( fRet ); RETURN_FINITE( fRet );
} }
...@@ -654,8 +654,8 @@ double SAL_CALL AnalysisAddIn::getFvschedule( double fPrinc, const css::uno::Seq ...@@ -654,8 +654,8 @@ double SAL_CALL AnalysisAddIn::getFvschedule( double fPrinc, const css::uno::Seq
aSchedList.Append( rSchedule ); aSchedList.Append( rSchedule );
for( const double* p = aSchedList.First() ; p ; p = aSchedList.Next() ) for( sal_uInt32 i = 0; i < aSchedList.Count(); ++i )
fPrinc *= 1.0 + *p; fPrinc *= 1.0 + aSchedList.Get(i);
RETURN_FINITE( fPrinc ); RETURN_FINITE( fPrinc );
} }
......
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