Loading...
Searching...
No Matches
function.h
Go to the documentation of this file.
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//
#ifndef BALL_MATHS_FUNCTION_H
#define BALL_MATHS_FUNCTION_H
#ifndef BALL_COMMON_H
# include <BALL/common.h>
#endif
namespace BALL
{
template <int constant_template>
class ConstantFunction
{
public:
BALL_CREATE(ConstantFunction)
BALL_INLINE
float operator () (float /* x */) const
{
return constant_template;
}
};
template <typename DataType = float>
class MutableConstant
{
public:
BALL_CREATE(MutableConstant)
MutableConstant();
MutableConstant(const MutableConstant<DataType>& constant);
MutableConstant(DataType constant);
virtual ~MutableConstant();
MutableConstant<DataType>& operator = (const MutableConstant<DataType>& constant);
bool operator == (const MutableConstant<DataType>& constant) const;
BALL_INLINE
DataType operator () (const DataType& /* x */) const
{
return constant_;
}
void setConstant(DataType constant)
{
constant_ = constant;
}
const DataType& getConstant() const
{
return constant_;
}
protected:
/*_ the constant
*/
DataType constant_;
};
template <typename First, typename Second, typename DataType = float>
class Addition
{
public:
BALL_CREATE(Addition)
Addition();
Addition(const Addition<First, Second, DataType>& addition);
virtual ~Addition();
Addition<First, Second, DataType>& operator = (const Addition<First, Second, DataType>& addition);
bool operator == (const Addition<First, Second, DataType>& addition) const;
BALL_INLINE
DataType operator () (const DataType& x) const
{
return (first_(x) + second_(x));
}
void setFirst(const First& first)
{
first_ = first;
}
First& getFirst()
{
return first_;
}
const First& getFirst() const
{
return first_;
}
void setSecond(const Second& second)
{
second_ = second;
}
Second& getSecond()
{
return second_;
}
const Second& getSecond() const
{
return second_;
}
protected:
/*_ the first argument of the addition
*/
First first_;
/*_ the second argument of the addition
*/
Second second_;
};
template <typename First, typename Second, typename DataType = float>
class Subtraction
{
public:
BALL_CREATE(Subtraction)
Subtraction();
Subtraction(const Subtraction& subtraction);
virtual ~Subtraction();
Subtraction<First, Second, DataType>& operator = (const Subtraction<First, Second, DataType>& subtraction);
bool operator == (const Subtraction<First, Second, DataType>& subtraction) const;
BALL_INLINE
DataType operator () (const DataType& x) const
{
return (first_(x) - second_(x));
}
void setFirst(const First& first)
{
first_ = first;
}
First& getFirst()
{
return first_;
}
void setSecond(const Second& second)
{
second_ = second;
}
Second& getSecond()
{
return second_;
}
protected:
/*_ the first argument of the subtraction
*/
First first_;
/*_ the second argument of the subtraction
*/
Second second_;
};
template <typename First, typename Second, typename DataType = float>
class Product
{
public:
BALL_CREATE(Product)
Product();
Product(const Product& product);
virtual ~Product();
Product<First, Second, DataType>& operator = (const Product<First, Second, DataType>& product);
bool operator == (const Product<First, Second, DataType>& product) const;
BALL_INLINE
DataType operator () (const DataType& x) const
{
return (first_(x) * second_(x));
}
void setFirst(const First& first)
{
first_ = first;
}
First& getFirst()
{
return first_;
}
const First& getFirst() const
{
return first_;
}
void setSecond(const Second& second)
{
second_ = second;
}
Second& getSecond()
{
return second_;
}
protected:
/*_ the first argument of the product
*/
First first_;
/*_ the second argument of the product
*/
Second second_;
};
template <typename First, typename Second, typename DataType = float>
class Division
{
public:
BALL_CREATE(Division)
Division();
Division(const Division& division);
virtual ~Division();
Division<First, Second, DataType>& operator = (const Division<First, Second, DataType>& division);
bool operator == (const Division<First, Second, DataType>& division) const;
BALL_INLINE
DataType operator () (const DataType& x) const
{
DataType val = second_(x);
if (val != 0.0)
{
return (first_(x) / val);
}
else
{
throw Exception::DivisionByZero(__FILE__, __LINE__);
}
}
void setFirst(const First& first)
{
first_ = first;
}
First& getFirst()
{
return first_;
}
void setSecond(const Second& second)
{
second_ = second;
}
Second& getSecond()
{
return second_;
}
protected:
/*_ the first argument of the division
*/
First first_;
/*_ the second argument of the division
*/
Second second_;
};
template <typename Function, typename DataType = float>
class Reciprocal
{
public:
BALL_CREATE(Reciprocal)
Reciprocal();
Reciprocal(const Reciprocal& reciprocal);
virtual ~Reciprocal();
Reciprocal<Function, DataType>& operator = (const Reciprocal<Function, DataType>& reciprocal);
bool operator == (const Reciprocal<Function, DataType>& reciprocal) const;
BALL_INLINE
DataType operator () (const DataType& x) const
{
DataType val = function_(x);
if (val != 0)
{
return (1 / val);
}
else
{
throw Exception::DivisionByZero(__FILE__, __LINE__);
}
}
void setFunction(const Function& function)
{
function_ = function;
}
const Function& getFunction() const
{
return function_;
}
protected:
/*_ the argument of the reciprocal
*/
Function function_;
};
template <typename Function, typename DataType = float>
class SquareFunction
{
public:
BALL_CREATE(SquareFunction)
SquareFunction();
SquareFunction(const SquareFunction& square);
virtual ~SquareFunction();
SquareFunction<Function, DataType>& operator = (const SquareFunction<Function, DataType>& square);
bool operator == (const SquareFunction<Function, DataType>& square) const;
BALL_INLINE
DataType operator () (const DataType& x) const
{
DataType val = function_(x);
return val * val;
}
void setFunction(const Function& function)
{
function_ = function;
}
const Function& getFunction() const
{
return function_;
}
protected:
/*_ the argument of the square
*/
Function function_;
};
template <typename Function, typename DataType = float>
class CubicFunction
{
public:
BALL_CREATE(CubicFunction)
CubicFunction();
CubicFunction(const CubicFunction& cubic);
virtual ~CubicFunction();
CubicFunction<Function, DataType>& operator = (const CubicFunction<Function, DataType>& cubic);
bool operator == (const CubicFunction<Function, DataType>& cubic) const;
BALL_INLINE
DataType operator () (const DataType& x) const
{
DataType val = function_(x);
return val * val * val;
}
void setFunction(const Function& function)
{
function_ = function;
}
const Function& getFunction() const
{
return function_;
}
protected:
/*_ the argument of the cubic
*/
Function function_;
};
template <typename Function, typename DataType = float>
class MutablePower
{
public:
BALL_CREATE(MutablePower)
MutablePower();
MutablePower(const MutablePower& power);
virtual ~MutablePower();
MutablePower<Function, DataType>& operator = (const MutablePower<Function, DataType>& power);
bool operator == (const MutablePower<Function, DataType>& power) const;
BALL_INLINE
DataType operator () (const DataType& x) const
{
return pow(function_(x), exponent_);
}
void setFunction(const Function& function)
{
function_ = function;
}
const Function& getFunction() const
{
return function_;
}
void setExponent(DataType exp);
DataType getExponent() const;
protected:
/*_ the argument of the power
*/
Function function_;
/*_ the exponent
*/
DataType exponent_;
};
template <typename DataType>
BALL_INLINE
MutableConstant<DataType>::MutableConstant()
: constant_(0)
{
}
template <typename DataType>
BALL_INLINE
MutableConstant<DataType>::MutableConstant
(const MutableConstant<DataType>& constant)
: constant_(constant.constant_)
{
}
template <typename DataType>
BALL_INLINE
MutableConstant<DataType>::MutableConstant(DataType constant)
: constant_(constant)
{
}
template <typename DataType>
BALL_INLINE
MutableConstant<DataType>::~MutableConstant()
{
}
template <typename DataType>
BALL_INLINE
MutableConstant<DataType>& MutableConstant<DataType>::operator =
(const MutableConstant<DataType>& constant)
{
constant_ = constant.constant_;
return *this;
}
template <typename DataType>
BALL_INLINE
bool MutableConstant<DataType>::operator ==
(const MutableConstant<DataType>& constant) const
{
return (constant_ == constant.constant_);
}
template <typename First, typename Second, typename DataType>
BALL_INLINE
Addition<First, Second, DataType>::Addition()
: first_(),
second_()
{
}
template <typename First, typename Second, typename DataType>
BALL_INLINE
Addition<First, Second, DataType>::Addition(const Addition& addition)
: first_(addition.first_),
second_(addition.second_)
{
}
template <typename First, typename Second, typename DataType>
BALL_INLINE
Addition<First, Second, DataType>::~Addition()
{
}
template <typename First, typename Second, typename DataType>
BALL_INLINE
Addition<First, Second, DataType>& Addition<First, Second, DataType>::operator = (const Addition<First, Second, DataType>& addition)
{
first_ = addition.first_;
second_ = addition.second_;
return *this;
}
template <typename First, typename Second, typename DataType>
BALL_INLINE
bool Addition<First, Second, DataType>::operator == (const Addition<First, Second, DataType>& addition) const
{
return ((first_ == addition.first_) && (second_ == addition.second_));
}
template <typename First, typename Second, typename DataType>
BALL_INLINE
Subtraction<First, Second, DataType>::Subtraction()
: first_(),
second_()
{
}
template <typename First, typename Second, typename DataType>
BALL_INLINE
Subtraction<First, Second, DataType>::Subtraction(const Subtraction& subtraction)
: first_(subtraction.first_),
second_(subtraction.second_)
{
}
template <typename First, typename Second, typename DataType>
BALL_INLINE
Subtraction<First, Second, DataType>::~Subtraction()
{
}
template <typename First, typename Second, typename DataType>
BALL_INLINE
Subtraction<First, Second, DataType>& Subtraction<First, Second, DataType>::operator = (const Subtraction<First, Second, DataType>& subtraction)
{
first_ = subtraction.first_;
second_ = subtraction.second_;
return *this;
}
template <typename First, typename Second, typename DataType>
BALL_INLINE
bool Subtraction<First, Second, DataType>::operator == (const Subtraction<First, Second, DataType>& subtraction) const
{
return ((first_ == subtraction.first_) && (second_ == subtraction.second_));
}
template <typename First, typename Second, typename DataType>
BALL_INLINE
Product<First, Second, DataType>::Product()
: first_(),
second_()
{
}
template <typename First, typename Second, typename DataType>
BALL_INLINE
Product<First, Second, DataType>::Product(const Product& product)
: first_(product.first_),
second_(product.second_)
{
}
template <typename First, typename Second, typename DataType>
BALL_INLINE
Product<First, Second, DataType>::~Product()
{
}
template <typename First, typename Second, typename DataType>
BALL_INLINE
Product<First, Second, DataType>& Product<First, Second, DataType>::operator = (const Product<First, Second, DataType>& product)
{
first_ = product.first_;
second_ = product.second_;
return *this;
}
template <typename First, typename Second, typename DataType>
BALL_INLINE
bool Product<First, Second, DataType>::operator == (const Product<First, Second, DataType>& product) const
{
return ((first_ == product.first_) && (second_ == product.second_));
}
template <typename First, typename Second, typename DataType>
BALL_INLINE
Division<First, Second, DataType>::Division()
: first_(),
second_()
{
}
template <typename First, typename Second, typename DataType>
BALL_INLINE
Division<First, Second, DataType>::Division(const Division& division)
: first_(division.first_),
second_(division.second_)
{
}
template <typename First, typename Second, typename DataType>
BALL_INLINE
Division<First, Second, DataType>::~Division()
{
}
template <typename First, typename Second, typename DataType>
BALL_INLINE
Division<First, Second, DataType>& Division<First, Second, DataType>::operator = (const Division<First, Second, DataType>& division)
{
first_ = division.first_;
second_ = division.second_;
return *this;
}
template <typename First, typename Second, typename DataType>
BALL_INLINE
bool Division<First, Second, DataType>::operator == (const Division<First, Second, DataType>& division) const
{
return ((first_ == division.first_) && (second_ == division.second_));
}
template <typename Function, typename DataType>
BALL_INLINE
SquareFunction<Function, DataType>::SquareFunction()
: function_()
{
}
template <typename Function, typename DataType>
BALL_INLINE
SquareFunction<Function, DataType>::SquareFunction(const SquareFunction& square)
: function_(square.function_)
{
}
template <typename Function, typename DataType>
BALL_INLINE
SquareFunction<Function, DataType>::~SquareFunction()
{
}
template <typename Function, typename DataType>
BALL_INLINE
SquareFunction<Function, DataType>& SquareFunction<Function, DataType>::operator = (const SquareFunction<Function, DataType>& square)
{
function_ = square.function_;
return *this;
}
template <typename Function, typename DataType>
BALL_INLINE
bool SquareFunction<Function, DataType>::operator == (const SquareFunction& square) const
{
return (function_ == square.function_);
}
template <typename Function, typename DataType>
BALL_INLINE
CubicFunction<Function, DataType>::CubicFunction()
: function_(0)
{
}
template <typename Function, typename DataType>
BALL_INLINE
CubicFunction<Function, DataType>::CubicFunction(const CubicFunction& cubic)
: function_(cubic.function_)
{
}
template <typename Function, typename DataType>
BALL_INLINE
CubicFunction<Function, DataType>::~CubicFunction()
{
}
template <typename Function, typename DataType>
BALL_INLINE
CubicFunction<Function, DataType>& CubicFunction<Function, DataType>::operator = (const CubicFunction<Function, DataType>& cubic)
{
function_ = cubic.function_;
return *this;
}
template <typename Function, typename DataType>
BALL_INLINE
bool CubicFunction<Function, DataType>::operator == (const CubicFunction& cubic) const
{
return (function_ == cubic.function_);
}
template <typename Function, typename DataType>
BALL_INLINE
Reciprocal<Function, DataType>::Reciprocal()
: function_()
{
}
template <typename Function, typename DataType>
BALL_INLINE
Reciprocal<Function, DataType>::Reciprocal(const Reciprocal& reciprocal)
: function_(reciprocal.function_)
{
}
template <typename Function, typename DataType>
BALL_INLINE
Reciprocal<Function, DataType>::~Reciprocal()
{
}
template <typename Function, typename DataType>
BALL_INLINE
Reciprocal<Function, DataType>& Reciprocal<Function, DataType>::operator = (const Reciprocal<Function, DataType>& reciprocal)
{
function_ = reciprocal.function_;
return *this;
}
template <typename Function, typename DataType>
BALL_INLINE
bool Reciprocal<Function, DataType>::operator == (const Reciprocal& reciprocal) const
{
return (function_ == reciprocal.function_);
}
template <typename Function, typename DataType>
BALL_INLINE
MutablePower<Function, DataType>::MutablePower()
: function_(0),
exponent_(0)
{
}
template <typename Function, typename DataType>
BALL_INLINE
MutablePower<Function, DataType>::MutablePower(const MutablePower& power)
: function_(power.function_),
exponent_(power.exponent_)
{
}
template <typename Function, typename DataType>
BALL_INLINE
MutablePower<Function, DataType>::~MutablePower()
{
}
template <typename Function, typename DataType>
BALL_INLINE
MutablePower<Function, DataType>& MutablePower<Function, DataType>::operator = (const MutablePower& power)
{
function_ = power.function_;
exponent_ = power.exponent_;
return *this;
}
template <typename Function, typename DataType>
BALL_INLINE
bool MutablePower<Function, DataType>::operator == (const MutablePower& power) const
{
return ((exponent_ == power.exponent_)
&& (function_ == power.function_));
}
template <typename Function, typename DataType>
BALL_INLINE
DataType MutablePower<Function, DataType>::getExponent() const
{
return exponent_;
}
template <typename Function, typename DataType>
BALL_INLINE
void MutablePower<Function, DataType>::setExponent(DataType exp)
{
exponent_ = exp;
}
} // namespace BALL
#endif // BALL_MATHS_FUNCTION_H
BALL::Addition::first_
First first_
Definition function.h:253
BALL::Addition::setFirst
void setFirst(const First &first)
Definition function.h:205
BALL::Addition::getSecond
const Second & getSecond() const
Definition function.h:242
BALL::Addition::second_
Second second_
Definition function.h:257
BALL::Addition::setSecond
void setSecond(const Second &second)
Definition function.h:227
BALL::Addition::getFirst
First & getFirst()
Definition function.h:213
BALL::Addition::Addition
Addition()
Definition function.h:1031
BALL::Addition::getFirst
const First & getFirst() const
Definition function.h:220
BALL::Addition::operator=
Addition< First, Second, DataType > & operator=(const Addition< First, Second, DataType > &addition)
Definition function.h:1053
BALL::Addition::getSecond
Second & getSecond()
Definition function.h:235
BALL::Addition::operator==
bool operator==(const Addition< First, Second, DataType > &addition) const
Definition function.h:1062
BALL::Addition::~Addition
virtual ~Addition()
Definition function.h:1047
BALL::ConstantFunction
Definition function.h:21
BALL::CubicFunction::setFunction
void setFunction(const Function &function)
Definition function.h:857
BALL::CubicFunction::function_
Function function_
Definition function.h:876
BALL::CubicFunction::CubicFunction
CubicFunction()
Definition function.h:1223
BALL::CubicFunction::getFunction
const Function & getFunction() const
Definition function.h:865
BALL::CubicFunction::operator==
bool operator==(const CubicFunction< Function, DataType > &cubic) const
Definition function.h:1251
BALL::CubicFunction::~CubicFunction
virtual ~CubicFunction()
Definition function.h:1237
BALL::CubicFunction::operator=
CubicFunction< Function, DataType > & operator=(const CubicFunction< Function, DataType > &cubic)
Definition function.h:1243
BALL::Division::setSecond
void setSecond(const Second &second)
Definition function.h:575
BALL::Division::operator=
Division< First, Second, DataType > & operator=(const Division< First, Second, DataType > &division)
Definition function.h:1170
BALL::Division::Division
Division()
Definition function.h:1148
BALL::Division::second_
Second second_
Definition function.h:598
BALL::Division::setFirst
void setFirst(const First &first)
Definition function.h:560
BALL::Division::first_
First first_
Definition function.h:594
BALL::Division::operator==
bool operator==(const Division< First, Second, DataType > &division) const
Definition function.h:1179
BALL::Division::getSecond
Second & getSecond()
Definition function.h:583
BALL::Division::getFirst
First & getFirst()
Definition function.h:568
BALL::Division::~Division
virtual ~Division()
Definition function.h:1164
BALL::Exception::DivisionByZero
Definition COMMON/exception.h:342
BALL::MutableConstant::getConstant
const DataType & getConstant() const
Definition function.h:123
BALL::MutableConstant::setConstant
void setConstant(DataType constant)
Definition function.h:115
BALL::MutableConstant::MutableConstant
MutableConstant()
Definition function.h:985
BALL::MutableConstant::constant_
DataType constant_
Definition function.h:134
BALL::MutableConstant::~MutableConstant
virtual ~MutableConstant()
Definition function.h:1007
BALL::MutablePower::operator=
MutablePower< Function, DataType > & operator=(const MutablePower< Function, DataType > &power)
Definition function.h:1317
BALL::MutablePower::operator==
bool operator==(const MutablePower< Function, DataType > &power) const
Definition function.h:1326
BALL::MutablePower::getFunction
const Function & getFunction() const
Definition function.h:954
BALL::MutablePower::getExponent
DataType getExponent() const
Definition function.h:1334
BALL::MutablePower::function_
Function function_
Definition function.h:975
BALL::MutablePower::MutablePower
MutablePower()
Definition function.h:1295
BALL::MutablePower::setExponent
void setExponent(DataType exp)
Definition function.h:1341
BALL::MutablePower::~MutablePower
virtual ~MutablePower()
Definition function.h:1311
BALL::MutablePower::exponent_
DataType exponent_
Definition function.h:979
BALL::MutablePower::setFunction
void setFunction(const Function &function)
Definition function.h:946
BALL::Product::first_
First first_
Definition function.h:477
BALL::Product::setSecond
void setSecond(const Second &second)
Definition function.h:458
BALL::Product::second_
Second second_
Definition function.h:481
BALL::Product::~Product
virtual ~Product()
Definition function.h:1125
BALL::Product::getSecond
Second & getSecond()
Definition function.h:466
BALL::Product::operator==
bool operator==(const Product< First, Second, DataType > &product) const
Definition function.h:1140
BALL::Product::getFirst
const First & getFirst() const
Definition function.h:450
BALL::Product::Product
Product()
Definition function.h:1109
BALL::Product::operator=
Product< First, Second, DataType > & operator=(const Product< First, Second, DataType > &product)
Definition function.h:1131
BALL::Product::setFirst
void setFirst(const First &first)
Definition function.h:434
BALL::Product::getFirst
First & getFirst()
Definition function.h:442
BALL::Reciprocal::operator=
Reciprocal< Function, DataType > & operator=(const Reciprocal< Function, DataType > &reciprocal)
Definition function.h:1279
BALL::Reciprocal::function_
Function function_
Definition function.h:696
BALL::Reciprocal::setFunction
void setFunction(const Function &function)
Definition function.h:677
BALL::Reciprocal::operator==
bool operator==(const Reciprocal< Function, DataType > &reciprocal) const
Definition function.h:1287
BALL::Reciprocal::~Reciprocal
virtual ~Reciprocal()
Definition function.h:1273
BALL::Reciprocal::getFunction
const Function & getFunction() const
Definition function.h:685
BALL::Reciprocal::Reciprocal
Reciprocal()
Definition function.h:1259
BALL::SquareFunction::setFunction
void setFunction(const Function &function)
Definition function.h:767
BALL::SquareFunction::SquareFunction
SquareFunction()
Definition function.h:1187
BALL::SquareFunction::getFunction
const Function & getFunction() const
Definition function.h:775
BALL::SquareFunction::~SquareFunction
virtual ~SquareFunction()
Definition function.h:1201
BALL::SquareFunction::function_
Function function_
Definition function.h:786
BALL::SquareFunction::operator=
SquareFunction< Function, DataType > & operator=(const SquareFunction< Function, DataType > &square)
Definition function.h:1207
BALL::SquareFunction::operator==
bool operator==(const SquareFunction< Function, DataType > &square) const
Definition function.h:1215
BALL::Subtraction::operator==
bool operator==(const Subtraction< First, Second, DataType > &subtraction) const
Definition function.h:1101
BALL::Subtraction::second_
Second second_
Definition function.h:365
BALL::Subtraction::operator=
Subtraction< First, Second, DataType > & operator=(const Subtraction< First, Second, DataType > &subtraction)
Definition function.h:1092
BALL::Subtraction::~Subtraction
virtual ~Subtraction()
Definition function.h:1086
BALL::Subtraction::first_
First first_
Definition function.h:361
BALL::Subtraction::getFirst
First & getFirst()
Definition function.h:335
BALL::Subtraction::Subtraction
Subtraction()
Definition function.h:1070
BALL::Subtraction::setSecond
void setSecond(const Second &second)
Definition function.h:342
BALL::Subtraction::setFirst
void setFirst(const First &first)
Definition function.h:327
BALL::Subtraction::getSecond
Second & getSecond()
Definition function.h:350
Function
common.h
BALL_CREATE
#define BALL_CREATE(name)
Definition create.h:62
BALL_INLINE
#define BALL_INLINE
Definition debug.h:15
BALL
Definition constants.h:13
BALL::operator==
BALL_EXPORT bool operator==(const String &s1, const String &s2)