5 #include <boost/optional.hpp>
21 template <
typename GenSet>
22 class letterset:
public detail::genset_labelset<GenSet>
31 using word_t =
typename genset_t::word_t;
34 using values_t = std::set<value_t, vcsn::less<self_t>>;
43 :
letterset(std::make_shared<const genset_t>(gs))
62 eat(is,
"letterset<");
63 auto gs = genset_t::make(is);
73 return this->
genset()->open(o);
82 template <
typename... Args>
85 return value_t{std::forward<Args>(args)...};
128 return genset_t::template special<value_t>();
135 return genset_t::equal(l, r);
141 return genset_t::less(l, r);
144 static constexpr
bool
150 static constexpr
bool
156 static constexpr
bool
168 static constexpr
bool
194 *
this,
": conv: invalid label: ",
str_escape(v));
199 template <
typename LabelSet_>
205 *
this,
": conv: invalid label: \\e");
211 conv(std::istream& i,
bool quoted =
true)
const
215 if (i.good() && i.peek() ==
'\\')
219 *
this,
": cannot represent \\e");
234 template <
typename Fun>
235 void convs(std::istream& i, Fun fun)
const
258 raise(*
this,
": lgcd: impossible operation. Arguments: ",
265 raise(*
this,
": ldivide: impossible operation. Arguments: ",
269 boost::optional<value_t>
272 raise(*
this,
": maybe_ldivide: impossible operation. Arguments: ",
279 raise(*
this,
": rdivide: impossible operation. Arguments: ",
283 boost::optional<value_t>
286 raise(*
this,
": maybe_rdivide: impossible operation. Arguments: ",
296 raise(
"conjunction: invalid operation (lhs and rhs are not equal)."
305 return this->
genset()->print(l, o, fmt);
314 this->
genset()->print_set(o, fmt);
318 this->
genset()->print_set(o, fmt);
323 this->genset()->print_set(o, fmt);
336 template <typename GenSet>
337 struct letterized_traits<letterset<GenSet>>
339 static constexpr bool is_letterized = true;
341 using labelset_t = nullableset<letterset<GenSet>>;
343 static labelset_t labelset(const letterset<GenSet>& ls)
345 return {ls.genset()};
350 template <typename GenSet>
351 struct nullableset_traits<letterset<GenSet>>
353 using type = nullableset<letterset<GenSet>>;
354 static type value(const letterset<GenSet>& ls)
361 template <typename GenSet>
362 struct law_traits<letterset<GenSet>>
364 using type = wordset<GenSet>;
365 static type value(const letterset<GenSet>& ls)
375 template <typename GenSet>
376 struct join_impl<letterset<GenSet>, letterset<GenSet>>
378 using type = letterset<GenSet>;
379 static type join(const letterset<GenSet>& lhs,
380 const letterset<GenSet>& rhs)
382 return {set_union(*lhs.genset(), *rhs.genset())};
388 template <typename GenSet>
390 meet(const letterset<GenSet>& lhs, const letterset<GenSet>& rhs)
392 return {set_intersection(*lhs.genset(), *rhs.genset())};
value_t conv(const nullableset< LabelSet_ > &ls, typename nullableset< LabelSet_ >::value_t v) const
Convert from nullableset to letterset.
std::set< value_t, vcsn::less< self_t >> values_t
value_t conjunction(const value_t l, const value_t r) const
static letterset make(std::istream &is)
Build from the description in is.
char eat(std::istream &is, char c)
Check lookahead character and advance.
Print as a parsable type string.
static constexpr bool is_letterized()
static constexpr bool is_expressionset()
boost::optional< value_t > maybe_rdivide(const value_t l, const value_t r) const
value_t ldivide(const value_t l, const value_t r) const
Compute w1 \ w2 = w1^{-1}w2.
std::ostream & print(const value_t &l, std::ostream &o=std::cout, format fmt={}) const
letterset(std::initializer_list< letter_t > letters)
value_t conv(self_t, value_t v) const
static bool equal(const value_t l, const value_t r)
Whether l == r.
value_t lgcd(const value_t l, const value_t r) const
The longest common prefix.
typename genset_t::letter_t letter_t
value_t value(Args &&...args) const
Value constructor.
void convs_(std::istream &i, Fun fun) const
Read and process a class of letters.
An input/output format for valuesets.
letterset(const genset_ptr &gs)
static size_t hash(value_t v)
void require(Bool b, Args &&...args)
If b is not verified, raise an error with args as message.
typename genset_t::letter_t letter_t
Provide a variadic mul on top of a binary mul(), and one().
genset_ptr genset() const
boost::flyweight< std::string, boost::flyweights::no_tracking, boost::flyweights::intermodule_holder > symbol
An internalized string.
auto hash_value(const T &v) -> decltype(std::hash< T >
Following the naming convention of Boost.
static constexpr bool has_one()
static constexpr bool is_free()
value_t conv(std::istream &i, bool quoted=true) const
Read one letter from i, return the corresponding label.
typename genset_t::word_t word_t
#define VCSN_REQUIRE(Cond,...)
A macro similar to require.
typename genset_t::word_t word_t
static constexpr bool is_one(value_t)
This class has no modeling purpose, it only serves to factor code common to letterset and wordset...
Implementation of labels are nullables (letter or empty).
typename helper_t::value_t value_t
static word_t letters_of(word_t v)
Prepare to iterate over the letters of v.
static word_t letters_of_padded(word_t v, letter_t)
Prepare to iterate over the letters of v.
std::shared_ptr< const genset_t > genset_ptr
bool open(bool o) const
Whether unknown letters should be added, or rejected.
std::ostream & print_set(std::ostream &o, format fmt={}) const
std::ostream & str_escape(std::ostream &os, const std::string &str, const char *special=nullptr)
Output a string, escaping special characters.
ATTRIBUTE_PURE auto has(Args &&...args) const -> decltype(this->genset() -> has(std::forward< Args >(args)...))
static word_t letters_of(letter_t v)
Prepare to iterate over v.
static ATTRIBUTE_PURE bool is_one(value_t l)
static value_t special() ATTRIBUTE_PURE
void convs(std::istream &i, Fun fun) const
Process a label class.
Implementation of labels are letters.
std::string to_string(direction d)
Conversion to string.
static size_t size(value_t)
boost::optional< value_t > maybe_ldivide(const value_t l, const value_t r) const
static word_t letters_of_padded(letter_t v, letter_t)
Prepare to iterate over v.
const labelset_ptr labelset() const
static labelset_t::value_t get_value(const value_t &v)
The (inner) value when it (the outer value) is not one.
letterset(const genset_t &gs={})
static bool less(const value_t l, const value_t r)
Whether l < r.
static word_t word(value_t v)
Convert to a word.
bool is_valid(value_t v) const
letter_t get_letter(std::istream &i, bool quoted=true) const
Read one letter from i.
value_t rdivide(const value_t l, const value_t r) const
Compute w1 / w2.
static bool is_special(value_t v) ATTRIBUTE_PURE