00001 #ifdef CH_LANG_CC
00002
00003
00004
00005
00006
00007
00008
00009 #endif
00010
00011
00012
00013
00014
00015 #ifndef _GENERICARITHMETICI_H_
00016 #define _GENERICARITHMETICI_H_
00017
00018 #include <functional>
00019 #include "BaseNamespaceHeader.H"
00020
00021
00022
00023
00024
00025 template<typename ScalarT, typename SelfT> bool
00026 GenericArithmeticable<ScalarT,SelfT>::operator<( const SelfT& rhs ) const
00027 {
00028 return m_child->operatorCompare( rhs, std::less<ScalarT>() );
00029 }
00030
00031 template<typename ScalarT, typename SelfT> bool
00032 GenericArithmeticable<ScalarT,SelfT>::operator>( const SelfT& rhs ) const
00033 {
00034 return m_child->operatorCompare( rhs, std::greater<ScalarT>() );
00035 }
00036
00037 template<typename ScalarT, typename SelfT> bool
00038 GenericArithmeticable<ScalarT,SelfT>::operator<=( const SelfT& rhs ) const
00039 {
00040 return m_child->operatorCompare( rhs, std::less_equal<ScalarT>() );
00041 }
00042
00043 template<typename ScalarT, typename SelfT> bool
00044 GenericArithmeticable<ScalarT,SelfT>::operator>=( const SelfT& rhs ) const
00045 {
00046 return m_child->operatorCompare( rhs, std::greater_equal<ScalarT>() );
00047 }
00048
00049
00050
00051
00052 template<typename ScalarT, typename SelfT> SelfT&
00053 GenericArithmeticable<ScalarT,SelfT>::operator+=(const SelfT& rhs)
00054 {
00055 return m_child->operatorOpEquals( rhs, std::plus<ScalarT>() );
00056 }
00057
00058 template<typename ScalarT, typename SelfT> SelfT&
00059 GenericArithmeticable<ScalarT,SelfT>::operator+=(const ScalarT& a)
00060 {
00061 return m_child->operatorOpEquals( a, std::plus<ScalarT>() );
00062 }
00063
00064 template<typename ScalarT, typename SelfT> SelfT&
00065 GenericArithmeticable<ScalarT,SelfT>::operator-=(const SelfT& rhs)
00066 {
00067 return m_child->operatorOpEquals( rhs, std::minus<ScalarT>() );
00068 }
00069
00070 template<typename ScalarT, typename SelfT> SelfT&
00071 GenericArithmeticable<ScalarT,SelfT>::operator-=(const ScalarT& a)
00072 {
00073 return m_child->operatorOpEquals( a, std::minus<ScalarT>() );
00074 }
00075
00076 template<typename ScalarT, typename SelfT> SelfT&
00077 GenericArithmeticable<ScalarT,SelfT>::operator*=(const SelfT& rhs)
00078 {
00079 return m_child->operatorOpEquals( rhs, std::multiplies<ScalarT>() );
00080 }
00081
00082 template<typename ScalarT, typename SelfT> SelfT&
00083 GenericArithmeticable<ScalarT,SelfT>::operator*=(const ScalarT& a)
00084 {
00085 return m_child->operatorOpEquals( a, std::multiplies<ScalarT>() );
00086 }
00087
00088 template<typename ScalarT, typename SelfT> SelfT&
00089 GenericArithmeticable<ScalarT,SelfT>::operator/=(const SelfT& rhs)
00090 {
00091 return m_child->operatorOpEquals( rhs, std::divides<ScalarT>() );
00092 }
00093
00094 template<typename ScalarT, typename SelfT> SelfT&
00095 GenericArithmeticable<ScalarT,SelfT>::operator/=(const ScalarT& a)
00096 {
00097 return m_child->operatorOpEquals( a, std::divides<ScalarT>() );
00098 }
00099
00100
00101
00102 template< class C >
00103 C operatorOp( const C& c1, const C& c2, C& (C::*op)(const C&) )
00104 {
00105 C result( c1 );
00106 (result.*op)( c2 );
00107 return result;
00108 }
00109
00110
00111 template< class C >
00112 C operatorOpScalar( const C& c1, const typename C::scalar_type& x,
00113 C& (C::*op)(const typename C::scalar_type&) )
00114 {
00115 C result( c1 );
00116 (result.*op)( x );
00117 return result;
00118 }
00119
00120
00121
00122
00123
00124 template<class C> typename C::self_type operator+( const C& c1, const C& c2 )
00125 {
00126 return operatorOp< C >( c1, c2, &C::operator+= );
00127 }
00128 template<class C> typename C::self_type operator-( const C& c1, const C& c2 )
00129 {
00130 return operatorOp< C >( c1, c2, &C::operator-= );
00131 }
00132 template<class C> typename C::self_type operator*( const C& c1, const C& c2 )
00133 {
00134 return operatorOp< C >( c1, c2, &C::operator*= );
00135 }
00136 template<class C> typename C::self_type operator/( const C& c1, const C& c2 )
00137 {
00138 return operatorOp< C >( c1, c2, &C::operator/= );
00139 }
00140
00141
00142
00143
00144
00145 template<class C> typename C::self_type operator+( const C& c, const typename C::scalar_type& x )
00146 {
00147 return operatorOpScalar<C>( c, x, &C::operator+= );
00148 }
00149 template<class C> typename C::self_type operator+( const typename C::scalar_type& x, const C& c )
00150 {
00151 return c + x;
00152 }
00153
00154 template<class C> typename C::self_type operator*( const C& c, const typename C::scalar_type& x )
00155 {
00156 return operatorOpScalar<C>( c, x, &C::operator*= );
00157 }
00158 template<class C> typename C::self_type operator*( const typename C::scalar_type& x, const C& c )
00159 {
00160 return c * x;
00161 }
00162
00163 template<class C> typename C::self_type operator-( const C& c, const typename C::scalar_type& x )
00164 {
00165 return operatorOpScalar<C>( c, x, &C::operator-= );
00166 }
00167 template<class C> typename C::self_type operator-( const typename C::scalar_type& x, const C& c )
00168 {
00169 C temp( c );
00170 return (-temp) + x;
00171 }
00172
00173 template<class C> typename C::self_type operator/( const C& c, const typename C::scalar_type& x )
00174 {
00175 return operatorOpScalar<C>( c, x, &C::operator/= );
00176 }
00177 template<class C> typename C::self_type operator/( const typename C::scalar_type& x, const C& c )
00178 {
00179 C temp( c );
00180 return temp.reciprocal() * x;
00181
00182
00183 }
00184
00185 #include "BaseNamespaceFooter.H"
00186
00187 #endif // include guard