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