Vcsn  2.1
Be Rational
oneset.hh
Go to the documentation of this file.
1 #pragma once
2 
3 #include <iostream>
4 #include <set>
5 #include <stdexcept>
6 
7 #include <vcsn/core/kind.hh>
8 #include <vcsn/misc/empty.hh>
10 #include <vcsn/misc/functional.hh>
11 #include <vcsn/misc/raise.hh>
12 
13 namespace vcsn
14 {
17  class oneset
18  {
19  public:
20  using self_t = oneset;
22 
24 
25  oneset() = default;
26 
27  static symbol sname()
28  {
29  static symbol res("lao");
30  return res;
31  }
32 
34  static oneset make(std::istream& is)
35  {
36  kind_t::make(is);
37  return {};
38  }
39 
41  bool open(bool o) const
42  {
43  return !o;
44  }
45 
46  static constexpr bool is_free()
47  {
48  // This is debatable. However, in Vaucanson, if a labelset
49  // is_free, then we expect to be able to iterate on its genset,
50  // and I don't plan to provide a genset here.
51  return false;
52  }
53 
55  template <typename... Args>
56  value_t value(Args&&... args) const
57  {
58  return value_t{std::forward<Args>(args)...};
59  }
60 
62  static bool
63  equal(const value_t, const value_t)
64  {
65  return true;
66  }
67 
69  static bool less(const value_t, const value_t)
70  {
71  return false;
72  }
73 
74  static value_t special()
75  {
76  return {};
77  }
78 
80  constexpr static bool
82  {
83  return true;
84  }
85 
86  static constexpr bool
88  {
89  return false;
90  }
91 
92  static constexpr bool
94  {
95  return true;
96  }
97 
98  static constexpr bool
100  {
101  return false;
102  }
103 
104  static empty_t one()
105  {
106  return {};
107  }
108 
109  static bool is_one(empty_t)
110  {
111  return true;
112  }
113 
115  {
116  return {};
117  }
118 
119  static bool is_letter(empty_t)
120  {
121  return false;
122  }
123 
125  {
126  return {};
127  }
128 
129  static std::ostream& print(empty_t, std::ostream& o,
130  format = {})
131  {
132  return o;
133  }
134 
135  static size_t size(value_t)
136  {
137  return 0;
138  }
139 
140  static size_t hash(value_t v)
141  {
142  return hash_value(v);
143  }
144 
145  static value_t
147  {
148  return v;
149  }
150 
152  template <typename LabelSet>
153  value_t
154  conv(const LabelSet& ls,
155  typename LabelSet::value_t v) const
156  {
157  require(ls.is_one(v),
158  sname(), ": conv: invalid label: ", to_string(ls, v));
159  return {};
160  }
161 
162 
163  static value_t conv(std::istream& i, bool = true)
164  {
165  if (i.peek() == '\\')
166  {
167  i.ignore();
168  char c = i.peek();
169  require(c == 'e',
170  "invalid label: unexpected \\", c);
171  i.ignore();
172  }
173  return {};
174  }
175 
176  template <typename Fun>
177  static void convs(std::istream&, Fun)
178  {
179  raise("oneset: ranges not implemented");
180  }
181 
182  std::ostream&
183  print_set(std::ostream& o, format fmt = {}) const
184  {
185  if (fmt == format::latex)
186  o << "1";
187  else if (fmt == format::text)
188  o << sname();
189  else
190  raise("invalid format: ", fmt);
191  return o;
192  }
193  };
194 
195  namespace detail
196  {
198  template <>
200  {
201  using type = oneset;
202  static type value(oneset)
203  {
204  return {};
205  }
206  };
207 
209  template <>
211  {
212  using type = oneset;
213  static type value(oneset)
214  {
215  return {};
216  }
217  };
218 
219  /*-------.
220  | Join. |
221  `-------*/
222 
223  template <>
225  {
226  using type = oneset;
227  static type join(const oneset&, const oneset&)
228  {
229  return {};
230  }
231  };
232  }
233 
235  inline
236  oneset
237  meet(const oneset&, const oneset&)
238  {
239  return {};
240  }
241 }
value_t value(Args &&...args) const
Value constructor.
Definition: oneset.hh:56
static type join(const oneset &, const oneset &)
Definition: oneset.hh:227
static bool is_letter(empty_t)
Definition: oneset.hh:119
static constexpr bool is_special(value_t)
The special label is indistinguishable for the others.
Definition: oneset.hh:81
static constexpr bool is_free()
Definition: oneset.hh:46
static std::ostream & print(empty_t, std::ostream &o, format={})
Definition: oneset.hh:129
static void make(std::istream &is)
Definition: kind.hh:49
value_t conv(const LabelSet &ls, typename LabelSet::value_t v) const
Convert from labelset to oneset.
Definition: oneset.hh:154
A structure that implements the computation of join(V1, V2).
Definition: join.hh:18
std::istringstream is
The input stream: the specification to translate.
Definition: translate.cc:372
Empty labels, for LAO.
Definition: empty.hh:8
static empty_t one()
Definition: oneset.hh:104
static empty_t mul(empty_t, empty_t)
Definition: oneset.hh:124
vcsn::empty_t value_t
Definition: oneset.hh:21
static constexpr bool is_expressionset()
Definition: oneset.hh:87
std::ostream & print_set(std::ostream &o, format fmt={}) const
Definition: oneset.hh:183
auto hash_value(const T &v) -> decltype(std::hash< T >
Following the naming convention of Boost.
Definition: functional.hh:63
static oneset make(std::istream &is)
Build from the description in is.
Definition: oneset.hh:34
static value_t conv(std::istream &i, bool=true)
Definition: oneset.hh:163
An input/output format.
Definition: format.hh:11
static constexpr bool has_one()
Definition: oneset.hh:93
Implementation of labels are ones: there is a single instance of label.
Definition: oneset.hh:17
static symbol sname()
Definition: oneset.hh:27
void require(bool b, Args &&...args)
If b is not verified, raise an error with args as message.
Definition: raise.hh:75
bool open(bool o) const
Does not make a lot of sense.
Definition: oneset.hh:41
static size_t hash(value_t v)
Definition: oneset.hh:140
std::string to_string(direction d)
Conversion to string.
Definition: direction.cc:7
static empty_t transpose(empty_t)
Definition: oneset.hh:114
static bool less(const value_t, const value_t)
Whether l < r.
Definition: oneset.hh:69
boost::flyweight< std::string, boost::flyweights::no_tracking, boost::flyweights::intermodule_holder > symbol
An internalized string.
Definition: symbol.hh:23
static value_t conv(self_t, value_t v)
Definition: oneset.hh:146
The smallest nullableset which includes LabelSet.
Definition: labelset.hh:140
auto meet(const expressionset< Ctx1 > &a, const expressionset< Ctx2 > &b) -> expressionset< meet_t< Ctx1, Ctx2 >>
The meet of two expressionsets.
static bool is_one(empty_t)
Definition: oneset.hh:109
static constexpr bool is_letterized()
Definition: oneset.hh:99
static void convs(std::istream &, Fun)
Definition: oneset.hh:177
static type value(oneset)
Definition: oneset.hh:213
static value_t special()
Definition: oneset.hh:74
static bool equal(const value_t, const value_t)
Whether l == r.
Definition: oneset.hh:63
oneset()=default
static size_t size(value_t)
Definition: oneset.hh:135
The LAW from a LAL.
Definition: labelset.hh:251