/*
 *  Open BEAGLE
 *  Copyright (C) 2001-2004 by Christian Gagne and Marc Parizeau
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 *  Contact:
 *  Laboratoire de Vision et Systemes Numeriques
 *  Departement de genie electrique et de genie informatique
 *  Universite Laval, Quebec, Canada, G1K 7P4
 *  http://vision.gel.ulaval.ca
 *
 */

/*!
 *  \file   beagle/Int.hpp
 *  \brief  Definition of the type Int and related operators.
 *  \author Christian Gagne
 *  \author Marc Parizeau
 *  $Revision: 1.3 $
 *  $Date: 2004/04/25 23:12:20 $
 */

#ifndef Beagle_Int_hpp
#define Beagle_Int_hpp

#include "beagle/config.hpp"
#include "beagle/macros.hpp"
#include "beagle/WrapperT.hpp"


namespace Beagle {

/*!
 *  \brief Beagle wrapper of the atomic int type.
 *  \ingroup Adapt
 */
typedef WrapperT< int >
        Int;

}


/*!
 *  \brief     Test whether an int is less than another.
 *  \param     inLeftInt  Left int compared.
 *  \param     inRightInt Right int compared.
 *  \return    True if left int is less than the right one, false if not.
 *  \par Note:
 *    The operator is defined relatively to the function isLess of Beagle::Int.
 */
inline bool operator<(const Beagle::Int& inLeftInt, const Beagle::Int& inRightInt)
{
  return inLeftInt.isLess(inRightInt);
}


/*!
 *  \brief     Test whether an int is less than, or equal to another.
 *  \param     inLeftInt  Left int compared.
 *  \param     inRightInt Right int compared.
 *  \return    True if left int is less than, or equal to the right one, false if not.
 *  \par Note:
 *    The operator is defined relatively to the functions isLess and isEqual of Beagle::Int.
 */
inline bool operator<=(const Beagle::Int& inLeftInt, const Beagle::Int& inRightInt)
{
  return ( inLeftInt.isLess(inRightInt) || inLeftInt.isEqual(inRightInt) );
}


/*!
 *  \brief     Test whether an int is more than another.
 *  \param     inLeftInt  Left int compared.
 *  \param     inRightInt Right int compared.
 *  \return    True if left int is more than the right one, false if not.
 *  \par Note:
 *    The operator is defined relatively to the function isLess of Beagle::Int.
 */
inline bool operator>(const Beagle::Int& inLeftInt, const Beagle::Int& inRightInt)
{
  return inRightInt.isLess(inLeftInt);
}


/*!
 *  \brief     Test whether an int is more than, or equal to another.
 *  \param     inLeftInt  Left int compared.
 *  \param     inRightInt Right int compared.
 *  \return    True if left int is more than, or equal to the right one, false if not.
 *  \par Note:
 *    The operator is defined relatively to the functions isLess and isEqual of Beagle::Int.
 */
inline bool operator>=(const Beagle::Int& inLeftInt, const Beagle::Int& inRightInt)
{
  return ( inRightInt.isLess(inLeftInt) || inLeftInt.isEqual(inRightInt) );
}


/*!
 *  \brief     Test whether an int is equal to another.
 *  \param     inLeftInt  Left int compared.
 *  \param     inRightInt Right int compared.
 *  \return    True if left int is equal to the right one, false if not.
 *  \par Note:
 *    The operator is defined relatively to the function isEqual of Beagle::Int.
 */
inline bool operator==(const Beagle::Int& inLeftInt, const Beagle::Int& inRightInt)
{
  return inLeftInt.isEqual(inRightInt);
}


/*!
 *  \brief     Test whether an int is not equal to another.
 *  \param     inLeftInt  Left int compared.
 *  \param     inRightInt Right int compared.
 *  \return    True if left int is not equal to the right one, false if it is.
 *  \par Note:
 *    The operator is defined relatively to the function isEqual of Beagle::Int.
 */
inline bool operator!=(const Beagle::Int& inLeftInt, const Beagle::Int& inRightInt)
{
  return ( inLeftInt.isEqual(inRightInt) == false);
}


/*!
 *  \brief Compare equality of a Int with a int.
 *  \param inLeftInt Left value to compare.
 *  \param inRightInt Right value to compare.
 *  \return Result of the comparison.
 */
inline
bool operator==(const Beagle::Int& inLeftInt, int inRightInt)
{
  return inLeftInt.getWrappedValue() == inRightInt;
}


/*!
 *  \brief Compare inequality of a Int with a int.
 *  \param inLeftInt Left value to compare.
 *  \param inRightInt Right value to compare.
 *  \return Result of the comparison.
 */
inline
bool operator!=(const Beagle::Int& inLeftInt, int inRightInt)
{
  return inLeftInt.getWrappedValue() != inRightInt;
}


/*!
 *  \brief Test if a Int is < than a int.
 *  \param inLeftInt Left value to compare.
 *  \param inRightInt Right value to compare.
 *  \return Result of the comparison.
 */
inline
bool operator<(const Beagle::Int& inLeftInt, int inRightInt)
{
  return inLeftInt.getWrappedValue() < inRightInt;
}


/*!
 *  \brief Test if a Int is <= than a int.
 *  \param inLeftInt Left value to compare.
 *  \param inRightInt Right value to compare.
 *  \return Result of the comparison.
 */
inline
bool operator<=(const Beagle::Int& inLeftInt, int inRightInt)
{
  return inLeftInt.getWrappedValue() <= inRightInt;
}


/*!
 *  \brief Test if a Int is > than a int.
 *  \param inLeftInt Left value to compare.
 *  \param inRightInt Right value to compare.
 *  \return Result of the comparison.
 */
inline
bool operator>(const Beagle::Int& inLeftInt, int inRightInt)
{
  return inLeftInt.getWrappedValue() > inRightInt;
}


/*!
 *  \brief Test if a Int is >= than a int.
 *  \param inLeftInt Left value to compare.
 *  \param inRightInt Right value to compare.
 *  \return Result of the comparison.
 */
inline
bool operator>=(const Beagle::Int& inLeftInt, int inRightInt)
{
  return inLeftInt.getWrappedValue() >= inRightInt;
}


/*!
 *  \brief Increment a Int (prefix version).
 *  \param inInt Int to increment.
 *  \return Int incremented.
 */
inline
Beagle::Int& operator++(Beagle::Int& inInt)
{
  inInt.getWrappedValue()++;
  return inInt;
}


/*!
 *  \brief Increment a Int (postfix version).
 *  \param inInt Int to increment.
 *  \return Int before being incremented.
 */
inline
Beagle::Int operator++(Beagle::Int& inInt, int)
{
  Beagle::Int lInt = inInt;
  inInt.getWrappedValue()++;
  return lInt;
}


/*!
 *  \brief Add two Int.
 *  \param inLeftInt Left value to add.
 *  \param inRightInt Right value to add.
 *  \return Result of the addition.
 */
inline
Beagle::Int operator+(const Beagle::Int& inLeftInt, const Beagle::Int& inRightInt)
{
  return inLeftInt.getWrappedValue() + inRightInt.getWrappedValue();
}


/*!
 *  \brief Add a Int with a int.
 *  \param inLeftInt Left value to add.
 *  \param inRightInt Right value to add.
 *  \return Result of the addition.
 */
inline
Beagle::Int operator+(const Beagle::Int& inLeftInt, int inRightInt)
{
  return inLeftInt.getWrappedValue() + inRightInt;
}


/*!
 *  \brief Add a Int to a Int.
 *  \param inLeftInt Left value to which the right one is added.
 *  \param inRightInt Value to add.
 *  \return Result of the addition.
 */
inline
Beagle::Int& operator+=(Beagle::Int& inLeftInt, const Beagle::Int& inRightInt)
{
  inLeftInt.getWrappedValue() += inRightInt.getWrappedValue();
  return inLeftInt;
}


/*!
 *  \brief Add a int to a Int.
 *  \param inLeftInt Left value to which the right one is added.
 *  \param inRightInt Value to add.
 *  \return Result of the addition.
 */
inline
Beagle::Int& operator+=(Beagle::Int& inLeftInt, int inRightInt)
{
  inLeftInt.getWrappedValue() += inRightInt;
  return inLeftInt;
}


/*!
 *  \brief Decrement a Int (prefix version).
 *  \param inInt Int to decrement.
 *  \return Int decremented.
 */
inline
Beagle::Int& operator--(Beagle::Int& inInt)
{
  inInt.getWrappedValue()--;
  return inInt;
}


/*!
 *  \brief Decrement a Int (postfix version).
 *  \param inInt Int to decrement.
 *  \return Int before being decremented.
 */
inline
Beagle::Int operator--(Beagle::Int& inInt, int)
{
  Beagle::Int lInt = inInt;
  inInt.getWrappedValue()--;
  return lInt;
}



/*!
 *  \brief Subtract two Int.
 *  \param inLeftInt Left value to subtract.
 *  \param inRightInt Right value to subtract.
 *  \return Result of the subtract.
 */
inline
Beagle::Int operator-(const Beagle::Int& inLeftInt, const Beagle::Int& inRightInt)
{
  return inLeftInt.getWrappedValue() - inRightInt.getWrappedValue();
}


/*!
 *  \brief Subtract a int from a Int.
 *  \param inLeftInt Left value to subtract.
 *  \param inRightInt Right value to subtract.
 *  \return Result of the subtract.
 */
inline
Beagle::Int operator-(const Beagle::Int& inLeftInt, int inRightInt)
{
  return inLeftInt.getWrappedValue() - inRightInt;
}


/*!
 *  \brief Subtract a Int from a Int.
 *  \param inLeftInt Left value from which the right int is subtracted.
 *  \param inRightInt Value to subtract.
 *  \return Result of the subtraction.
 */
inline
Beagle::Int& operator-=(Beagle::Int& inLeftInt, const Beagle::Int& inRightInt)
{
  inLeftInt.getWrappedValue() -= inRightInt.getWrappedValue();
  return inLeftInt;
}


/*!
 *  \brief Subtract a int from a Int.
 *  \param inLeftInt Left value from which the right int is subtracted.
 *  \param inRightInt Value to subtract.
 *  \return Result of the subtraction.
 */
inline
Beagle::Int& operator-=(Beagle::Int& inLeftInt, int inRightInt)
{
  inLeftInt.getWrappedValue() -= inRightInt;
  return inLeftInt;
}


/*!
 *  \brief Multiply two Int.
 *  \param inLeftInt Left value to multiply.
 *  \param inRightInt Right value to multiply.
 *  \return Result of the multiply.
 */
inline
Beagle::Int operator*(const Beagle::Int& inLeftInt, const Beagle::Int& inRightInt)
{
  return inLeftInt.getWrappedValue() * inRightInt.getWrappedValue();
}


/*!
 *  \brief Multiply a Int with a int.
 *  \param inLeftInt Left value to multiply.
 *  \param inRightInt Right value to multiply.
 *  \return Result of the multiply.
 */
inline
Beagle::Int operator*(const Beagle::Int& inLeftInt, int inRightInt)
{
  return inLeftInt.getWrappedValue() * inRightInt;
}


/*!
 *  \brief Multiply a Int with a Int.
 *  \param inLeftInt Left value to which the right int is multiplied.
 *  \param inRightInt Right value to multiply.
 *  \return Result of the multiplication.
 */
inline
Beagle::Int& operator*=(Beagle::Int& inLeftInt, const Beagle::Int& inRightInt)
{
  inLeftInt.getWrappedValue() *= inRightInt.getWrappedValue();
  return inLeftInt;
}


/*!
 *  \brief Multiply a Int with a int.
 *  \param inLeftInt Left value from which the right int is multiplied.
 *  \param inRightInt Right value to multiply.
 *  \return Result of the multiplication.
 */
inline
Beagle::Int& operator*=(Beagle::Int& inLeftInt, int inRightInt)
{
  inLeftInt.getWrappedValue() *= inRightInt;
  return inLeftInt;
}


/*!
 *  \brief Divide two Int.
 *  \param inLeftInt Left value to divide.
 *  \param inRightInt Right value to divide.
 *  \return Result of the division.
 */
inline
Beagle::Int operator/(const Beagle::Int& inLeftInt, const Beagle::Int& inRightInt)
{
  return inLeftInt.getWrappedValue() / inRightInt.getWrappedValue();
}


/*!
 *  \brief Divide a Int with a int.
 *  \param inLeftInt Left value to divide.
 *  \param inRightInt Right value to divide.
 *  \return Result of the division.
 */
inline
Beagle::Int operator/(const Beagle::Int& inLeftInt, int inRightInt)
{
  return inLeftInt.getWrappedValue() / inRightInt;
}


/*!
 *  \brief Divide a Int with a Int.
 *  \param inLeftInt Left value to which the right int is divided.
 *  \param inRightInt Right value to divide.
 *  \return Result of the division.
 */
inline
Beagle::Int& operator/=(Beagle::Int& inLeftInt, const Beagle::Int& inRightInt)
{
  inLeftInt.getWrappedValue() /= inRightInt.getWrappedValue();
  return inLeftInt;
}


/*!
 *  \brief Divide a Int with a int.
 *  \param inLeftInt Left value from which the right int is divided.
 *  \param inRightInt Right value to divide.
 *  \return Result of the division.
 */
inline
Beagle::Int operator/=(Beagle::Int& inLeftInt, int inRightInt)
{
  inLeftInt.getWrappedValue() /= inRightInt;
  return inLeftInt;
}


#endif // Beagle_Int_hpp



