Vcsn  2.8
Be Rational
make-context.hh
Go to the documentation of this file.
1 #pragma once
2 
3 #include <sstream>
4 
6 #include <vcsn/ctx/fwd.hh>
7 #include <vcsn/dyn/automaton.hh>
8 #include <vcsn/dyn/context.hh>
9 #include <vcsn/dyn/value.hh>
10 #include <vcsn/misc/raise.hh>
11 
12 namespace vcsn
13 {
14  /*---------------.
15  | make_context. |
16  `---------------*/
17 
19  template <typename Ctx>
20  Ctx
21  make_context(const std::string& name)
22  {
23  std::istringstream is{name};
24  try
25  {
26  auto res = Ctx::make(is);
27  require(is.peek() == EOF, "unexpected trailing characters: ", is);
28  return res;
29  }
30  catch (const std::runtime_error& e)
31  {
32  raise(e, " while reading context: ", str_quote(name));
33  }
34  }
35 
36  namespace dyn
37  {
38  namespace detail
39  {
41  template <typename Ctx>
42  context
43  make_context(const std::string& name)
44  {
45  return vcsn::make_context<Ctx>(name);
46  }
47  }
48  }
49 
50 
51  /*-------------.
52  | context_of. |
53  `-------------*/
54 
55  namespace dyn
56  {
57  namespace detail
58  {
60  template <Automaton Aut>
61  context
62  context_of(const automaton& aut)
63  {
64  const auto& a = aut->as<Aut>();
65  return context(a->context());
66  }
67 
69  template <typename ExpSet>
70  context
72  {
73  const auto& e = exp->as<ExpSet>().valueset();
74  return e.context();
75  }
76 
78  template <typename ExpansionSet>
79  context
81  {
82  const auto& e = exp->as<ExpansionSet>().valueset();
83  return e.context();
84  }
85 
87  template <typename PolynomialSet>
88  context
90  {
91  const auto& p = poly->as<PolynomialSet>().valueset();
92  return p.context();
93  }
94  }
95  }
96 
97 
98  /*--------.
99  | join. |
100  `--------*/
101 
102  namespace dyn
103  {
104  namespace detail
105  {
107  template <typename Ctx1, typename Ctx2>
108  context
109  join(const context& c1, const context& c2)
110  {
111  return join(c1->as<Ctx1>(), c2->as<Ctx2>());
112  }
113  }
114  }
115 
116 
117 
118  /*--------------------.
119  | make_word_context. |
120  `--------------------*/
121 
122  namespace dyn
123  {
124  namespace detail
125  {
127  template <typename Ctx>
128  context
130  {
131  const auto& c = ctx->as<Ctx>();
133  }
134  }
135  }
136 }
A dyn automaton.
Definition: automaton.hh:17
context make_context(const std::string &name)
Bridge.
Definition: make-context.hh:43
context make_word_context(const context &ctx)
Bridge.
auto & as()
Extract wrapped typed value.
Definition: value.hh:55
context join(const context &c1, const context &c2)
Bridge.
Ctx make_context(const std::string &name)
Build a context from its name.
Definition: make-context.hh:21
A dyn Value/ValueSet.
Definition: fwd.hh:29
context context_of_expression(const expression &exp)
Bridge (context_of).
Definition: make-context.hh:71
Template-less root for contexts.
Definition: context.hh:16
context context_of_polynomial(const polynomial &poly)
Bridge (context_of).
Definition: make-context.hh:89
Definition: a-star.hh:8
auto & as()
Downcast to the exact type.
Definition: context.hh:36
context context_of(const automaton &aut)
Bridge.
Definition: make-context.hh:62
auto & as()
Extract wrapped typed automaton.
Definition: automaton.hh:37
value_impl< detail::expression_tag > expression
Definition: fwd.hh:31
std::string str_quote(Args &&... args)
Convert to a string, in quotes.
Definition: escape.hh:49
context context_of_expansion(const expansion &exp)
Bridge (context_of).
Definition: make-context.hh:80
void require(Bool b, Args &&... args)
If b is not verified, raise an error with args as message.
Definition: raise.hh:87
return res
Definition: multiply.hh:399