6 #include <boost/optional.hpp> 28 template <
typename LabelSet>
32 using value_t = std::pair<typename labelset_t::value_t, bool>;
38 return value_t{labelset_t::special(),
true};
45 return value_t{labelset_t::special(),
false};
48 template <
typename Ls>
50 static std::enable_if_t<Ls::has_one(), bool>
53 return std::get<1>(l) || Ls::is_one(
get_value(l));
56 template <
typename Ls>
58 static std::enable_if_t<!Ls::has_one(), bool>
61 return std::get<1>(l);
68 return is_one_<labelset_t>(l);
71 template <
typename Value>
81 return {ls.transpose(
get_value(l)),
false};
84 template <
typename... Args>
88 return {ls.value(std::forward<Args>(args)...),
false};
92 static typename labelset_t::value_t
95 return std::get<0>(
v);
105 template <
typename GenSet>
116 return genset_t::special();
123 return genset_t::one_letter();
133 template <
typename Value>
140 template <
typename... Args>
144 return ls.
value(std::forward<Args>(args)...);
157 template <
typename LabelSet>
169 using word_t =
typename labelset_t::word_t;
186 :
nullableset{std::make_shared<const labelset_t>(ls)}
201 eat(is,
"nullableset<");
202 auto ls = labelset_t::make(is);
212 return this->ls_->open(o);
215 static constexpr
bool 221 static constexpr
bool 227 static constexpr
bool 249 return helper_t::is_one(l);
261 return ls_->genset();
268 return ls_->generators();
286 template <
typename LabelSet_>
288 conv(
const LabelSet_& ls,
typename LabelSet_::value_t
v)
const 290 return value(ls_->conv(ls, v));
298 template <
typename... Args>
302 return helper_t::value(*ls_, std::forward<Args>(args)...);
317 -> decltype(labelset_t::letters_of(
v))
319 return labelset_t::letters_of(
v);
326 -> decltype(ls_->letters_of_padded(
v, l))
328 return ls_->letters_of_padded(
v, l);
333 -> decltype(this->letters_of_padded(this->word(
v), l))
335 return letters_of_padded(word(
v), l);
375 raise(*
this,
": mul: invalid arguments: ",
393 if (
auto res = maybe_ldivide(l, r))
396 raise(*
this,
": ldivide: invalid arguments: ",
400 boost::optional<value_t>
418 if (
auto res = maybe_rdivide(l, r))
421 raise(*
this,
": rdivide: invalid arguments: ",
425 boost::optional<value_t>
443 return helper_t::special();
467 return ls_->get_letter(i, quoted);
472 conv(std::istream& i,
bool quoted =
true)
const 475 if (i.good() && i.peek() ==
'\\')
487 return value(ls_->conv(i, quoted));
499 template <
typename Fun>
500 void convs(std::istream& i, Fun&& fun)
const 503 [
this,fun](
const typename labelset_t::value_t& l)
517 ": conjunction: invalid operation (lhs and rhs are not equal): ",
538 return value(ls_->zero());
554 template <
typename Value>
569 ls_->print_set(o, fmt);
575 ls_->print_set(o, fmt);
581 ls_->print_set(o, fmt); 594 static typename labelset_t::value_t 595 get_value(const value_t& v) 598 return helper_t::get_value(v); 605 template <typename LabelSet> 606 struct letterized_traits<nullableset<LabelSet>> 608 using traits = letterized_traits<LabelSet>; 609 static constexpr bool is_letterized = traits::is_letterized; 611 using labelset_t = typename traits::labelset_t; 613 static labelset_t labelset(const nullableset<LabelSet>& ls) 615 return make_letterized(*ls.labelset()); 620 template <typename LabelSet> 621 struct nullableset_traits<nullableset<LabelSet>> 623 using type = nullableset<LabelSet>; 624 static type value(const nullableset<LabelSet>& ls) 630 template <typename LabelSet> 631 struct proper_traits<nullableset<LabelSet>> 633 using type = LabelSet; 634 static type value(const nullableset<LabelSet>& ls) 636 return *ls.labelset(); 641 template <typename LabelSet> 642 struct law_traits<nullableset<LabelSet>> 644 using type = law_t<LabelSet>; 645 static type value(const nullableset<LabelSet>& ls) 647 return make_wordset(*ls.labelset()); 656 template <typename LS> 657 struct join_impl<oneset, LS, 658 std::enable_if_t<!LS::has_one()>> 660 using type = nullableset<LS>; 661 static type join(const oneset&, const LS& ls) 668 template <typename LS> 669 struct join_impl<oneset, LS, 670 std::enable_if_t<LS::has_one()>> 673 static type join(const oneset&, const LS& ls) 680 template <typename LS1, typename LS2> 681 struct join_impl<nullableset<LS1>, LS2> 683 using type = nullableset<join_t<LS1, LS2>>; 684 static type join(const nullableset<LS1>& ls1, const LS2& ls2) 686 return {::vcsn::join(*ls1.labelset(), ls2)}; 694 template <typename LS1, typename LS2> 695 struct join_impl<nullableset<LS1>, nullableset<LS2>> 697 using type = nullableset<join_t<LS1, LS2>>; 698 static type join(const nullableset<LS1>& ls1, 699 const nullableset<LS2>& ls2) 701 return {::vcsn::join(*ls1.labelset(), *ls2.labelset())}; 710 #define DEFINE(Lhs, Rhs, Res) \ 711 template <typename GenSet> \ 713 meet(const Lhs& lhs, const Rhs& rhs) \ 715 return {set_intersection(*lhs.genset(), *rhs.genset())}; \ 719 DEFINE(nullableset<letterset<GenSet>>, 720 nullableset<letterset<GenSet>>, nullableset<letterset<GenSet>>); 722 DEFINE(letterset<GenSet>, 723 nullableset<letterset<GenSet>>, nullableset<letterset<GenSet>>); 725 DEFINE(nullableset<letterset<GenSet>>, 726 letterset<GenSet>, nullableset<letterset<GenSet>>); 728 template <typename Lls, typename Rls> 729 nullableset<meet_t<Lls, Rls>> 730 meet(const nullableset<Lls>& lhs, const nullableset<Rls>& rhs) 732 return nullableset<meet_t<Lls, Rls>>{meet(*lhs.labelset(), 744 template <typename LabelSet, 745 typename RandomGenerator = std::default_random_engine> 746 typename nullableset<LabelSet>::value_t 747 random_label(const nullableset<LabelSet>& ls, 748 RandomGenerator& gen = RandomGenerator()) 750 // FIXME: the proportion should be controllable. 751 auto dis = std::bernoulli_distribution(0.5); 752 if (dis(gen) || ls.generators().empty()) 755 return ls.value(random_label(*ls.labelset(), gen)); typename helper_t::value_t value_t
value_t conv(oneset, typename oneset::value_t) const
word_t word(const value_t &l) const
typename labelset_t::letter_t letter_t
genset_ptr genset() const
Print as a parsable type string.
Implementation of labels are nullables (letter or empty).
static ATTRIBUTE_PURE value_t get_value(const value_t &v)
value_t conv(std::istream &i, bool quoted=true) const
Read a label from a stream.
static ATTRIBUTE_PURE constexpr value_t one()
static ATTRIBUTE_PURE std::enable_if_t<!Ls::has_one(), bool > is_one_(const value_t &l)
value_t conjunction(const value_t &l, const value_t &r) const
value_t value(Args &&... args) const
Value constructor.
std::ostream & print_set(std::ostream &o, format fmt={}) const
Print labelset description.
boost::optional< value_t > maybe_rdivide(const value_t &l, const value_t &r) const
typename labelset_t::word_t word_t
static constexpr bool has_one()
bool is_special(const Aut &aut, transition_t_of< Aut > t)
Whether this transition is from pre or to post.
static ATTRIBUTE_PURE std::enable_if_t< Ls::has_one(), bool > is_one_(const value_t &l)
static size_t size(const value_t &v)
static ATTRIBUTE_PURE bool is_one(const value_t &l)
static ATTRIBUTE_PURE constexpr value_t special()
static ATTRIBUTE_PURE labelset_t::value_t get_value(const value_t &v)
letter_t get_letter(std::istream &i, bool quoted=true) const
std::shared_ptr< const labelset_t > labelset_ptr
Add support for an empty word to a LabelSet that does not provide such special label to this end...
decltype(ls_->genset()) genset_ptr
void convs(std::istream &i, Fun &&fun) const
Process a label class.
static size_t hash(const value_t &v)
static value_t value(const labelset_t &ls, Args &&... args)
static bool equal(const value_t &l, const value_t &r)
Whether l == r.
std::ostream & print(const value_t &l, std::ostream &o=std::cout, format fmt={}) const
Print label to stream.
bool open(bool o) const
Whether unknown letters should be added, or rejected.
static ATTRIBUTE_PURE constexpr value_t one()
boost::flyweight< std::string, boost::flyweights::no_tracking, boost::flyweights::intermodule_holder > symbol
An internalized string.
boost::optional< value_t > maybe_ldivide(const value_t &l, const value_t &r) const
Value transpose(const Value &l) const
Mirror label.
value_t ldivide(const value_t &l, const value_t &r) const
Compute l \ r = l^{-1}r.
weightset_mixin< detail::r_impl > r
Implementation of labels are ones: there is a single instance of label.
value_t conv(self_t, value_t v) const
static bool less(const value_t &l, const value_t &r)
Whether l < r.
Print as rich UTF-8 text, escaped.
labelset_ptr ls_
The wrapped LabelSet.
decltype(ls_->generators()) genset_t
nullableset(const labelset_t &ls={})
static Value transpose(const labelset_t &ls, Value l)
bool is_valid(value_t v) const
static Value transpose(const labelset_t &ls, const Value &l)
std::enable_if_t<!is_letterized_t< labelset_t_of< Aut > >{}, bool > is_letterized(const Aut &aut)
bool is_letter(const value_t &v) const
nullableset(const labelset_ptr &ls)
value_t value(Args &&... args) const
An input/output format for valuesets.
Provide a variadic mul on top of a binary mul(), and one().
Aut transpose(const transpose_automaton< Aut > &aut)
The transpose of a transpose automaton is the original automaton.
ATTRIBUTE_PURE auto transpose(Args &&... args) const -> decltype(this->genset() -> transpose(std::forward< Args >(args)...))
static ATTRIBUTE_PURE constexpr value_t one()
constant< type_t::one, Context > one
static constexpr bool is_letterized()
auto letters_of_padded(const word_t &v, letter_t l) const -> decltype(ls_->letters_of_padded(v, l))
Prepare to iterate over the letters of v.
static ATTRIBUTE_PURE bool is_one(value_t l)
static constexpr bool is_free()
static ATTRIBUTE_PURE constexpr value_t special()
typename labelset_t::value_t value_t
const labelset_ptr labelset() const
Implementation of labels are letters.
char eat(std::istream &is, char c)
Check lookahead character and advance.
value_t mul(const value_t &l, const value_t &r) const
The concatenation.
static value_t value(const labelset_t &ls, Args &&... args)
static ATTRIBUTE_PURE bool is_one(value_t l)
value_t conv(const LabelSet_ &ls, typename LabelSet_::value_t v) const
Conversion from another type: first by the wrapped labelset, and then by our wrappers (in case the wr...
static auto letters_of(const word_t &v) -> decltype(labelset_t::letters_of(v))
Prepare to iterate over the letters of v.
value_t lgcd(const value_t &l, const value_t &r) const
The longest common prefix.
int compare(const Lhs &lhs, const Rhs &rhs)
Comparison between lhs and rhs.
std::pair< typename labelset_t::value_t, bool > value_t
auto letters_of_padded(value_t v, letter_t l) const -> decltype(this->letters_of_padded(this->word(v), l))
static int compare(const value_t &l, const value_t &r)
Three way comparison between l and r.
size_t size(const ExpSet &rs, const typename ExpSet::value_t &r)
std::string to_string(direction d)
Conversion to string.
bool is_zero(const value_t &v) const
static bool is_special(const value_t &v)
static nullableset make(std::istream &is)
Build from the description in is.
value_t rdivide(const value_t &l, const value_t &r) const
Compute l / r.
law_t< LabelSet > make_wordset(const LabelSet &ls)
The wordset of a labelset.
static constexpr bool is_expressionset()