connectivity/source/drivers/ado/Aolevariant.cxx | 1 include/tools/fract.hxx | 129 ++--------- sal/osl/w32/path_helper.h | 1 tools/source/generic/fract.cxx | 270 ++++++++++++++++++------ 4 files changed, 230 insertions(+), 171 deletions(-)
New commits: commit 5fffe5e5ece8ab130c9024bd1f04f1d08a8e01c2 Author: Kohei Yoshida <kohei.yosh...@collabora.com> Date: Mon Nov 17 16:19:28 2014 -0500 Build fix on Windows Change-Id: I5c24856bfe48646bc0e9cd00f0849a5db12dfef2 diff --git a/connectivity/source/drivers/ado/Aolevariant.cxx b/connectivity/source/drivers/ado/Aolevariant.cxx index bcb0c62..5a1962b 100644 --- a/connectivity/source/drivers/ado/Aolevariant.cxx +++ b/connectivity/source/drivers/ado/Aolevariant.cxx @@ -19,6 +19,7 @@ #include "ado/Aolevariant.hxx" #include <connectivity/dbconversion.hxx> +#include <osl/diagnose.h> #include <com/sun/star/sdbc/SQLException.hpp> #include <com/sun/star/util/Time.hpp> #include <com/sun/star/util/Date.hpp> commit 2cd24526e7e806b279b5d85f89a932393b65bd0a Author: Kohei Yoshida <kohei.yosh...@collabora.com> Date: Mon Nov 17 10:01:31 2014 -0500 Build fix. Change-Id: Ifa6775384993900980c93df88162143aa7ac0a08 diff --git a/sal/osl/w32/path_helper.h b/sal/osl/w32/path_helper.h index 056a1ca..7da985b 100644 --- a/sal/osl/w32/path_helper.h +++ b/sal/osl/w32/path_helper.h @@ -23,6 +23,7 @@ #include <sal/types.h> #include <rtl/ustring.h> #include <osl/file.h> +#include <osl/diagnose.h> #ifdef __cplusplus extern "C" commit 2dff8ff29583526920e017fc86b5e2a51b4d6c30 Author: Kohei Yoshida <kohei.yosh...@collabora.com> Date: Mon Nov 17 09:37:03 2014 -0500 Build fix on Linux. Change-Id: Iea96991a3bef08c17a8a0cbc347408dadc0061af diff --git a/tools/source/generic/fract.cxx b/tools/source/generic/fract.cxx index 7f7ab6f..2c48502 100644 --- a/tools/source/generic/fract.cxx +++ b/tools/source/generic/fract.cxx @@ -22,6 +22,7 @@ #include <tools/lineend.hxx> #include <tools/stream.hxx> #include <rtl/ustring.hxx> +#include <osl/diagnose.h> #include <limits.h> #include <algorithm> commit 6d7282fa8a2c6075ae838aaababe47a1e6513d74 Author: Kohei Yoshida <kohei.yosh...@collabora.com> Date: Mon Nov 17 08:35:01 2014 -0500 Apply pimpl to Fraction. Change-Id: I60eb597a6374b807b2264af6d5841a42e9b1c0f3 diff --git a/include/tools/fract.hxx b/include/tools/fract.hxx index 597876f..93663ac 100644 --- a/include/tools/fract.hxx +++ b/include/tools/fract.hxx @@ -19,8 +19,7 @@ #ifndef INCLUDED_TOOLS_FRACT_HXX #define INCLUDED_TOOLS_FRACT_HXX -#include <boost/rational.hpp> -#include <sal/log.hxx> +#include <sal/types.h> #include <tools/toolsdllapi.h> class SvStream; @@ -29,17 +28,18 @@ class SvStream; // calculations using sal_Int64 with checks for 'long' overflows. class TOOLS_DLLPUBLIC SAL_WARN_UNUSED Fraction { -private: - bool valid; - boost::rational<sal_Int64> value; + struct Impl; + + Impl* mpImpl; bool HasOverflowValue(); public: - Fraction() { valid = true; } + Fraction(); Fraction( const Fraction & rFrac ); Fraction( long nNum, long nDen=1 ); Fraction( double dVal ); + ~Fraction(); bool IsValid() const; diff --git a/tools/source/generic/fract.cxx b/tools/source/generic/fract.cxx index e9e2f5f..7f7ab6f 100644 --- a/tools/source/generic/fract.cxx +++ b/tools/source/generic/fract.cxx @@ -17,16 +17,18 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#include <algorithm> -#include <cmath> - -#include <limits.h> -#include <rtl/ustring.hxx> -#include <osl/diagnose.h> -#include <tools/debug.hxx> #include <tools/fract.hxx> +#include <tools/debug.hxx> #include <tools/lineend.hxx> #include <tools/stream.hxx> +#include <rtl/ustring.hxx> + +#include <limits.h> +#include <algorithm> +#include <cmath> + +#include <boost/rational.hpp> +#include <boost/noncopyable.hpp> template<typename T> static boost::rational<T> rational_FromDouble(double dVal); @@ -34,51 +36,79 @@ static boost::rational<T> rational_FromDouble(double dVal); template<typename T> static void rational_ReduceInaccurate(boost::rational<T>& rRational, unsigned nSignificantBits); +struct Fraction::Impl : boost::noncopyable +{ + bool valid; + boost::rational<sal_Int64> value; +}; + +Fraction::Fraction() : mpImpl(new Impl) +{ + mpImpl->valid = true; +} + +Fraction::Fraction( const Fraction& rFrac ) : mpImpl(new Impl) +{ + mpImpl->valid = rFrac.mpImpl->valid; + if (mpImpl->valid) + mpImpl->value.assign( rFrac.mpImpl->value.numerator(), rFrac.mpImpl->value.denominator() ); +} + // Initialized by setting nNum as nominator and nDen as denominator // Negative values in the denominator are invalid and cause the // inversion of both nominator and denominator signs // in order to return the correct value. -Fraction::Fraction( long nNum, long nDen ) +Fraction::Fraction( long nNum, long nDen ) : mpImpl(new Impl) { - if ( nDen == 0 ) { - valid = false; + if ( nDen == 0 ) + { + mpImpl->valid = false; SAL_WARN( "tools.fraction", "'Fraction(" << nNum << ",0)' invalid fraction created" ); return; } - value.assign( nNum, nDen); - valid = true; + mpImpl->value.assign( nNum, nDen); + mpImpl->valid = true; } -Fraction::Fraction( double dVal ) +Fraction::Fraction( double dVal ) : mpImpl(new Impl) { - try { - value = rational_FromDouble<sal_Int64>( dVal ); + try + { + mpImpl->value = rational_FromDouble<sal_Int64>( dVal ); if ( HasOverflowValue() ) throw boost::bad_rational(); - valid = true; - } catch(const boost::bad_rational&) { - valid = false; + mpImpl->valid = true; + } + catch (const boost::bad_rational&) + { + mpImpl->valid = false; SAL_WARN( "tools.fraction", "'Fraction(" << dVal << ")' invalid fraction created" ); } } +Fraction::~Fraction() +{ + delete mpImpl; +} + bool Fraction::HasOverflowValue() { //coverity[result_independent_of_operands] - return value.numerator() < std::numeric_limits<long>::min() || - value.numerator() > std::numeric_limits<long>::max() || - value.denominator() < std::numeric_limits<long>::min() || - value.denominator() > std::numeric_limits<long>::max(); + return mpImpl->value.numerator() < std::numeric_limits<long>::min() || + mpImpl->value.numerator() > std::numeric_limits<long>::max() || + mpImpl->value.denominator() < std::numeric_limits<long>::min() || + mpImpl->value.denominator() > std::numeric_limits<long>::max(); } Fraction::operator double() const { - if ( !valid ) { + if (!mpImpl->valid) + { SAL_WARN( "tools.fraction", "'double()' on invalid fraction" ); return 0.0; } - return boost::rational_cast<double>(value); + return boost::rational_cast<double>(mpImpl->value); } // This methods first validates both values. @@ -87,17 +117,20 @@ Fraction::operator double() const // which cause the operation to be marked as invalid Fraction& Fraction::operator += ( const Fraction& rVal ) { - if ( !rVal.valid ) - valid = false; - if ( !valid ) { + if ( !rVal.mpImpl->valid ) + mpImpl->valid = false; + + if ( !mpImpl->valid ) + { SAL_WARN( "tools.fraction", "'operator +=' with invalid fraction" ); return *this; } - value += rVal.value; + mpImpl->value += rVal.mpImpl->value; - if ( HasOverflowValue() ) { - valid = false; + if ( HasOverflowValue() ) + { + mpImpl->valid = false; SAL_WARN( "tools.fraction", "'operator +=' detected overflow" ); } @@ -106,17 +139,20 @@ Fraction& Fraction::operator += ( const Fraction& rVal ) Fraction& Fraction::operator -= ( const Fraction& rVal ) { - if ( !rVal.valid ) - valid = false; - if ( !valid ) { + if ( !rVal.mpImpl->valid ) + mpImpl->valid = false; + + if ( !mpImpl->valid ) + { SAL_WARN( "tools.fraction", "'operator -=' with invalid fraction" ); return *this; } - value -= rVal.value; + mpImpl->value -= rVal.mpImpl->value; - if ( HasOverflowValue() ) { - valid = false; + if ( HasOverflowValue() ) + { + mpImpl->valid = false; SAL_WARN( "tools.fraction", "'operator -=' detected overflow" ); } @@ -125,17 +161,20 @@ Fraction& Fraction::operator -= ( const Fraction& rVal ) Fraction& Fraction::operator *= ( const Fraction& rVal ) { - if ( !rVal.valid ) - valid = false; - if ( !valid ) { + if ( !rVal.mpImpl->valid ) + mpImpl->valid = false; + + if ( !mpImpl->valid ) + { SAL_WARN( "tools.fraction", "'operator *=' with invalid fraction" ); return *this; } - value *= rVal.value; + mpImpl->value *= rVal.mpImpl->value; - if ( HasOverflowValue() ) { - valid = false; + if ( HasOverflowValue() ) + { + mpImpl->valid = false; SAL_WARN( "tools.fraction", "'operator *=' detected overflow" ); } @@ -144,17 +183,20 @@ Fraction& Fraction::operator *= ( const Fraction& rVal ) Fraction& Fraction::operator /= ( const Fraction& rVal ) { - if ( !rVal.valid ) - valid = false; - if ( !valid ) { + if ( !rVal.mpImpl->valid ) + mpImpl->valid = false; + + if ( !mpImpl->valid ) + { SAL_WARN( "tools.fraction", "'operator /=' with invalid fraction" ); return *this; } - value /= rVal.value; + mpImpl->value /= rVal.mpImpl->value; - if ( HasOverflowValue() ) { - valid = false; + if ( HasOverflowValue() ) + { + mpImpl->valid = false; SAL_WARN( "tools.fraction", "'operator /=' detected overflow" ); } @@ -181,62 +223,61 @@ Fraction& Fraction::operator /= ( const Fraction& rVal ) */ void Fraction::ReduceInaccurate( unsigned nSignificantBits ) { - if ( !valid ) { + if ( !mpImpl->valid ) + { SAL_WARN( "tools.fraction", "'ReduceInaccurate' on invalid fraction" ); return; } - if ( !value.numerator() ) - return; - rational_ReduceInaccurate(value, nSignificantBits); -} + if ( !mpImpl->value.numerator() ) + return; -Fraction::Fraction( const Fraction& rFrac ) -{ - valid = rFrac.valid; - if ( valid ) - value.assign( rFrac.value.numerator(), rFrac.value.denominator() ); + rational_ReduceInaccurate(mpImpl->value, nSignificantBits); } long Fraction::GetNumerator() const { - if ( !valid ) { + if ( !mpImpl->valid ) + { SAL_WARN( "tools.fraction", "'GetNumerator()' on invalid fraction" ); return 0; } - return value.numerator(); + return mpImpl->value.numerator(); } -long Fraction::GetDenominator() const { - if ( !valid ) { +long Fraction::GetDenominator() const +{ + if ( !mpImpl->valid ) + { SAL_WARN( "tools.fraction", "'GetDenominator()' on invalid fraction" ); return -1; } - return value.denominator(); + return mpImpl->value.denominator(); } Fraction& Fraction::operator=( const Fraction& rFrac ) { - if ( this != &rFrac ) { - valid = rFrac.valid; - if ( valid ) - value.assign( rFrac.value.numerator(), rFrac.value.denominator() ); - } + if (this == &rFrac) + return *this; + + Fraction tmp(rFrac); + std::swap(mpImpl, tmp.mpImpl); return *this; } bool Fraction::IsValid() const { - return valid; + return mpImpl->valid; } Fraction::operator long() const { - if ( !valid ) { + if ( !mpImpl->valid ) + { SAL_WARN( "tools.fraction", "'operator long()' on invalid fraction" ); return 0; } - return boost::rational_cast<long>(value); + return boost::rational_cast<long>(mpImpl->value); } Fraction operator+( const Fraction& rVal1, const Fraction& rVal2 ) @@ -284,32 +325,35 @@ bool operator >=( const Fraction& rVal1, const Fraction& rVal2 ) bool operator == ( const Fraction& rVal1, const Fraction& rVal2 ) { - if ( !rVal1.valid || !rVal2.valid ) { + if ( !rVal1.mpImpl->valid || !rVal2.mpImpl->valid ) + { SAL_WARN( "tools.fraction", "'operator ==' with an invalid fraction" ); return false; } - return rVal1.value == rVal2.value; + return rVal1.mpImpl->value == rVal2.mpImpl->value; } bool operator < ( const Fraction& rVal1, const Fraction& rVal2 ) { - if ( !rVal1.valid || !rVal2.valid ) { + if ( !rVal1.mpImpl->valid || !rVal2.mpImpl->valid ) + { SAL_WARN( "tools.fraction", "'operator <' with an invalid fraction" ); return false; } - return rVal1.value < rVal2.value; + return rVal1.mpImpl->value < rVal2.mpImpl->value; } bool operator > ( const Fraction& rVal1, const Fraction& rVal2 ) { - if ( !rVal1.valid || !rVal2.valid ) { + if ( !rVal1.mpImpl->valid || !rVal2.mpImpl->valid ) + { SAL_WARN( "tools.fraction", "'operator >' with an invalid fraction" ); return false; } - return rVal1.value > rVal2.value; + return rVal1.mpImpl->value > rVal2.mpImpl->value; } SvStream& ReadFraction( SvStream& rIStream, Fraction& rFract ) @@ -317,25 +361,29 @@ SvStream& ReadFraction( SvStream& rIStream, Fraction& rFract ) sal_Int32 num(0), den(0); rIStream.ReadInt32( num ); rIStream.ReadInt32( den ); - if ( den <= 0 ) { + if ( den <= 0 ) + { SAL_WARN( "tools.fraction", "'ReadFraction()' read an invalid fraction" ); - rFract.valid = false; - } else { - rFract.value.assign( num, den ); - rFract.valid = true; + rFract.mpImpl->valid = false; + } + else + { + rFract.mpImpl->value.assign( num, den ); + rFract.mpImpl->valid = true; } return rIStream; } SvStream& WriteFraction( SvStream& rOStream, const Fraction& rFract ) { - if ( !rFract.valid ) { + if ( !rFract.mpImpl->valid ) + { SAL_WARN( "tools.fraction", "'WriteFraction()' write an invalid fraction" ); rOStream.WriteInt32( 0 ); rOStream.WriteInt32( -1 ); } else { - rOStream.WriteInt32( rFract.value.numerator() ); - rOStream.WriteInt32( rFract.value.denominator() ); + rOStream.WriteInt32( rFract.mpImpl->value.numerator() ); + rOStream.WriteInt32( rFract.mpImpl->value.denominator() ); } return rOStream; } commit 0348341f5ef8b92ed26451e90e42355bdf83e2f3 Author: Kohei Yoshida <kohei.yosh...@collabora.com> Date: Sat Nov 15 22:34:15 2014 -0500 Make these methods non-inline. Change-Id: I0b24e34dec6c452659b224b45a6849dafe708c3b diff --git a/include/tools/fract.hxx b/include/tools/fract.hxx index 0e81155..597876f 100644 --- a/include/tools/fract.hxx +++ b/include/tools/fract.hxx @@ -58,112 +58,29 @@ public: void ReduceInaccurate( unsigned nSignificantBits ); - friend inline Fraction operator+( const Fraction& rVal1, const Fraction& rVal2 ); - friend inline Fraction operator-( const Fraction& rVal1, const Fraction& rVal2 ); - friend inline Fraction operator*( const Fraction& rVal1, const Fraction& rVal2 ); - friend inline Fraction operator/( const Fraction& rVal1, const Fraction& rVal2 ); - - TOOLS_DLLPUBLIC friend bool operator==( const Fraction& rVal1, const Fraction& rVal2 ); - friend inline bool operator!=( const Fraction& rVal1, const Fraction& rVal2 ); - TOOLS_DLLPUBLIC friend bool operator< ( const Fraction& rVal1, const Fraction& rVal2 ); - TOOLS_DLLPUBLIC friend bool operator> ( const Fraction& rVal1, const Fraction& rVal2 ); - friend inline bool operator<=( const Fraction& rVal1, const Fraction& rVal2 ); - friend inline bool operator>=( const Fraction& rVal1, const Fraction& rVal2 ); + TOOLS_DLLPUBLIC friend Fraction operator+( const Fraction& rVal1, const Fraction& rVal2 ); + TOOLS_DLLPUBLIC friend Fraction operator-( const Fraction& rVal1, const Fraction& rVal2 ); + TOOLS_DLLPUBLIC friend Fraction operator*( const Fraction& rVal1, const Fraction& rVal2 ); + TOOLS_DLLPUBLIC friend Fraction operator/( const Fraction& rVal1, const Fraction& rVal2 ); + + TOOLS_DLLPUBLIC friend bool operator==( const Fraction& rVal1, const Fraction& rVal2 ); + TOOLS_DLLPUBLIC friend bool operator!=( const Fraction& rVal1, const Fraction& rVal2 ); + TOOLS_DLLPUBLIC friend bool operator< ( const Fraction& rVal1, const Fraction& rVal2 ); + TOOLS_DLLPUBLIC friend bool operator> ( const Fraction& rVal1, const Fraction& rVal2 ); + TOOLS_DLLPUBLIC friend bool operator<=( const Fraction& rVal1, const Fraction& rVal2 ); + TOOLS_DLLPUBLIC friend bool operator>=( const Fraction& rVal1, const Fraction& rVal2 ); TOOLS_DLLPUBLIC friend SvStream& ReadFraction( SvStream& rIStream, Fraction& rFract ); TOOLS_DLLPUBLIC friend SvStream& WriteFraction( SvStream& rOStream, const Fraction& rFract ); }; -inline Fraction::Fraction( const Fraction& rFrac ) -{ - valid = rFrac.valid; - if ( valid ) - value.assign( rFrac.value.numerator(), rFrac.value.denominator() ); -} - -inline long Fraction::GetNumerator() const -{ - if ( !valid ) { - SAL_WARN( "tools.fraction", "'GetNumerator()' on invalid fraction" ); - return 0; - } - return value.numerator(); -} - -inline long Fraction::GetDenominator() const { - if ( !valid ) { - SAL_WARN( "tools.fraction", "'GetDenominator()' on invalid fraction" ); - return -1; - } - return value.denominator(); -} - -inline Fraction& Fraction::operator=( const Fraction& rFrac ) -{ - if ( this != &rFrac ) { - valid = rFrac.valid; - if ( valid ) - value.assign( rFrac.value.numerator(), rFrac.value.denominator() ); - } - return *this; -} - -inline bool Fraction::IsValid() const -{ - return valid; -} - -inline Fraction::operator long() const -{ - if ( !valid ) { - SAL_WARN( "tools.fraction", "'operator long()' on invalid fraction" ); - return 0; - } - return boost::rational_cast<long>(value); -} - -inline Fraction operator+( const Fraction& rVal1, const Fraction& rVal2 ) -{ - Fraction aErg( rVal1 ); - aErg += rVal2; - return aErg; -} - -inline Fraction operator-( const Fraction& rVal1, const Fraction& rVal2 ) -{ - Fraction aErg( rVal1 ); - aErg -= rVal2; - return aErg; -} - -inline Fraction operator*( const Fraction& rVal1, const Fraction& rVal2 ) -{ - Fraction aErg( rVal1 ); - aErg *= rVal2; - return aErg; -} - -inline Fraction operator/( const Fraction& rVal1, const Fraction& rVal2 ) -{ - Fraction aErg( rVal1 ); - aErg /= rVal2; - return aErg; -} - -inline bool operator !=( const Fraction& rVal1, const Fraction& rVal2 ) -{ - return !(rVal1 == rVal2); -} - -inline bool operator <=( const Fraction& rVal1, const Fraction& rVal2 ) -{ - return !(rVal1 > rVal2); -} - -inline bool operator >=( const Fraction& rVal1, const Fraction& rVal2 ) -{ - return !(rVal1 < rVal2); -} +TOOLS_DLLPUBLIC Fraction operator+( const Fraction& rVal1, const Fraction& rVal2 ); +TOOLS_DLLPUBLIC Fraction operator-( const Fraction& rVal1, const Fraction& rVal2 ); +TOOLS_DLLPUBLIC Fraction operator*( const Fraction& rVal1, const Fraction& rVal2 ); +TOOLS_DLLPUBLIC Fraction operator/( const Fraction& rVal1, const Fraction& rVal2 ); +TOOLS_DLLPUBLIC bool operator !=( const Fraction& rVal1, const Fraction& rVal2 ); +TOOLS_DLLPUBLIC bool operator <=( const Fraction& rVal1, const Fraction& rVal2 ); +TOOLS_DLLPUBLIC bool operator >=( const Fraction& rVal1, const Fraction& rVal2 ); #endif diff --git a/tools/source/generic/fract.cxx b/tools/source/generic/fract.cxx index 020d894..e9e2f5f 100644 --- a/tools/source/generic/fract.cxx +++ b/tools/source/generic/fract.cxx @@ -191,6 +191,97 @@ void Fraction::ReduceInaccurate( unsigned nSignificantBits ) rational_ReduceInaccurate(value, nSignificantBits); } +Fraction::Fraction( const Fraction& rFrac ) +{ + valid = rFrac.valid; + if ( valid ) + value.assign( rFrac.value.numerator(), rFrac.value.denominator() ); +} + +long Fraction::GetNumerator() const +{ + if ( !valid ) { + SAL_WARN( "tools.fraction", "'GetNumerator()' on invalid fraction" ); + return 0; + } + return value.numerator(); +} + +long Fraction::GetDenominator() const { + if ( !valid ) { + SAL_WARN( "tools.fraction", "'GetDenominator()' on invalid fraction" ); + return -1; + } + return value.denominator(); +} + +Fraction& Fraction::operator=( const Fraction& rFrac ) +{ + if ( this != &rFrac ) { + valid = rFrac.valid; + if ( valid ) + value.assign( rFrac.value.numerator(), rFrac.value.denominator() ); + } + return *this; +} + +bool Fraction::IsValid() const +{ + return valid; +} + +Fraction::operator long() const +{ + if ( !valid ) { + SAL_WARN( "tools.fraction", "'operator long()' on invalid fraction" ); + return 0; + } + return boost::rational_cast<long>(value); +} + +Fraction operator+( const Fraction& rVal1, const Fraction& rVal2 ) +{ + Fraction aErg( rVal1 ); + aErg += rVal2; + return aErg; +} + +Fraction operator-( const Fraction& rVal1, const Fraction& rVal2 ) +{ + Fraction aErg( rVal1 ); + aErg -= rVal2; + return aErg; +} + +Fraction operator*( const Fraction& rVal1, const Fraction& rVal2 ) +{ + Fraction aErg( rVal1 ); + aErg *= rVal2; + return aErg; +} + +Fraction operator/( const Fraction& rVal1, const Fraction& rVal2 ) +{ + Fraction aErg( rVal1 ); + aErg /= rVal2; + return aErg; +} + +bool operator !=( const Fraction& rVal1, const Fraction& rVal2 ) +{ + return !(rVal1 == rVal2); +} + +bool operator <=( const Fraction& rVal1, const Fraction& rVal2 ) +{ + return !(rVal1 > rVal2); +} + +bool operator >=( const Fraction& rVal1, const Fraction& rVal2 ) +{ + return !(rVal1 < rVal2); +} + bool operator == ( const Fraction& rVal1, const Fraction& rVal2 ) { if ( !rVal1.valid || !rVal2.valid ) { _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits