diff options
author | Kohei Yoshida <kohei.yoshida@collabora.com> | 2014-11-15 22:34:15 -0500 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@gmail.com> | 2014-11-17 16:37:33 -0500 |
commit | 0348341f5ef8b92ed26451e90e42355bdf83e2f3 (patch) | |
tree | edf02709cef1792d9724aabd8180d83a8006db61 /tools | |
parent | 07a086feaf6d045849cc6474ffe95f61b9021fa1 (diff) |
Make these methods non-inline.
Change-Id: I0b24e34dec6c452659b224b45a6849dafe708c3b
Diffstat (limited to 'tools')
-rw-r--r-- | tools/source/generic/fract.cxx | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/tools/source/generic/fract.cxx b/tools/source/generic/fract.cxx index 020d894423ba..e9e2f5fec44f 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 ) { |