00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef MLN_VALUE_MIXIN_HH
00028 # define MLN_VALUE_MIXIN_HH
00029
00030 # include <mln/core/concept/function.hh>
00031 # include <mln/core/concept/image.hh>
00032 # include <mln/value/internal/value_like.hh>
00033
00034 namespace mln
00035 {
00036
00037 namespace value
00038 {
00039 template <typename T, typename F>
00040 struct mixin;
00041 }
00042
00043 namespace trait
00044 {
00045
00046 template <typename T, typename F>
00047 struct value_< mln::value::mixin<T, F> >
00048 : value_< T >
00049 {
00050 static const T max()
00051 {
00052 static const F f = F();
00053 return f.max();
00054 }
00055 };
00056
00057 }
00058
00059
00060 namespace value
00061 {
00062
00063 template <typename T, typename F>
00064 struct mixin : T
00065 {
00066
00067
00068 mixin()
00069 {
00070 }
00071
00072 mixin(const T& t)
00073 : T(t)
00074 {
00075 }
00076
00077 mixin(const mixin& rhs)
00078 : T(rhs)
00079 {
00080 }
00081
00082 mixin& operator=(const mixin& rhs)
00083 {
00084
00085 this->T::operator=(rhs);
00086 return *this;
00087 }
00088
00089 mixin& operator=(const T& t)
00090 {
00091
00092 this->T::operator=(t);
00093 return *this;
00094 }
00095 };
00096
00097 }
00098
00099
00100 template <typename T, typename F>
00101 bool operator < (const value::mixin<T,F>& lhs, const value::mixin<T,F>& rhs)
00102 {
00103 static F f;
00104 return f.less(lhs, rhs);
00105 }
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116 template <typename T, typename F>
00117 bool operator == (const value::mixin<T,F>& lhs, const value::mixin<T,F>& rhs)
00118 {
00119 static F f;
00120 return !(f.less(lhs, rhs) || f.less(rhs, lhs));
00121 }
00122
00123 template <typename T, typename F>
00124 bool operator <= (const value::mixin<T,F>& lhs, const value::mixin<T,F>& rhs)
00125 {
00126 static F f;
00127 return f.less(lhs, rhs) || lhs == rhs;
00128 }
00129
00130 template <typename T, typename F>
00131 bool operator > (const value::mixin<T,F>& lhs, const value::mixin<T,F>& rhs)
00132 {
00133 static F f;
00134 return ! (f.less(lhs, rhs) || lhs == rhs);
00135 }
00136
00137 template <typename T, typename F>
00138 bool operator >= (const value::mixin<T,F>& lhs, const value::mixin<T,F>& rhs)
00139 {
00140 static F f;
00141 return ! f.less(lhs, rhs);
00142 }
00143
00144 # ifndef MLN_INCLUDE_ONLY
00145
00146 # endif // MLN_INCLUDE_ONLY
00147
00148 };
00149
00150 #endif // ! MLN_VALUE_MIXIN_HH