// $Source: /usr/local/SimSoft/SoftShop/XMath/Fraction/Fraction.h,v $
// $Revision: 1.2 $
// $Author: baum $
// $Date: 2001/11/29 15:52:25 $
//
// Login name of the user who locked the revision
// $Locker:  $
// Tag name used to checkout the file
// $Name: Release-20 $
// State assigned to revision
// $State: Exp $
//
//
// $Log: Fraction.h,v $
// Revision 1.2  2001/11/29 15:52:25  baum
// -In Kalender.cpp und Kalender.h Handsteuerung eingebaut
//

#ifndef _FRACTION_H
#define _FRACTION_H 1

#include <stdlib.h>
#include <iostream.h>

#ifdef _FRACTION_CPP
#  undef _impexp
#  define _impexp __declspec(dllexport)
#elif defined BUILD_XMATH_DLL
#  undef _impexp
#  define _impexp
#else
#  undef _impexp
#  define _impexp __declspec(dllimport)
#endif

#if defined __GNUG__ || defined __hpux
#  undef _impexp
#  define _impexp
#endif

//==================================================================
//		Class-Header
//		for class Fraction
//==================================================================

class _impexp Fraction {

  public:
    // default-constructor
    Fraction (int numerator = 0, int denominator = 1);

    // copy-konstructor
    Fraction (const Fraction& f);

    // destructor
    virtual ~Fraction ();

    // assignement-operator
    Fraction& operator = (const Fraction& f);

    // comparison-operator
    bool operator == (const Fraction&) const;
    bool operator != (const Fraction&) const;
    bool operator <  (const Fraction&) const;
    bool operator <= (const Fraction&) const;
    bool operator >  (const Fraction&) const;
    bool operator >= (const Fraction&) const;

    // NOT and VOID*-operator
    bool operator ! () const;
    operator void* () const;
    
    // arithmatic-operators
    Fraction  operator -  () const;

    Fraction  operator +  (const Fraction&) const;
    Fraction& operator += (const Fraction&);

    Fraction  operator -  (const Fraction&) const;
    Fraction& operator -= (const Fraction&);

    Fraction  operator *  (const Fraction&) const;
    Fraction& operator *= (const Fraction&);

    Fraction  operator /  (const Fraction&) const;
    Fraction& operator /= (const Fraction&);

    // cacel down the fraction (if possible)
    Fraction& cancelDown ();

    // could the fraction cancel down
    bool couldCancelDown () const;

    // get the numerator
    int Numerator   () const;

    // get the denominator
    int Denominator () const;

    // get Fraction as double
    double asDouble () const;

    // stream-output
    ostream& print (ostream& = cout) const;

    // stream-input
    istream& read  (istream& = cin);

  protected:

  private:
    // data-members
    int ObjNumerator;
    int ObjDenominator;
    unsigned ObjCancelDown;

    // greatest common factor
    // of numerator and denominator
    unsigned GreatestCommonFactor () const;

  //friends

};

// global ostream-operator
inline ostream& operator << (ostream& ostrm, const Fraction& f) {
    return f.print (ostrm);
}

// global istream-operator
inline istream& operator >> (istream& istrm, Fraction& f) {
    return f.read (istrm);
}

#endif  // _FRACTION_H

