27 #ifndef MLN_VALUE_LABEL_HH
28 # define MLN_VALUE_LABEL_HH
34 # include <mln/debug/format.hh>
35 # include <mln/metal/math/pow.hh>
36 # include <mln/trait/value_.hh>
37 # include <mln/value/concept/symbolic.hh>
38 # include <mln/value/internal/value_like.hh>
39 # include <mln/value/internal/convert.hh>
40 # include <mln/value/internal/encoding.hh>
42 # include <mln/value/internal/make_generic_name.hh>
49 template <
unsigned n>
struct label;
50 template <
unsigned n>
struct int_u;
62 struct value_< mln::value::label<n> >
72 card = mln_value_card_from_(n)
75 typedef trait::value::nature::symbolic nature;
76 typedef trait::value::kind::label kind;
77 typedef mln_value_quant_from_(card) quant;
79 static const self_ min() {
return 0; }
80 static const self_
max() {
return mlc_pow_int(2, n) - 1; }
82 static const char* name()
85 s = mln::value::internal::make_generic_name(
"label_", n);
89 typedef unsigned comp;
102 template <
unsigned n>
104 from_to_(
const value::int_u<n>& from, value::label<n>& to_);
107 template <
unsigned n>
109 from_to_(
const value::label<n>& from, value::int_u<n>& to_);
113 template <
unsigned n,
unsigned m>
115 from_to_(
const value::int_u<n>& from, value::label<m>& to_);
118 template <
unsigned n>
120 from_to_(
const value::label<n>& from,
bool& to_);
123 template <
unsigned n>
125 from_to_(
const value::label<n>& from,
unsigned& to_);
139 template <
unsigned n>
141 :
public Symbolic< label<n> >,
142 public internal::value_like_< unsigned,
143 typename internal::encoding_unsigned_<n>::ret,
150 typedef typename internal::encoding_unsigned_<n>::ret
enc;
162 operator unsigned()
const;
186 template <>
struct label<0>;
187 template <>
struct label<1>;
196 template <
unsigned n>
197 std::ostream& operator<<(std::ostream& ostr, const label<n>& l);
203 # ifndef MLN_INCLUDE_ONLY
213 template <
unsigned n>
222 template <
unsigned n>
224 from_to_(
const value::label<n>& from, value::int_u<n>& to_)
231 template <
unsigned n,
unsigned m>
234 from_to_(
const value::int_u<n>& from, value::label<m>& to_)
236 enum { valid = n < m };
237 metal::bool_<valid>::check();
242 template <
unsigned n>
245 from_to_(
const value::label<n>& from,
bool& to_)
251 template <
unsigned n>
254 from_to_(
const value::label<n>& from,
unsigned& to_)
269 template <
unsigned n>
275 template <
unsigned n>
282 template <
unsigned n>
289 template <
unsigned n>
293 return this->to_enc();
296 template <
unsigned n>
301 mln_precondition(i <= mln_max(enc));
306 template <
unsigned n>
315 template <
unsigned n>
320 mln_precondition(this->v_ < mln_max(enc));
325 template <
unsigned n>
330 mln_precondition(this->v_ != 0);
335 template <
unsigned n>
343 template <
unsigned n>
351 template <
unsigned n>
353 std::ostream& operator<<(std::ostream& ostr, const label<n>& i)
361 # endif // ! MLN_INCLUDE_ONLY
366 #endif // ! MLN_VALUE_LABEL_HH