Vcsn  2.0
Be Rational
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ratexp.hh
Go to the documentation of this file.
1 #ifndef VCSN_DYN_RATEXP_HH
2 # define VCSN_DYN_RATEXP_HH
3 
4 # include <memory>
5 # include <string>
6 
7 # include <vcsn/dyn/fwd.hh>
8 # include <vcsn/misc/export.hh>
9 
10 namespace vcsn
11 {
12  namespace dyn
13  {
14  namespace detail
15  {
16 
19  {
20  public:
24  virtual std::string vname(bool full = true) const = 0;
25 
27  template <typename RatExpSet>
29  {
30  return dynamic_cast<ratexp_wrapper<RatExpSet>&>(*this);
31  }
32 
34  template <typename RatExpSet>
36  {
37  return dynamic_cast<const ratexp_wrapper<RatExpSet>&>(*this);
38  }
39  };
40 
41 
43  template <typename RatExpSet>
44  class ratexp_wrapper: public ratexp_base
45  {
46  public:
47  using ratexpset_t = RatExpSet;
49  using ratexp_t = typename ratexpset_t::value_t;
51  const ratexpset_t& ratexpset)
52  : ratexp_(ratexp)
53  , ratexpset_(ratexpset)
54  {}
55 
56  virtual std::string vname(bool full = true) const override
57  {
58  return ratexpset().vname(full);
59  }
60 
61  const ratexp_t ratexp() const
62  {
63  return ratexp_;
64  }
65 
66  const ratexpset_t& ratexpset() const
67  {
68  return ratexpset_;
69  }
70 
71  protected:
76  };
77 
78  } // namespace detail
79 
80  using ratexp = std::shared_ptr<detail::ratexp_base>;
81 
82  template <typename RatExpSet>
83  inline
84  ratexp
85  make_ratexp(const RatExpSet& rs,
86  const typename RatExpSet::value_t& ratexp)
87  {
88  using wrapper_t = detail::ratexp_wrapper<RatExpSet>;
89  return std::make_shared<wrapper_t>(ratexp, rs);
90  }
91 
92  } // namespace dyn
93 } // namespace vcsn
94 
95 #endif // !VCSN_DYN_RATEXP_HH
typename ratexpset_t::value_t ratexp_t
Definition: ratexp.hh:49
ratexp make_ratexp(const RatExpSet &rs, const typename RatExpSet::value_t &ratexp)
Definition: ratexp.hh:85
const ratexp_wrapper< RatExpSet > & as() const
Extract wrapped typed ratexp.
Definition: ratexp.hh:35
const ratexp_t ratexp() const
Definition: ratexp.hh:61
An abstract ratexp.
Definition: ratexp.hh:18
ratexp_wrapper< RatExpSet > & as()
Extract wrapped typed ratexp.
Definition: ratexp.hh:28
Aggregate a ratexp and its ratexpset.
Definition: fwd.hh:62
std::shared_ptr< detail::ratexp_base > ratexp
Definition: fwd.hh:64
std::shared_ptr< const detail::ratexpset_base > ratexpset
Definition: fwd.hh:73
const ratexp_t ratexp_
The ratexp.
Definition: ratexp.hh:73
std::string vname(T &t)
Definition: name.hh:65
virtual std::string vname(bool full=true) const override
A description of the ratexp type.
Definition: ratexp.hh:56
const ratexpset_t & ratexpset() const
Definition: ratexp.hh:66
#define LIBVCSN_API
Definition: export.hh:9
ratexp_wrapper(const ratexp_t &ratexp, const ratexpset_t &ratexpset)
Definition: ratexp.hh:50
const ratexpset_t ratexpset_
The ratexp set.
Definition: ratexp.hh:75