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 #ifndef MLN_VALUE_SCALAR_HH
00027 # define MLN_VALUE_SCALAR_HH
00028
00032
00033 # include <mln/value/concept/scalar.hh>
00034 # include <mln/metal/is_a.hh>
00035 # include <mln/metal/if.hh>
00036
00037
00038 namespace mln
00039 {
00040
00041 namespace value
00042 {
00043
00044 template <typename T>
00045 class scalar_ : public Scalar< scalar_<T> >
00046 {
00047 public:
00048
00050 typedef T enc;
00051
00053 typedef T equiv;
00054
00055
00057 scalar_();
00058
00060 explicit scalar_(const T& val);
00061
00063 T to_equiv() const;
00064
00065 protected:
00066 T val_;
00067 };
00068
00069 template <typename T> class scalar_< scalar_<T> >;
00070
00071
00073 template <typename T>
00074 std::ostream& operator<<(std::ostream& ostr, const scalar_<T>& s);
00075
00076
00077
00078
00079
00080 namespace internal
00081 {
00082
00083 template <typename T>
00084 struct helper_scalar_
00085 {
00086 typedef mlc_is_a(T, Scalar) is_scalar_;
00087 typedef mlc_if(is_scalar_, T, scalar_<T>) ret;
00088 };
00089
00090 }
00091
00092
00093
00094 template <typename T>
00095 typename internal::helper_scalar_<T>::ret
00096 scalar(const T& s);
00097
00098
00099
00100
00101 # ifndef MLN_INCLUDE_ONLY
00102
00103
00104
00105 template <typename T>
00106 inline
00107 scalar_<T>::scalar_()
00108 {
00109 }
00110
00111 template <typename T>
00112 inline
00113 scalar_<T>::scalar_(const T& val)
00114 : val_(val)
00115 {
00116 }
00117
00118 template <typename T>
00119 inline
00120 T
00121 scalar_<T>::to_equiv() const
00122 {
00123 return val_;
00124 }
00125
00126
00127
00128 template <typename T>
00129 inline
00130 std::ostream& operator<<(std::ostream& ostr, const scalar_<T>& s)
00131 {
00132 return ostr << s.to_equiv();
00133 }
00134
00135
00136
00137 template <typename T>
00138 inline
00139 typename internal::helper_scalar_<T>::ret
00140 scalar(const T& s)
00141 {
00142 typename internal::helper_scalar_<T>::ret tmp(s);
00143 return tmp;
00144 }
00145
00146 # endif // ! MLN_INCLUDE_ONLY
00147
00148 }
00149
00150 }
00151
00152
00153 #endif // ! MLN_VALUE_SCALAR_HH