Vcsn  2.4
Be Rational
nmin.hh
Go to the documentation of this file.
1 #pragma once
2 
3 #include <vcsn/core/join.hh>
4 #include <vcsn/misc/raise.hh>
5 #include <vcsn/misc/stream.hh> // eat
6 #include <vcsn/weightset/fwd.hh>
9 
10 namespace vcsn
11 {
12  namespace detail
13  {
14  class nmin_impl
15  : public min_plus_impl<nmin_impl, unsigned int>
16  {
17  public:
19  using self_t = nmin;
20  using value_t = typename super_t::value_t;
21 
22  static symbol sname()
23  {
24  static auto res = symbol{"nmin"};
25  return res;
26  }
27 
29  static nmin make(std::istream& is)
30  {
31  eat(is, sname());
32  return {};
33  }
34 
35  using super_t::conv;
36  static value_t
38  {
39  return v;
40  }
41 
42  value_t
43  conv(std::istream& is, bool = true) const
44  {
45  if (is.peek() == '-')
46  fail_reading(is, *this, ": negative values are invalid");
47  else
48  return super_t::conv(is);
49  }
50 
51  static constexpr bool has_lightening_weights() { return false; }
52 
53  std::ostream&
54  print_set(std::ostream& o, format fmt = {}) const
55  {
56  switch (fmt.kind())
57  {
58  case format::latex:
59  o << "\\mathbb{N}_{\\text{min}}";
60  break;
61  case format::sname:
62  o << sname();
63  break;
64  case format::text:
65  o << "Nmin";
66  break;
67  case format::utf8:
68  o << "â„•min";
69  break;
70  case format::raw:
71  assert(0);
72  break;
73  }
74  return o;
75  }
76  };
77 
78  // Random generation.
79  template <typename RandomGenerator>
80  class random_weight<nmin, RandomGenerator>
81  : public random_weight_base<nmin, RandomGenerator>
82  {
83  public:
85  using value_t = typename super_t::weight_t;
86 
87  using super_t::super_t;
88 
89  private:
91  {
92  auto dis =
93  std::uniform_int_distribution<nmin::value_t>(super_t::min_, super_t::max_);
94  return dis(super_t::gen_);
95  }
96  };
97 
100  }
101 
102  template <>
103  struct is_tropical<nmin> : std::true_type
104  {};
105 }
Print as is. For instance, don't try to escape labels.
Definition: format.hh:24
char eat(std::istream &is, char c)
Check lookahead character and advance.
Definition: stream.cc:90
Print as a parsable type string.
Definition: format.hh:26
Generic declaration of the class which is specialized in each weightset.
Definition: weightset.hh:205
static constexpr bool has_lightening_weights()
Definition: nmin.hh:51
return res
Definition: multiply.hh:398
VCSN_JOIN_SIMPLE(b, b)
Print for LaTeX.
Definition: format.hh:22
An input/output format for valuesets.
Definition: format.hh:13
Abstract class for random weight generation.
Definition: weightset.hh:112
typename super_t::value_t value_t
Definition: nmin.hh:20
Provide a variadic mul on top of a binary mul(), and one().
Definition: fwd.hh:46
boost::flyweight< std::string, boost::flyweights::no_tracking, boost::flyweights::intermodule_holder > symbol
An internalized string.
Definition: symbol.hh:23
static nmin make(std::istream &is)
Build from the description in is.
Definition: nmin.hh:29
Definition: a-star.hh:8
static symbol sname()
Definition: nmin.hh:22
Print as rich UTF-8 text, escaped.
Definition: format.hh:30
Print as plain (ASCII) text, escaped.
Definition: format.hh:28
weightset_mixin< detail::nmin_impl > nmin
Definition: fwd.hh:51
ATTRIBUTE_NORETURN void fail_reading(std::istream &is, Args &&...args)
Throw an exception after failing to read from is.
Definition: stream.hh:68
std::ostream & print_set(std::ostream &o, format fmt={}) const
Definition: nmin.hh:54
value_t conv(std::istream &is, bool=true) const
Definition: nmin.hh:43
static value_t conv(self_t, value_t v)
Definition: nmin.hh:37