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>();
141 return genset_t::equal(l, r);
147 return genset_t::less(l, r);
150 static constexpr
bool 156 static constexpr
bool 162 static constexpr
bool 174 static constexpr
bool 200 *
this,
": conv: invalid label: ",
str_escape(v));
205 template <
typename LabelSet_>
211 *
this,
": conv: invalid label: \\e");
217 conv(std::istream& i,
bool quoted =
true)
const 221 if (i.good() && i.peek() ==
'\\')
225 *
this,
": cannot represent \\e");
240 template <
typename Fun>
241 void convs(std::istream& i, Fun fun)
const 264 raise(*
this,
": lgcd: impossible operation. Arguments: ",
271 raise(*
this,
": ldivide: impossible operation. Arguments: ",
275 boost::optional<value_t>
278 raise(*
this,
": maybe_ldivide: impossible operation. Arguments: ",
285 raise(*
this,
": rdivide: impossible operation. Arguments: ",
289 boost::optional<value_t>
292 raise(*
this,
": maybe_rdivide: impossible operation. Arguments: ",
302 raise(
"conjunction: invalid operation (lhs and rhs are not equal)." 311 return this->
genset()->print(l, o, fmt);
320 this->
genset()->print_set(o, fmt);
324 this->
genset()->print_set(o, fmt);
329 this->genset()->print_set(o, fmt); 342 template <typename GenSet> 343 struct letterized_traits<letterset<GenSet>> 345 static constexpr bool is_letterized = true; 347 using labelset_t = nullableset<letterset<GenSet>>; 349 static labelset_t labelset(const letterset<GenSet>& ls) 351 return {ls.genset()}; 356 template <typename GenSet> 357 struct nullableset_traits<letterset<GenSet>> 359 using type = nullableset<letterset<GenSet>>; 360 static type value(const letterset<GenSet>& ls) 367 template <typename GenSet> 368 struct law_traits<letterset<GenSet>> 370 using type = wordset<GenSet>; 371 static type value(const letterset<GenSet>& ls) 381 template <typename GenSet> 382 struct join_impl<letterset<GenSet>, letterset<GenSet>> 384 using type = letterset<GenSet>; 385 static type join(const letterset<GenSet>& lhs, 386 const letterset<GenSet>& rhs) 388 return {set_union(*lhs.genset(), *rhs.genset())}; 394 template <typename GenSet> 396 meet(const letterset<GenSet>& lhs, const letterset<GenSet>& rhs) 398 return {set_intersection(*lhs.genset(), *rhs.genset())}; typename helper_t::value_t value_t
This class has no modeling purpose, it only serves to factor code common to letterset and wordset...
value_t conv(const nullableset< LabelSet_ > &ls, typename nullableset< LabelSet_ >::value_t v) const
Convert from nullableset to letterset.
Print as a parsable type string.
Implementation of labels are nullables (letter or empty).
letterset(const genset_t &gs={})
std::ostream & print_set(std::ostream &o, format fmt={}) const
bool open(bool o) const
Whether unknown letters should be added, or rejected.
static constexpr bool is_letterized()
static constexpr bool has_one()
value_t value(Args &&... args) const
Value constructor.
static word_t letters_of_padded(word_t v, letter_t)
Prepare to iterate over the letters of v.
typename genset_t::letter_t letter_t
static word_t word(value_t v)
Convert to a word.
static value_t special() ATTRIBUTE_PURE
genset_ptr genset() const
typename genset_t::letter_t letter_t
static bool less(const value_t l, const value_t r)
Whether l < r.
value_t ldivide(const value_t l, const value_t r) const
Compute w1 \ w2 = w1^{-1}w2.
boost::flyweight< std::string, boost::flyweights::no_tracking, boost::flyweights::intermodule_holder > symbol
An internalized string.
value_t conjunction(const value_t l, const value_t r) const
static constexpr bool is_free()
static word_t letters_of(letter_t v)
Prepare to iterate over v.
auto hash_value(const T &v) -> decltype(std::hash< T >
Following the naming convention of Boost.
value_t conv(self_t, value_t v) const
typename genset_t::word_t word_t
static word_t letters_of_padded(letter_t v, letter_t)
Prepare to iterate over v.
static constexpr bool is_expressionset()
letterset(std::initializer_list< letter_t > letters)
std::set< value_t, vcsn::less< self_t > > values_t
std::ostream & str_escape(std::ostream &os, const std::string &str, const char *special=nullptr)
Output a string, escaping special characters.
bool is_valid(value_t v) const
static word_t letters_of(word_t v)
Prepare to iterate over the letters of v.
ATTRIBUTE_PURE auto has(Args &&... args) const -> decltype(this->genset() -> has(std::forward< Args >(args)...))
static labelset_t::value_t get_value(const value_t &v)
The (inner) value when it (the outer value) is not one.
void convs(std::istream &i, Fun fun) const
Process a label class.
An input/output format for valuesets.
Provide a variadic mul on top of a binary mul(), and one().
std::shared_ptr< const genset_t > genset_ptr
value_t rdivide(const value_t l, const value_t r) const
Compute w1 / w2.
static size_t hash(value_t v)
static bool is_special(value_t v) ATTRIBUTE_PURE
letterset(const genset_ptr &gs)
static int compare(const value_t l, const value_t r)
Three-way comparison between l and r.
static ATTRIBUTE_PURE bool is_one(value_t l)
boost::optional< value_t > maybe_ldivide(const value_t l, const value_t r) const
boost::optional< value_t > maybe_rdivide(const value_t l, const value_t r) const
const labelset_ptr labelset() const
Implementation of labels are letters.
char eat(std::istream &is, char c)
Check lookahead character and advance.
static bool equal(const value_t l, const value_t r)
Whether l == r.
#define VCSN_REQUIRE(Cond,...)
A macro similar to require.
value_t lgcd(const value_t l, const value_t r) const
The longest common prefix.
void require(Bool b, Args &&... args)
If b is not verified, raise an error with args as message.
std::ostream & print(const value_t &l, std::ostream &o=std::cout, format fmt={}) const
letter_t get_letter(std::istream &i, bool quoted=true) const
Read one letter from i.
static letterset make(std::istream &is)
Build from the description in is.
static size_t size(value_t)
int compare(const Lhs &lhs, const Rhs &rhs)
Comparison between lhs and rhs.
std::string to_string(direction d)
Conversion to string.
value_t conv(std::istream &i, bool quoted=true) const
Read one letter from i, return the corresponding label.
static constexpr bool is_one(value_t)
void convs_(std::istream &i, Fun fun) const
Read and process a class of letters.