6 #include <boost/range/algorithm/mismatch.hpp>
7 #include <boost/algorithm/string/predicate.hpp>
21 template <
typename GenSet>
22 class wordset:
public detail::genset_labelset<GenSet>
31 using word_t =
typename genset_t::word_t;
43 :
wordset{std::make_shared<const genset_t>(gs)}
46 wordset(std::initializer_list<letter_t> letters)
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)...};
119 return genset_t::less(l, r);
133 return genset_t::less(l, r);
139 return genset_t::template special<value_t>();
157 static constexpr
bool
163 static constexpr
bool
169 static constexpr
bool
178 return genset_t::empty_word();
184 return genset_t::is_empty_word(l);
205 template <
typename GenSet_>
216 *
this,
": conv: invalid label: ",
str_escape(v));
221 template <
typename LabelSet_>
234 conv(std::istream& i,
bool =
true)
const
236 return this->
genset()->get_word(i);
248 template <
typename Fun>
249 void convs(std::istream& i, Fun fun)
const
263 this->
genset()->print(l, o, fmt);
273 this->
genset()->print_set(o, fmt);
278 this->
genset()->print_set(o, fmt);
283 this->genset()->print_set(o, fmt);
294 static value_t lgcd(const value_t& w1, const value_t& w2)
296 return {w1.begin(), boost::mismatch(w1, w2).first};
301 value_t ldivide(const value_t& w1, const value_t& w2) const
303 using boost::algorithm::starts_with;
304 VCSN_REQUIRE(starts_with(w2, w1),
305 *this, ": ldivide: invalid arguments: ", str_escape(w1),
306 ", ", str_escape(w2));
307 return {begin(w2) + size(w1), end(w2)};
311 value_t& ldivide_here(const value_t& w1, value_t& w2) const
313 w2 = ldivide(w1, w2);
317 const value_t& conjunction(const value_t& l, const value_t& r) const
323 ": conjunction: invalid operation (lhs and rhs are not equal): ",
324 to_string(*this, l), ", ", to_string(*this, r));
331 template <typename GenSet>
332 struct letterized_traits<wordset<GenSet>>
334 static constexpr bool is_letterized = false;
336 using labelset_t = nullableset<letterset<GenSet>>;
338 static labelset_t labelset(const wordset<GenSet>& ls)
340 return {ls.genset()};
345 template <typename GenSet>
346 struct nullableset_traits<wordset<GenSet>>
348 using type = wordset<GenSet>;
349 static type value(const wordset<GenSet>& ls)
355 template <typename GenSet>
356 struct law_traits<wordset<GenSet>>
358 using type = wordset<GenSet>;
359 static type value(const wordset<GenSet>& ls)
370 #define DEFINE(Lhs, Rhs) \
371 template <typename GenSet> \
372 struct join_impl<Lhs, Rhs> \
375 static type join(const Lhs& lhs, const Rhs& rhs) \
377 return {set_union(*lhs.genset(), *rhs.genset())}; \
382 DEFINE(letterset<GenSet>, wordset<GenSet>);
383 DEFINE(nullableset<letterset<GenSet>>, wordset<GenSet>);
384 DEFINE(wordset<GenSet>, wordset<GenSet>);
389 // FIXME: Factor in genset_labelset?
390 template <typename GenSet>
392 meet(const wordset<GenSet>& lhs, const wordset<GenSet>& rhs)
394 return {set_intersection(*lhs.genset(), *rhs.genset())};
static ATTRIBUTE_PURE bool is_one(value_t l)
static size_t size(const value_t &v)
static bool is_special(const value_t &v)
wordset(const genset_t &gs={})
boost::flyweight< std::string, boost::flyweights::no_tracking, boost::flyweights::intermodule_holder > symbol
An internalized string.
static labelset_t::value_t get_value(const value_t &v)
The (inner) value when it (the outer value) is not one.
std::shared_ptr< const genset_t > genset_ptr
std::ostream & str_escape(std::ostream &os, const std::string &str, const char *special=nullptr)
Output a string, escaping special characters.
Implementation of labels are letters.
static size_t hash(const value_t &v)
typename helper_t::value_t value_t
value_t value(Args &&...args) const
Value constructor.
Print as a parsable type string.
value_t conv(std::istream &i, bool=true) const
Read a word from this stream.
void convs(std::istream &i, Fun fun) const
Process a label class.
word_t word(const value_t &v) const
Convert to a word.
bool open(bool o) const
Whether unknown letters should be added, or rejected.
Implementation of labels are nullables (letter or empty).
static bool is_one(const value_t &l) ATTRIBUTE_PURE
std::ostream & print_set(std::ostream &o, format fmt={}) const
void convs_(std::istream &i, Fun fun) const
Read and process a class of letters.
std::ostream & print(const value_t &l, std::ostream &o=std::cout, format fmt={}) const
typename genset_t::word_t word_t
wordset(std::initializer_list< letter_t > letters)
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...
static constexpr bool is_free()
typename genset_t::letters_t letters_t
genset_ptr genset() const
static constexpr bool is_letterized()
#define VCSN_REQUIRE(Cond,...)
A macro similar to require.
static constexpr bool is_expressionset()
An input/output format for valuesets.
ATTRIBUTE_PURE auto has(Args &&...args) const -> decltype(this->genset() -> has(std::forward< Args >(args)...))
Print as rich UTF-8 text, escaped.
static wordset make(std::istream &is)
Build from the description in is.
Implementation of labels are words.
typename genset_t::letter_t letter_t
value_t conv(const nullableset< LabelSet_ > &ls, const typename nullableset< LabelSet_ >::value_t &v) const
static bool is_special(value_t v) ATTRIBUTE_PURE
static bool equal(const value_t &l, const value_t &r)
Whether l == r.
value_t conv(const letterset< GenSet_ > &ls, typename letterset< GenSet_ >::value_t v) const
static word_t letters_of_padded(const value_t &v, letter_t)
Prepare to iterate over the letters of v.
static constexpr bool has_one()
bool is_valid(const value_t &v) const
const labelset_ptr labelset() const
Provide a variadic mul on top of a binary mul(), and one().
static word_t letters_of(const value_t &v)
Prepare to iterate over the letters of v.
wordset(const genset_ptr &gs)
value_t conv(self_t, const value_t &v) const
char eat(std::istream &is, char c)
Check lookahead character and advance.
static bool less(const value_t &l, const value_t &r)
Whether l < r.
static bool less(const letter_t &l, const letter_t &r)
Whether l < r.
weightset_mixin< detail::r_impl > r