Vcsn  2.0
Be Rational
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
label.hh
Go to the documentation of this file.
1 #ifndef VCSN_DYN_LABEL_HH
2 # define VCSN_DYN_LABEL_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 LabelSet>
28  {
29  return dynamic_cast<label_wrapper<LabelSet>&>(*this);
30  }
31 
33  template <typename LabelSet>
34  const label_wrapper<LabelSet>& as() const
35  {
36  return dynamic_cast<const label_wrapper<LabelSet>&>(*this);
37  }
38  };
39 
41  template <typename LabelSet>
42  class label_wrapper: public label_base
43  {
44  public:
47  using label_t = typename labelset_t::value_t;
48  label_wrapper(const label_t& l, const labelset_t& ls)
49  : label_(l)
50  , labelset_(ls)
51  {}
52 
53  virtual std::string vname(bool full = true) const override
54  {
55  return labelset().vname(full);
56  }
57 
58  const label_t label() const
59  {
60  return label_;
61  }
62 
63  const labelset_t& labelset() const
64  {
65  return labelset_;
66  }
67 
68  protected:
70  const label_t label_;
73  };
74 
75  } // namespace detail
76 
77  using label = std::shared_ptr<const detail::label_base>;
78 
79  template <typename LabelSet>
80  inline
81  label
82  make_label(const LabelSet& ls,
83  const typename LabelSet::value_t& l)
84  {
85  return std::make_shared<detail::label_wrapper<LabelSet>>(l, ls);
86  }
87 
88  template <typename LabelSet>
89  inline
90  label
91  make_word(const LabelSet& ls,
92  const typename LabelSet::value_t& l)
93  {
94  return make_label(make_wordset(ls), l);
95  }
96  } // namespace dyn
97 } // namespace vcsn
98 
99 #endif // !VCSN_DYN_LABEL_HH
const label_t label_
The label.
Definition: label.hh:70
typename labelset_t::value_t label_t
Definition: label.hh:47
label_wrapper< LabelSet > & as()
Extract wrapped typed label.
Definition: label.hh:27
label make_word(const LabelSet &ls, const typename LabelSet::value_t &l)
Definition: label.hh:91
virtual std::string vname(bool full=true) const override
A description of the label type.
Definition: label.hh:53
label_wrapper(const label_t &l, const labelset_t &ls)
Definition: label.hh:48
const labelset_t & labelset() const
Definition: label.hh:63
const label_wrapper< LabelSet > & as() const
Extract wrapped typed label.
Definition: label.hh:34
law_t< LabelSet > make_wordset(const LabelSet &ls)
The wordset of a labelset.
Definition: labelset.hh:72
const label_t label() const
Definition: label.hh:58
std::string vname(T &t)
Definition: name.hh:65
std::shared_ptr< const detail::label_base > label
Definition: fwd.hh:46
const labelset_t labelset_
The label set.
Definition: label.hh:72
#define LIBVCSN_API
Definition: export.hh:9
Aggregate a label and its labelset.
Definition: fwd.hh:44
label make_label(const LabelSet &ls, const typename LabelSet::value_t &l)
Definition: label.hh:82
An abstract label.
Definition: label.hh:17