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
double nZ = 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 )
throw lang::IllegalArgumentException();
......@@ -787,15 +788,10 @@ double SAL_CALL AnalysisAddIn::getGcd( const uno::Reference< beans::XPropertySet
if( aValList.Count() == 0 )
return 0.0;
const double* p = aValList.First();
double f = *p;
p = aValList.Next();
while( p )
double f = aValList.Get(0);
for( sal_uInt32 i = 1; i < aValList.Count(); ++i )
{
f = GetGcd( *p, f );
p = aValList.Next();
f = GetGcd( aValList.Get(i), f );
}
RETURN_FINITE( f );
......@@ -812,22 +808,18 @@ double SAL_CALL AnalysisAddIn::getLcm( const uno::Reference< beans::XPropertySet
if( aValList.Count() == 0 )
return 0.0;
const double* p = aValList.First();
double f = *p;
double f = aValList.Get(0);
if( f == 0.0 )
return f;
p = aValList.Next();
while( p )
for( sal_uInt32 i = 1; i < aValList.Count(); ++i )
{
double fTmp = *p;
double fTmp = aValList.Get(i);
if( f == 0.0 )
return f;
else
f = fTmp * f / GetGcd( fTmp, f );
p = aValList.Next();
}
RETURN_FINITE( f );
......
......@@ -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(
const uno::Sequence< uno::Sequence< double > >& rValueSeq ) throw( uno::RuntimeException, lang::IllegalArgumentException )
{
......
......@@ -331,12 +331,13 @@ public:
//-----------------------------------------------------------------------------
class ScaDoubleList : protected MyList
class ScaDoubleList
{
private:
std::vector<double> maVector;
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 )
{ if( CheckInsert( fValue ) ) ListAppend( fValue ); }
......@@ -362,14 +363,12 @@ protected:
sal_Bool bIgnoreEmpty ) throw( css::uno::RuntimeException, css::lang::IllegalArgumentException );
public:
virtual ~ScaDoubleList();
using MyList::Count;
inline const double* Get( sal_uInt32 nIndex ) const
{ return static_cast< const double* >( MyList::GetObject( nIndex ) ); }
virtual ~ScaDoubleList() {}
inline const double* First() { return static_cast< const double* >( MyList::First() ); }
inline const double* Next() { return static_cast< const double* >( MyList::Next() ); }
inline sal_uInt32 Count() const
{ return maVector.size(); }
inline double Get( sal_uInt32 n ) const
{ return maVector[n]; }
void Append( const css::uno::Sequence< css::uno::Sequence< double > >& rValueArr )
throw( css::uno::RuntimeException, css::lang::IllegalArgumentException );
......
......@@ -461,8 +461,8 @@ double SAL_CALL AnalysisAddIn::getOddlyield( const css::uno::Reference< css::bea
// ============================================================================
// XIRR helper functions
#define V_(i) (*rValues.Get(i))
#define D_(i) (*rDates.Get(i))
#define V_(i) (rValues.Get(i))
#define D_(i) (rDates.Get(i))
/** 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 )
......@@ -579,11 +579,11 @@ double SAL_CALL AnalysisAddIn::getXnpv(
throw css::lang::IllegalArgumentException();
double fRet = 0.0;
double fNull = *aDateList.Get( 0 );
double fNull = aDateList.Get( 0 );
fRate++;
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 );
}
......@@ -654,8 +654,8 @@ double SAL_CALL AnalysisAddIn::getFvschedule( double fPrinc, const css::uno::Seq
aSchedList.Append( rSchedule );
for( const double* p = aSchedList.First() ; p ; p = aSchedList.Next() )
fPrinc *= 1.0 + *p;
for( sal_uInt32 i = 0; i < aSchedList.Count(); ++i )
fPrinc *= 1.0 + aSchedList.Get(i);
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