Vcsn  2.2
Be Rational
automaton.hh
Go to the documentation of this file.
1 #pragma once
2 
3 #include <memory> // shared_ptr
4 #include <string>
5 #include <vcsn/dyn/fwd.hh>
6 #include <vcsn/misc/export.hh>
7 #include <vcsn/misc/symbol.hh>
8 
9 namespace vcsn
10 {
11  namespace dyn
12  {
13  namespace detail
14  {
17  {
18  public:
20  virtual symbol vname() const = 0;
21 
23  template <Automaton Aut>
24  auto& as()
25  {
26  return dyn_cast<automaton_wrapper<Aut>&>(*this).automaton();
27  }
28 
30  template <Automaton Aut>
31  auto& as() const
32  {
33  return dyn_cast<const automaton_wrapper<Aut>&>(*this).automaton();
34  }
35  };
36 
38  template <Automaton Aut>
39  class automaton_wrapper final: public automaton_base
40  {
41  public:
42  using automaton_t = Aut;
43 
45  : automaton_(aut)
46  {}
47 
48  virtual symbol vname() const override
49  {
50  return automaton()->sname();
51  }
52 
54  {
55  return automaton_;
56  }
57 
58  const automaton_t& automaton() const
59  {
60  return automaton_;
61  }
62 
63  private:
66  };
67  }
68 
69  using automaton = std::shared_ptr<detail::automaton_base>;
70 
72  template <Automaton Aut>
73  inline
74  automaton
75  make_automaton(const Aut& aut)
76  {
77  return std::make_shared<detail::automaton_wrapper<Aut>>(aut);
78  }
79  }
80 }
automaton make_automaton(const Aut &aut)
Build a dyn::automaton.
Definition: automaton.hh:75
Definition: a-star.hh:8
To dyn_cast(From &&from)
A dynamic_cast in debug mode, static_cast with NDEBUG.
Definition: fwd.hh:16
automaton_t automaton_
The automaton.
Definition: automaton.hh:65
auto & as()
Extract wrapped typed automaton.
Definition: automaton.hh:24
symbol vname(T &t)
Definition: name.hh:101
boost::flyweight< std::string, boost::flyweights::no_tracking, boost::flyweights::intermodule_holder > symbol
An internalized string.
Definition: symbol.hh:23
#define LIBVCSN_API
Definition: export.hh:8
virtual symbol vname() const override
A description of the automaton, sufficient to build it.
Definition: automaton.hh:48
std::shared_ptr< detail::automaton_base > automaton
Definition: automaton.hh:69
auto & as() const
Extract wrapped typed automaton.
Definition: automaton.hh:31
Base class for automata.
Definition: automaton.hh:16
const automaton_t & automaton() const
Definition: automaton.hh:58
A wrapped typed automaton.
Definition: automaton.hh:39