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_OTHER_HH
00027 # define MLN_VALUE_OTHER_HH
00028 
00034 # include <mln/core/concept/value.hh>
00035 # include <mln/value/set.hh>
00036 # include <mln/value/concept/all.hh>
00037 
00038 
00039 namespace mln
00040 {
00041 
00042   namespace value
00043   {
00044 
00045 
00047     template <typename V>
00048     V other(const V& val);
00049 
00050 
00051 
00052 # ifndef MLN_INCLUDE_ONLY
00053 
00054     namespace internal
00055     {
00056 
00057       template <typename V>
00058       V
00059       other_(const void*, const V& val) 
00060       {
00061         return val + 1;
00062       }
00063 
00064       inline
00065       bool
00066       other_(const void*, const bool& val)
00067       {
00068         return ! val;
00069       }
00070 
00071 
00072       template <typename V>
00073       inline
00074       V
00075       other_(mln::trait::value::quant::high, const Value<V>& val_)
00076       {
00077         const V& val = exact(val_);
00078         return val.other();
00079       }
00080 
00081       template <typename V>
00082       inline
00083       V
00084       other_(mln::trait::value::quant::high, const value::Scalar<V>& val_)
00085       {
00086         const V& val = exact(val_);
00087         return (mln_max(V) - val) + mln_min(V);
00088       }
00089 
00090       template <typename V>
00091       inline
00092       V
00093       other_(mln::trait::value::quant::low, const Value<V>& val_)
00094       {
00095         const V& val = exact(val_);
00096         value::set<V> s;
00097         unsigned i = s.index_of(val);
00098         mln_assertion(s.nvalues() >= 2);
00099         return i == 0 ? s[1] : s[0];
00100       }
00101 
00102       template <typename V>
00103       inline
00104       V
00105       other_(const Value<V>*, const V& val)
00106       {
00107         return other_(mln_trait_value_quant(V)(), val);
00108       }
00109 
00110     } 
00111 
00112 
00113     template <typename V>
00114     inline
00115     V other(const V& val)
00116     {
00117       V tmp = internal::other_(&val, val);
00118       mln_postcondition(tmp != val);
00119       return tmp;
00120     }
00121 
00122 # endif // ! MLN_INCLUDE_ONLY
00123 
00124   } 
00125 
00126 } 
00127 
00128 
00129 #endif // ! MLN_VALUE_OTHER_HH