Branch libreoffice-5-0-4
[LibreOffice.git] / include / tools / fract.hxx
blob93663aca8ad221ee2bd7146045751d5dc1b926b7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #ifndef INCLUDED_TOOLS_FRACT_HXX
20 #define INCLUDED_TOOLS_FRACT_HXX
22 #include <sal/types.h>
23 #include <tools/toolsdllapi.h>
25 class SvStream;
27 // This class uses the platform defined type 'long' as valid values but do all
28 // calculations using sal_Int64 with checks for 'long' overflows.
29 class TOOLS_DLLPUBLIC SAL_WARN_UNUSED Fraction
31 struct Impl;
33 Impl* mpImpl;
35 bool HasOverflowValue();
37 public:
38 Fraction();
39 Fraction( const Fraction & rFrac );
40 Fraction( long nNum, long nDen=1 );
41 Fraction( double dVal );
42 ~Fraction();
44 bool IsValid() const;
46 long GetNumerator() const;
47 long GetDenominator() const;
49 operator long() const;
50 operator double() const;
52 Fraction& operator=( const Fraction& rfrFrac );
54 Fraction& operator+=( const Fraction& rfrFrac );
55 Fraction& operator-=( const Fraction& rfrFrac );
56 Fraction& operator*=( const Fraction& rfrFrac );
57 Fraction& operator/=( const Fraction& rfrFrac );
59 void ReduceInaccurate( unsigned nSignificantBits );
61 TOOLS_DLLPUBLIC friend Fraction operator+( const Fraction& rVal1, const Fraction& rVal2 );
62 TOOLS_DLLPUBLIC friend Fraction operator-( const Fraction& rVal1, const Fraction& rVal2 );
63 TOOLS_DLLPUBLIC friend Fraction operator*( const Fraction& rVal1, const Fraction& rVal2 );
64 TOOLS_DLLPUBLIC friend Fraction operator/( const Fraction& rVal1, const Fraction& rVal2 );
66 TOOLS_DLLPUBLIC friend bool operator==( const Fraction& rVal1, const Fraction& rVal2 );
67 TOOLS_DLLPUBLIC friend bool operator!=( const Fraction& rVal1, const Fraction& rVal2 );
68 TOOLS_DLLPUBLIC friend bool operator< ( const Fraction& rVal1, const Fraction& rVal2 );
69 TOOLS_DLLPUBLIC friend bool operator> ( const Fraction& rVal1, const Fraction& rVal2 );
70 TOOLS_DLLPUBLIC friend bool operator<=( const Fraction& rVal1, const Fraction& rVal2 );
71 TOOLS_DLLPUBLIC friend bool operator>=( const Fraction& rVal1, const Fraction& rVal2 );
73 TOOLS_DLLPUBLIC friend SvStream& ReadFraction( SvStream& rIStream, Fraction& rFract );
74 TOOLS_DLLPUBLIC friend SvStream& WriteFraction( SvStream& rOStream, const Fraction& rFract );
77 TOOLS_DLLPUBLIC Fraction operator+( const Fraction& rVal1, const Fraction& rVal2 );
78 TOOLS_DLLPUBLIC Fraction operator-( const Fraction& rVal1, const Fraction& rVal2 );
79 TOOLS_DLLPUBLIC Fraction operator*( const Fraction& rVal1, const Fraction& rVal2 );
80 TOOLS_DLLPUBLIC Fraction operator/( const Fraction& rVal1, const Fraction& rVal2 );
81 TOOLS_DLLPUBLIC bool operator !=( const Fraction& rVal1, const Fraction& rVal2 );
82 TOOLS_DLLPUBLIC bool operator <=( const Fraction& rVal1, const Fraction& rVal2 );
83 TOOLS_DLLPUBLIC bool operator >=( const Fraction& rVal1, const Fraction& rVal2 );
85 #endif
87 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */