Vcsn  2.2
Be Rational
context.hh
Go to the documentation of this file.
1 #pragma once
2 
3 #include <memory>
4 #include <string>
5 
6 #include <vcsn/ctx/fwd.hh> // vcsn::context
7 #include <vcsn/dyn/fwd.hh>
8 #include <vcsn/misc/export.hh>
9 #include <vcsn/misc/symbol.hh>
10 
11 namespace vcsn
12 {
13  namespace dyn
14  {
15  namespace detail
16  {
19  {
20  public:
22  virtual symbol vname() const = 0;
23 
25  template <typename Ctx>
26  auto& as()
27  {
28  return dyn_cast<context_wrapper<Ctx>&>(*this).context();
29  }
30 
32  template <typename Ctx>
33  auto& as() const
34  {
35  return dyn_cast<const context_wrapper<Ctx>&>(*this).context();
36  }
37  };
38 
40  template <typename Context>
41  class context_wrapper final: public context_base
42  {
43  public:
44  using context_t = Context;
46 
48  : context_(context)
49  {}
50 
51  virtual symbol vname() const override
52  {
53  return context().sname();
54  }
55 
56  const context_t& context() const
57  {
58  return context_;
59  }
60 
61  private:
64  };
65 
66  } // namespace detail
67 
69  template <typename LabelSet, typename WeightSet>
70  inline
71  context
73  {
74  using context_t = vcsn::context<LabelSet, WeightSet>;
75  return std::make_shared<detail::context_wrapper<context_t>>(ctx);
76  }
77  }
78 }
virtual symbol vname() const override
A description of the context, sufficient to build it.
Definition: context.hh:51
auto & as()
Downcast to the exact type.
Definition: context.hh:26
A wrapped typed context.
Definition: context.hh:41
context_wrapper(const context_t &context)
Definition: context.hh:47
Definition: a-star.hh:8
To dyn_cast(From &&from)
A dynamic_cast in debug mode, static_cast with NDEBUG.
Definition: fwd.hh:16
symbol vname(T &t)
Definition: name.hh:101
auto & as() const
Downcast to the exact type.
Definition: context.hh:33
boost::flyweight< std::string, boost::flyweights::no_tracking, boost::flyweights::intermodule_holder > symbol
An internalized string.
Definition: symbol.hh:23
std::shared_ptr< const detail::context_base > context
A dyn::context.
Definition: fwd.hh:43
#define LIBVCSN_API
Definition: export.hh:8
Template-less root for contexts.
Definition: context.hh:18
context make_context(const std::string &name)
Build a context from its name.
Definition: others.cc:99
static dyn::context ctx(const driver &d)
Get the context of the driver.
Definition: parse.cc:82
const context_t context_
The context.
Definition: context.hh:63
const context_t & context() const
Definition: context.hh:56