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);
92 template <
typename... Args>
95 return value_t{std::forward<Args>(args)...};
138 return genset_t::template special<value_t>();
151 return genset_t::equal(l, r);
157 return genset_t::less(l, r);
160 static constexpr
bool 166 static constexpr
bool 172 static constexpr
bool 184 static constexpr
bool 210 *
this,
": conv: invalid label: ",
str_escape(v));
215 template <
typename LabelSet_>
221 *
this,
": conv: invalid label: \\e");
227 conv(std::istream& i,
bool quoted =
true)
const 231 if (i.good() && i.peek() ==
'\\')
235 *
this,
": cannot represent \\e");
250 template <
typename Fun>
251 void convs(std::istream& i, Fun fun)
const 274 raise(*
this,
": lgcd: impossible operation. Arguments: ",
281 raise(*
this,
": ldivide: impossible operation. Arguments: ",
285 boost::optional<value_t>
288 raise(*
this,
": maybe_ldivide: impossible operation. Arguments: ",
295 raise(*
this,
": rdivide: impossible operation. Arguments: ",
299 boost::optional<value_t>
302 raise(*
this,
": maybe_rdivide: impossible operation. Arguments: ",
312 raise(
"conjunction: invalid operation (lhs and rhs are not equal)." 321 return this->
genset()->print(l, o, fmt);
330 this->
genset()->print_set(o, fmt);
334 this->
genset()->print_set(o, fmt);
339 this->genset()->print_set(o, fmt); 352 template <typename GenSet> 353 struct letterized_traits<letterset<GenSet>> 355 static constexpr bool is_letterized = true; 357 using labelset_t = nullableset<letterset<GenSet>>; 359 static labelset_t labelset(const letterset<GenSet>& ls) 361 return {ls.genset()}; 366 template <typename GenSet> 367 struct nullableset_traits<letterset<GenSet>> 369 using type = nullableset<letterset<GenSet>>; 370 static type value(const letterset<GenSet>& ls) 377 template <typename GenSet> 378 struct law_traits<letterset<GenSet>> 380 using type = wordset<GenSet>; 381 static type value(const letterset<GenSet>& ls) 391 template <typename GenSet> 392 struct join_impl<letterset<GenSet>, letterset<GenSet>> 394 using type = letterset<GenSet>; 395 static type join(const letterset<GenSet>& lhs, 396 const letterset<GenSet>& rhs) 398 return {set_union(*lhs.genset(), *rhs.genset())}; 404 template <typename GenSet> 406 meet(const letterset<GenSet>& lhs, const letterset<GenSet>& rhs) 408 return {set_intersection(*lhs.genset(), *rhs.genset())};
Print as a parsable type string.
std::ostream & print(const value_t &l, std::ostream &o=std::cout, format fmt={}) const
static bool equal(const value_t l, const value_t r)
Whether l == r.
static value_t special() ATTRIBUTE_PURE
Implementation of labels are letters.
auto generators(Args &&... args) const -> decltype(this->genset() -> generators(std::forward< Args >(args)...))
value_t conv(const nullableset< LabelSet_ > &ls, typename nullableset< LabelSet_ >::value_t v) const
Convert from nullableset to letterset.
static word_t letters_of_padded(letter_t v, letter_t)
Prepare to iterate over v.
boost::optional< value_t > maybe_rdivide(const value_t l, const value_t r) const
char eat(std::istream &is, char c)
Check lookahead character and advance.
typename genset_t::word_t word_t
value_t rdivide(const value_t l, const value_t r) const
Compute w1 / w2.
value_t conv(std::istream &i, bool quoted=true) const
Read one letter from i, return the corresponding label.
static int compare(const value_t l, const value_t r)
Three-way comparison between l and r.
auto pregenerators() const
static constexpr bool is_one(value_t)
letterset(std::initializer_list< letter_t > letters)
std::ostream & str_escape(std::ostream &os, const std::string &str, const char *special=nullptr)
Output a string, escaping special characters.
boost::flyweight< std::string, boost::flyweights::no_tracking, boost::flyweights::intermodule_holder > symbol
An internalized string.
static constexpr bool is_free()
static word_t letters_of(letter_t v)
Prepare to iterate over v.
value_t value(Args &&... args) const
Value constructor.
std::ostream & print_set(std::ostream &o, format fmt={}) const
bool open(bool o) const
Whether unknown letters should be added, or rejected.
bool is_valid(value_t v) const
value_t conjunction(const value_t l, const value_t r) const
static bool is_special(value_t v) ATTRIBUTE_PURE
An input/output format for valuesets.
Provide a variadic mul on top of a binary mul(), and one().
static constexpr bool is_letterized()
static constexpr bool has_one()
void convs(std::istream &i, Fun fun) const
Process a label class.
value_t ldivide(const value_t l, const value_t r) const
Compute w1 \ w2 = w1^{-1}w2.
typename helper_t::value_t value_t
static size_t hash(value_t v)
auto hash_value(const T &v) -> decltype(std::hash< T >
Following the naming convention of Boost.
This class has no modeling purpose, it only serves to factor code common to letterset and wordset...
ATTRIBUTE_PURE auto has(Args &&... args) const -> decltype(this->genset() -> has(std::forward< Args >(args)...))
value_t lgcd(const value_t l, const value_t r) const
The longest common prefix.
Implementation of labels are nullables (letter or empty).
static bool less(const value_t l, const value_t r)
Whether l < r.
std::set< value_t, vcsn::less< self_t > > values_t
const labelset_ptr labelset() const
static constexpr bool is_expressionset()
genset_ptr genset() const
static letterset make(std::istream &is)
Build from the description in is.
static ATTRIBUTE_PURE bool is_one(value_t l)
typename genset_t::letter_t letter_t
letter_t get_letter(std::istream &i, bool quoted=true) const
Read one letter from i.
static word_t letters_of_padded(word_t v, letter_t)
Prepare to iterate over the letters of v.
letterset(const genset_ptr &gs)
void convs_(std::istream &i, Fun fun) const
Read and process a class of letters.
typename genset_t::letter_t letter_t
static size_t size(value_t)
std::shared_ptr< const genset_t > genset_ptr
void require(Bool b, Args &&... args)
If b is not verified, raise an error with args as message.
std::string to_string(direction d)
Conversion to string.
value_t conv(self_t, value_t v) const
static word_t letters_of(word_t v)
Prepare to iterate over the letters of v.
#define VCSN_REQUIRE(Cond,...)
A macro similar to require.
int compare(const Lhs &lhs, const Rhs &rhs)
Comparison between lhs and rhs.
letterset(const genset_t &gs={})
static word_t word(value_t v)
Convert to a word.
static labelset_t::value_t get_value(const value_t &v)
The (inner) value when it (the outer value) is not one.
boost::optional< value_t > maybe_ldivide(const value_t l, const value_t r) const