Vcsn  2.0
Be Rational
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
polynomial.hh
Go to the documentation of this file.
1 #ifndef VCSN_DYN_POLYNOMIAL_HH
2 # define VCSN_DYN_POLYNOMIAL_HH
3 
4 # include <memory>
5 # include <string>
6 
7 # include <vcsn/dyn/fwd.hh>
8 
9 namespace vcsn
10 {
11  namespace dyn
12  {
13  namespace detail
14  {
15 
18  {
19  public:
23  virtual std::string vname(bool full = true) const = 0;
24 
25  template <typename PolynomialSet>
27  {
28  return dynamic_cast<polynomial_wrapper<PolynomialSet>&>(*this);
29  }
30 
31  template <typename PolynomialSet>
33  {
34  return dynamic_cast<const polynomial_wrapper<PolynomialSet>&>(*this);
35  }
36 
38  virtual bool empty() const = 0;
39  };
40 
42  template <typename PolynomialSet>
43  class polynomial_wrapper: public polynomial_base
44  {
45  public:
46  using polynomialset_t = PolynomialSet;
48  using polynomial_t = typename polynomialset_t::value_t;
51  : polynomial_(polynomial)
52  , polynomialset_(polynomialset)
53  {}
54  virtual ~polynomial_wrapper() {}
55 
56  virtual std::string vname(bool full = true) const override
57  {
58  return polynomialset().vname(full);
59  }
60 
61  const polynomial_t polynomial() const
62  {
63  return polynomial_;
64  }
65 
67  {
68  return polynomialset_;
69  }
70 
72  virtual bool empty() const override
73  {
74  return polynomial_.empty();
75  }
76 
77  protected:
82  };
83 
84  } // namespace detail
85 
86  using polynomial = std::shared_ptr<const detail::polynomial_base>;
87 
88  template <typename PolynomialSet>
89  inline
91  make_polynomial(const PolynomialSet& ps,
92  const typename PolynomialSet::value_t& polynomial)
93  {
95  return std::make_shared<wrapper_t>(polynomial, ps);
96  }
97  } // namespace dyn
98 } // namespace vcsn
99 
100 #endif // !VCSN_DYN_POLYNOMIAL_HH
Linear combination of labels: map labels to weights.
Definition: fwd.hh:32
Aggregate a polynomial and its polynomialset.
Definition: fwd.hh:53
polynomial make_polynomial(const PolynomialSet &ps, const typename PolynomialSet::value_t &polynomial)
Definition: polynomial.hh:91
An abstract polynomial.
Definition: polynomial.hh:17
virtual std::string vname(bool full=true) const override
A description of the polynomial.
Definition: polynomial.hh:56
const polynomialset_t & polynomialset() const
Definition: polynomial.hh:66
virtual std::string vname(bool full=true) const =0
A description of the polynomial.
polynomial_wrapper(const polynomial_t &polynomial, const polynomialset_t &polynomialset)
Definition: polynomial.hh:49
const polynomialset_t polynomialset_
The polynomial set.
Definition: polynomial.hh:81
const polynomial_wrapper< PolynomialSet > & as() const
Definition: polynomial.hh:32
const polynomial_t polynomial() const
Definition: polynomial.hh:61
typename polynomialset_t::value_t polynomial_t
Definition: polynomial.hh:48
virtual bool empty() const =0
Whether is zero.
const polynomial_t polynomial_
The polynomial.
Definition: polynomial.hh:79
polynomial_wrapper< PolynomialSet > & as()
Definition: polynomial.hh:26
std::shared_ptr< const detail::polynomial_base > polynomial
Definition: fwd.hh:55
virtual bool empty() const override
Whether is zero.
Definition: polynomial.hh:72