Vcsn  2.0
Be Rational
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
weight.hh
Go to the documentation of this file.
1 #ifndef VCSN_DYN_WEIGHT_HH
2 # define VCSN_DYN_WEIGHT_HH
3 
4 # include <memory>
5 # include <string>
6 
7 # include <vcsn/misc/export.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 
26  template <typename WeightSet>
28  {
29  return dynamic_cast<weight_wrapper<WeightSet>&>(*this);
30  }
31 
33  template <typename WeightSet>
35  {
36  return dynamic_cast<const weight_wrapper<WeightSet>&>(*this);
37  }
38  };
39 
41  template <typename WeightSet>
42  class weight_wrapper: public weight_base
43  {
44  public:
47  using weight_t = typename weightset_t::value_t;
48  weight_wrapper(const weight_t& w, const weightset_t& ws)
49  : weight_(w)
50  , weightset_(ws)
51  {}
52 
53  virtual std::string vname(bool full = true) const override
54  {
55  return weightset().vname(full);
56  }
57 
58  const weight_t weight() const
59  {
60  return weight_;
61  }
62 
63  const weightset_t& weightset() const
64  {
65  return weightset_;
66  }
67 
68  protected:
73  };
74 
75  } // namespace detail
76 
77  using weight = std::shared_ptr<const detail::weight_base>;
78 
79  template <typename WeightSet>
80  inline
81  weight
83  const typename WeightSet::value_t& w)
84  {
85  return std::make_shared<detail::weight_wrapper<WeightSet>>(w, ws);
86  }
87  } // namespace dyn
88 } // namespace vcsn
89 
90 #endif // !VCSN_DYN_WEIGHT_HH
virtual std::string vname(bool full=true) const override
A description of the weight type.
Definition: weight.hh:53
weight_wrapper< WeightSet > & as()
Extract wrapped typed weight.
Definition: weight.hh:27
An abstract weight.
Definition: weight.hh:17
const weightset_t weightset_
The weight set.
Definition: weight.hh:72
const weight_wrapper< WeightSet > & as() const
Extract wrapped typed weight.
Definition: weight.hh:34
const weight_t weight_
The weight.
Definition: weight.hh:70
std::shared_ptr< const detail::weight_base > weight
Definition: fwd.hh:82
std::string vname(T &t)
Definition: name.hh:65
const weight_t weight() const
Definition: weight.hh:58
weight make_weight(const WeightSet &ws, const typename WeightSet::value_t &w)
Definition: weight.hh:82
const weightset_t & weightset() const
Definition: weight.hh:63
weight_wrapper(const weight_t &w, const weightset_t &ws)
Definition: weight.hh:48
Aggregate a weight and its weightset.
Definition: fwd.hh:80
#define LIBVCSN_API
Definition: export.hh:9
typename weightset_t::value_t weight_t
Definition: weight.hh:47