Vcsn  2.2a
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<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  static value_t
43  conv(std::istream& is, bool = true)
44  {
45  if (is.peek() == '-')
46  fail_reading(is, sname(), ": negative values are invalid");
47  return super_t::conv(is);
48  }
49 
50  static constexpr bool has_lightening_weights() { return false; }
51 
52  std::ostream&
53  print_set(std::ostream& o, format fmt = {}) const
54  {
55  switch (fmt.kind())
56  {
57  case format::latex:
58  o << "\\mathbb{N}_{\\text{min}}";
59  break;
60  case format::sname:
61  o << sname();
62  break;
63  case format::text:
64  o << "Nmin";
65  break;
66  case format::utf8:
67  o << "â„•min";
68  break;
69  case format::raw:
70  assert(0);
71  break;
72  }
73  return o;
74  }
75  };
76 
79  }
80 
81  template <>
82  struct is_tropical<nmin> : std::true_type
83  {};
84 }
static value_t conv(b, b::value_t v)
Definition: min-plus.hh:122
std::istringstream is
The input stream: the specification to translate.
Definition: translate.cc:380
static value_t conv(self_t, value_t v)
Definition: nmin.hh:37
Provide a variadic mul on top of a binary mul(), and one().
Definition: fwd.hh:46
VCSN_JOIN_SIMPLE(b, b)
boost::flyweight< std::string, boost::flyweights::no_tracking, boost::flyweights::intermodule_holder > symbol
An internalized string.
Definition: symbol.hh:23
Print as plain (ASCII) text, escaped.
Definition: format.hh:26
static value_t conv(std::istream &is, bool=true)
Definition: nmin.hh:43
weightset_mixin< detail::b_impl > b
Definition: fwd.hh:48
Print as a parsable type string.
Definition: format.hh:24
Print for LaTeX.
Definition: format.hh:20
std::ostream & print_set(std::ostream &o, format fmt={}) const
Definition: nmin.hh:53
static nmin make(std::istream &is)
Build from the description in is.
Definition: nmin.hh:29
Print as is. For instance, don't try to escape labels.
Definition: format.hh:22
weightset_mixin< detail::nmin_impl > nmin
Definition: fwd.hh:51
char eat(std::istream &is, char c)
Check lookahead character and advance.
Definition: stream.cc:37
typename super_t::value_t value_t
Definition: nmin.hh:20
Print as rich UTF-8 text, escaped.
Definition: format.hh:28
static constexpr bool has_lightening_weights()
Definition: nmin.hh:50
static symbol sname()
Definition: nmin.hh:22
An input/output format for valuesets.
Definition: format.hh:11
Definition: a-star.hh:8
ATTRIBUTE_NORETURN void fail_reading(std::istream &is, Args &&...args)
Throw an exception after failing to read from is.
Definition: stream.hh:62