Vcsn  2.0
Be Rational
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
context.hh
Go to the documentation of this file.
1 #ifndef VCSN_DYN_CONTEXT_HH
2 # define VCSN_DYN_CONTEXT_HH
3 
4 # include <memory>
5 # include <string>
6 
7 # include <vcsn/dyn/fwd.hh>
8 # include <vcsn/misc/export.hh>
9 
10 namespace vcsn
11 {
12  namespace dyn
13  {
14  namespace detail
15  {
18  {
19  public:
23  virtual std::string vname(bool full = true) const = 0;
24 
27  static std::string sname(const std::string& vname);
28 
29  template <typename Ctx>
30  Ctx as()
31  {
32  return dynamic_cast<context_wrapper<Ctx>&>(*this).context();
33  }
34 
35  template <typename Ctx>
36  const Ctx as() const
37  {
38  return dynamic_cast<const context_wrapper<Ctx>&>(*this).context();
39  }
40  };
41 
43  template <typename Context>
45  {
46  public:
47  using context_t = Context;
49 
51  : context_(context)
52  {}
53 
54  virtual std::string vname(bool full = true) const override
55  {
56  return context().vname(full);
57  }
58 
59  const context_t context() const
60  {
61  return context_;
62  }
63 
64  protected:
67  };
68 
69  } // namespace detail
70 
71  using context = std::shared_ptr<const detail::context_base>;
72 
73  template <typename Context>
74  inline
75  context
76  make_context(const Context& ctx)
77  {
78  return std::make_shared<detail::context_wrapper<Context>>(ctx);
79  }
80 
81  }
82 
83 }
84 
85 #endif // !VCSN_DYN_CONTEXT_HH
context make_context(const std::string &name)
Build a context from its name.
Definition: make-context.cc:38
const context_t context() const
Definition: context.hh:59
Template-less root for contexts.
Definition: context.hh:17
A wrapped typed context.
Definition: context.hh:44
context_wrapper(const context_t &context)
Definition: context.hh:50
std::string sname()
Definition: name.hh:31
const Ctx as() const
Definition: context.hh:36
virtual std::string vname(bool full=true) const override
A description of the context, sufficient to build it.
Definition: context.hh:54
std::string vname(T &t)
Definition: name.hh:65
std::shared_ptr< const detail::context_base > context
Definition: context.hh:71
const context_t context_
The context.
Definition: context.hh:66
#define LIBVCSN_API
Definition: export.hh:9