Vcsn  2.2
Be Rational
label.hh
Go to the documentation of this file.
1 #pragma once
2 
3 #include <memory>
4 #include <string>
5 
6 #include <vcsn/misc/export.hh>
7 
8 namespace vcsn
9 {
10  namespace dyn
11  {
12  namespace detail
13  {
14 
17  {
18  public:
20  virtual symbol vname() const = 0;
21 
23  template <typename LabelSet>
24  auto& as()
25  {
26  return dyn_cast<label_wrapper<LabelSet>&>(*this);
27  }
28 
30  template <typename LabelSet>
31  auto& as() const
32  {
33  return dyn_cast<const label_wrapper<LabelSet>&>(*this);
34  }
35  };
36 
38  template <typename LabelSet>
39  class label_wrapper final: public label_base
40  {
41  public:
42  using labelset_t = LabelSet;
44  using label_t = typename labelset_t::value_t;
45 
46  label_wrapper(const labelset_t& ls, const label_t& l)
47  : labelset_(ls)
48  , label_(l)
49  {}
50 
51  virtual symbol vname() const override
52  {
53  return labelset().sname();
54  }
55 
56  const labelset_t& labelset() const
57  {
58  return labelset_;
59  }
60 
61  const label_t label() const
62  {
63  return label_;
64  }
65 
66  private:
70  const label_t label_;
71  };
72 
73  } // namespace detail
74 
75  using label = std::shared_ptr<const detail::label_base>;
76 
77  template <typename LabelSet>
78  inline
79  label
80  make_label(const LabelSet& ls,
81  const typename LabelSet::value_t& l)
82  {
83  return std::make_shared<detail::label_wrapper<LabelSet>>(ls, l);
84  }
85 
86  template <typename LabelSet>
87  inline
88  label
89  make_word(const LabelSet& ls,
90  const typename LabelSet::value_t& l)
91  {
92  return make_label(make_wordset(ls), l);
93  }
94  } // namespace dyn
95 } // namespace vcsn
Aggregate a label and its labelset.
Definition: fwd.hh:59
typename labelset_t::value_t label_t
Definition: label.hh:44
Definition: a-star.hh:8
label_wrapper(const labelset_t &ls, const label_t &l)
Definition: label.hh:46
virtual symbol vname() const override
A description of the label type.
Definition: label.hh:51
label make_label(const LabelSet &ls, const typename LabelSet::value_t &l)
Definition: label.hh:80
An abstract label.
Definition: label.hh:16
To dyn_cast(From &&from)
A dynamic_cast in debug mode, static_cast with NDEBUG.
Definition: fwd.hh:16
std::shared_ptr< const detail::label_base > label
Definition: fwd.hh:61
symbol vname(T &t)
Definition: name.hh:101
label make_word(const LabelSet &ls, const typename LabelSet::value_t &l)
Definition: label.hh:89
const labelset_t & labelset() const
Definition: label.hh:56
boost::flyweight< std::string, boost::flyweights::no_tracking, boost::flyweights::intermodule_holder > symbol
An internalized string.
Definition: symbol.hh:23
const label_t label() const
Definition: label.hh:61
#define LIBVCSN_API
Definition: export.hh:8
const label_t label_
The label.
Definition: label.hh:70
const labelset_t labelset_
The label set.
Definition: label.hh:68
auto & as() const
Extract wrapped typed label.
Definition: label.hh:31
auto & as()
Extract wrapped typed label.
Definition: label.hh:24
law_t< LabelSet > make_wordset(const LabelSet &ls)
The wordset of a labelset.
Definition: labelset.hh:269