Home

hersto:  Library/Follower_Trait_impl.h

Source of Library/Follower_Trait_impl.h:

Here is a link for right-clicking and downloading the file: Library/Follower_Trait_impl.h (2.48 K Byte),

and below is its content to view online.



/*
 Follower_Trait_impl.h
 
 A trait class for specifying how to perform
 operations on the data type used by the CTDamper
 and CTChaser template classes.

 Author:
     Herbert Stocker

 HomePage:
     http://www.hersto.net/Followers
     (various resources there)

 License:
     You may use this file in any project and
     modify it as long as you keep this comment
     block unchanged.

 Accompanying Files:
     Follower_Trait.h
     Follower_Trait.cpp

 Documentation:
     See http://www.hersto.net/Followers
     and the comments below.

 */



#define This (*this)


template<class Type>
CTFollowerVarTrait<Type>::CTFollowerVarTrait()
{}
// relies on the default constructor of Type to initialize to some kind of zero.
// However, we provide specializations for float and double, so that these are
// always initialized.

inline
CTFollowerVarTrait<float>::CTFollowerVarTrait()
:   mValue(0)
{}

inline
CTFollowerVarTrait<double>::CTFollowerVarTrait()
:   mValue(0)
{}

template<class Type>
CTFollowerVarTrait<Type>::~CTFollowerVarTrait()
{}


template<class Type>
CTFollowerVarTrait<Type>::CTFollowerVarTrait(const Type& Value)
:   mValue(Value)
{}




template<class Type>
CTFollowerVarTrait<Type>::CTFollowerVarTrait(const CTFollowerVarTrait<Type>& That)
:   mValue(That.mValue)
{}


template<class Type>
const Type& CTFollowerVarTrait<Type>::get_Value() const
{
    return mValue;
}








template<class Type>
CTFollowerVarTrait<Type> CTFollowerVarTrait<Type>::Interpolate(const CTFollowerVarTrait<Type>& That, double T) const
{
    return mValue * (1 - T) + That.mValue * T;
}



template<class Type>
double CTFollowerVarTrait<Type>::Distance(const CTFollowerVarTrait<Type>& That) const
{
    return CTFollowerVarTrait<Type>(mValue - That.mValue).Length();
}



template<class Type>
bool CTFollowerVarTrait<Type>::operator!= (const CTFollowerVarTrait<Type>& That) const
{
    return This.mValue != That.mValue;
}


template<class Type>
double CTFollowerVarTrait<Type>::Length() const
{
    return mValue.length(); // in the hope that if it is a vector, it has a .length() funciton.
    // However we provide specializations for float and double, so that this is not an issue.
}

 
inline
double CTFollowerVarTrait<float>::Length() const
{
    return mValue < 0? -mValue : mValue;
}


inline
double CTFollowerVarTrait<double>::Length() const
{
    return mValue < 0? -mValue : mValue;
}



__.-.__
end of document