Vcsn  2.0
Be Rational
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ratexpset.hh
Go to the documentation of this file.
1 #ifndef VCSN_DYN_RATEXPSET_HH
2 # define VCSN_DYN_RATEXPSET_HH
3 
4 # include <memory> // shared_ptr
5 # include <set>
6 # include <string>
7 
8 # include <vcsn/ctx/traits.hh>
9 # include <vcsn/dyn/fwd.hh> // dyn::ratexp.
10 # include <vcsn/core/rat/fwd.hh> // rat::exp_t.
11 
12 namespace vcsn
13 {
14 namespace dyn
15 {
16 namespace detail
17 {
18 
26  {
27  public:
29 
33  virtual std::string vname(bool full = true) const = 0;
34 
36  template <typename RatExpSet>
38  {
39  return dynamic_cast<ratexpset_wrapper<RatExpSet>&>(*this);
40  }
41 
43  template <typename RatExpSet>
45  {
46  return dynamic_cast<const ratexpset_wrapper<RatExpSet>&>(*this);
47  }
48 
49  virtual rat::identities identities() const = 0;
50 
51  virtual value_t zero() const = 0;
52  virtual value_t one() const = 0;
53  virtual value_t atom(const std::string& w) const = 0;
54  virtual value_t add(value_t l, value_t r) const = 0;
56  virtual value_t mul(value_t l, value_t r) const = 0;
57  virtual value_t conjunction(value_t l, value_t r) const = 0;
58  virtual value_t shuffle(value_t l, value_t r) const = 0;
59  virtual value_t ldiv(value_t l, value_t r) const = 0;
60  virtual value_t rdiv(value_t l, value_t r) const = 0;
63  virtual value_t concat(value_t l, value_t r) const = 0;
64  virtual value_t star(value_t e) const = 0;
65 
67  virtual value_t complement(value_t e) const = 0;
68 
70  virtual value_t transposition(value_t e) const = 0;
71 
73  virtual value_t lmul(const std::string& w, value_t e) const = 0;
74 
76  virtual value_t rmul(value_t e, const std::string& w) const = 0;
77 
78  using letter_class_t = std::set<std::pair<std::string, std::string>>;
79 
86  virtual value_t letter_class(const letter_class_t& chars,
87  bool accept = true) const = 0;
88 
89  virtual dyn::ratexp make_ratexp(const value_t& v) const = 0;
90 
92  virtual value_t conv(std::istream& s) const = 0;
93 
94  virtual std::ostream& print(const value_t v, std::ostream& o) const = 0;
95  };
96 
98  template <typename RatExpSet>
99  class ratexpset_wrapper : public ratexpset_base
100  {
101  public:
102  using ratexpset_t = RatExpSet;
107  using value_t = typename super_t::value_t;
108 
111  ratexpset_wrapper(const ratexpset_t& rs);
112 
113  virtual std::string vname(bool full = true) const override
114  {
115  return ratexpset().vname(full);
116  }
117 
119  const ratexpset_t& ratexpset() const
120  {
121  return rs_;
122  }
123 
125  typename ratexpset_t::value_t down(const value_t& v) const;
126 
128  weight_t down(const std::string& w) const;
129 
130  virtual dyn::ratexp make_ratexp(const value_t& v) const override;
131 
132  /*--------------------------------------.
133  | Specializations from ratexpset_base. |
134  `--------------------------------------*/
135 
136  virtual rat::identities identities() const override;
137 
138  virtual value_t zero() const override;
139  virtual value_t one() const override;
140 
141  virtual value_t atom(const std::string& w) const override;
142 
143  virtual value_t add(value_t l, value_t r) const override;
144 
145  virtual value_t mul(value_t l, value_t r) const override;
146 
147  virtual value_t conjunction(value_t l, value_t r) const override;
148 
149  virtual value_t shuffle(value_t l, value_t r) const override;
150 
151  virtual value_t ldiv(value_t l, value_t r) const override;
152  virtual value_t rdiv(value_t l, value_t r) const override;
153 
156  virtual value_t concat(value_t l, value_t r) const override;
157 
158  virtual value_t star(value_t v) const override;
159 
160  virtual value_t complement(value_t v) const override;
161  virtual value_t transposition(value_t v) const override;
162 
163  virtual value_t lmul(const std::string& w, value_t v) const override;
164 
165  virtual value_t rmul(value_t v, const std::string& w) const override;
166 
167  virtual value_t letter_class(const letter_class_t& chars,
168  bool accept = true) const override;
169 
171  virtual value_t conv(std::istream& is) const override;
172 
173  virtual std::ostream& print(value_t v, std::ostream& o) const override;
174 
175  private:
177  template <typename LabelSet_, typename Bool>
178  value_t letter_class_(const letter_class_t& chars,
179  bool accept, std::true_type, Bool) const;
181  template <typename LabelSet_>
182  value_t letter_class_(const letter_class_t& chars,
183  bool accept, std::false_type,
184  std::false_type) const;
186  template <typename LabelSet_>
187  value_t letter_class_(const letter_class_t& chars,
188  bool accept, std::false_type,
189  std::true_type) const;
190 
192  };
193 } // namespace detail
194 
196  template <typename RatExpSet>
197  ratexpset make_ratexpset(const RatExpSet& rs);
198 
199 } // namespace dyn
200 } // namespace vcsn
201 
202 # include <vcsn/dyn/ratexpset.hxx>
203 
204 #endif // !VCSN_DYN_RATEXPSET_HH
virtual value_t one() const =0
virtual value_t add(value_t l, value_t r) const =0
label_t_of< context_t > label_t
Definition: ratexpset.hh:105
virtual std::ostream & print(const value_t v, std::ostream &o) const =0
virtual value_t lmul(const std::string &w, value_t v) const override
Left-multiplication by a weight.
Definition: ratexpset.hxx:119
virtual value_t transposition(value_t e) const =0
Add a transposition operator.
ratexpset make_ratexpset(const context &ctx,::vcsn::rat::identities is)
Build an ratexpset from its context.
Definition: make-context.cc:57
Wrapper around a ratexpset.
Definition: fwd.hh:71
virtual value_t complement(value_t v) const override
Add a complement operator.
Definition: ratexpset.hxx:109
const ratexpset_wrapper< RatExpSet > & as() const
Extract wrapped typed ratexp.
Definition: ratexpset.hh:44
virtual value_t one() const override
Definition: ratexpset.hxx:59
virtual rat::identities identities() const override
Definition: ratexpset.hxx:49
virtual value_t rmul(value_t e, const std::string &w) const =0
Right-multiplication by a weight.
virtual value_t atom(const std::string &w) const =0
virtual value_t letter_class(const letter_class_t &chars, bool accept=true) const override
A ratexp matching one character amongst chars.
Definition: ratexpset.hxx:129
std::shared_ptr< detail::ratexp_base > ratexp
Definition: fwd.hh:64
virtual value_t zero() const override
Definition: ratexpset.hxx:54
virtual std::string vname(bool full=true) const =0
A description of the ratexp type.
virtual std::string vname(bool full=true) const override
A description of the ratexp type.
Definition: ratexpset.hh:113
virtual value_t concat(value_t l, value_t r) const =0
Implicit product.
typename detail::context_t_of_impl< base_t< ValueSet >>::type context_t_of
Definition: traits.hh:32
ratexpset_t::value_t down(const value_t &v) const
From weak to strong typing.
Definition: ratexpset.hxx:32
virtual rat::identities identities() const =0
virtual value_t atom(const std::string &w) const override
Definition: ratexpset.hxx:64
virtual dyn::ratexp make_ratexp(const value_t &v) const =0
virtual value_t conv(std::istream &s) const =0
Parsing.
const ratexpset_t & ratexpset() const
The ratexpset which this wraps.
Definition: ratexpset.hh:119
virtual value_t rmul(value_t v, const std::string &w) const override
Right-multiplication by a weight.
Definition: ratexpset.hxx:124
virtual value_t mul(value_t l, value_t r) const override
Explicit product.
Definition: ratexpset.hxx:74
virtual value_t star(value_t v) const override
Definition: ratexpset.hxx:104
virtual value_t conjunction(value_t l, value_t r) const =0
typename detail::label_t_of_impl< base_t< ValueSet >>::type label_t_of
Definition: traits.hh:33
virtual value_t complement(value_t e) const =0
Add a complement operator.
std::shared_ptr< const detail::ratexpset_base > ratexpset
Definition: fwd.hh:73
ratexpset_wrapper(const ratexpset_t &rs)
Constructor.
Definition: ratexpset.hxx:21
virtual value_t ldiv(value_t l, value_t r) const override
Definition: ratexpset.hxx:89
std::istringstream is
The input stream: the specification to translate.
Definition: translate.cc:329
typename super_t::value_t value_t
Definition: ratexpset.hh:107
virtual value_t letter_class(const letter_class_t &chars, bool accept=true) const =0
A ratexp matching one character amongst chars.
weight_t_of< context_t > weight_t
Definition: ratexpset.hh:106
virtual value_t mul(value_t l, value_t r) const =0
Explicit product.
Provide a variadic mul on top of a binary mul(), and one().
Definition: fwd.hh:36
std::shared_ptr< const exp > exp_t
Definition: fwd.hh:16
typename detail::weight_t_of_impl< base_t< ValueSet >>::type weight_t_of
Definition: traits.hh:37
Abstract wrapper around a (typeful) ratexpset.
Definition: ratexpset.hh:25
context_t_of< ratexpset_t > context_t
Definition: ratexpset.hh:103
virtual value_t lmul(const std::string &w, value_t e) const =0
Left-multiplication by a weight.
virtual value_t transposition(value_t v) const override
Add a transposition operator.
Definition: ratexpset.hxx:114
virtual value_t shuffle(value_t l, value_t r) const override
Definition: ratexpset.hxx:84
virtual value_t shuffle(value_t l, value_t r) const =0
virtual value_t ldiv(value_t l, value_t r) const =0
virtual value_t zero() const =0
virtual value_t conv(std::istream &is) const override
Parsing.
Definition: ratexpset.hxx:199
std::set< std::pair< std::string, std::string >> letter_class_t
Definition: ratexpset.hh:78
virtual value_t conjunction(value_t l, value_t r) const override
Definition: ratexpset.hxx:79
virtual value_t star(value_t e) const =0
virtual value_t rdiv(value_t l, value_t r) const override
Definition: ratexpset.hxx:94
identities
A ratexpset can implement several different sets of identities on expressions.
Definition: identities.hh:17
virtual value_t concat(value_t l, value_t r) const override
When concatenating two atoms, possibly make a single one, or make the product.
Definition: ratexpset.hxx:99
virtual dyn::ratexp make_ratexp(const value_t &v) const override
Definition: ratexpset.hxx:43
virtual value_t add(value_t l, value_t r) const override
Definition: ratexpset.hxx:69
value_t letter_class_(const letter_class_t &chars, bool accept, std::true_type, Bool) const
If context is oneset.
ratexpset_wrapper< RatExpSet > & as()
Extract wrapped typed ratexpset.
Definition: ratexpset.hh:37
virtual value_t rdiv(value_t l, value_t r) const =0
virtual std::ostream & print(value_t v, std::ostream &o) const override
Definition: ratexpset.hxx:204