Vcsn  2.3
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  /*---------------.
16  | make_context. |
17  `---------------*/
18 
20  template <typename Ctx>
21  Ctx
22  make_context(const std::string& name)
23  {
24  std::istringstream is{name};
25  try
26  {
27  auto res = Ctx::make(is);
28  require(is.peek() == EOF, "unexpected trailing characters: ", is);
29  return res;
30  }
31  catch (const std::runtime_error& e)
32  {
33  raise(e, " while reading context: ", name);
34  }
35  }
36 
37  namespace dyn
38  {
39  namespace detail
40  {
42  template <typename Ctx>
43  context
44  make_context(const std::string& name)
45  {
46  return vcsn::make_context<Ctx>(name);
47  }
48  }
49  }
50 
51 
52  /*-------------.
53  | context_of. |
54  `-------------*/
55 
56  namespace dyn
57  {
58  namespace detail
59  {
61  template <Automaton Aut>
62  context
63  context_of(const automaton& aut)
64  {
65  const auto& a = aut->as<Aut>();
66  return context(a->context());
67  }
68 
70  template <typename ExpSet>
71  context
73  {
74  const auto& e = exp->as<ExpSet>().valueset();
75  return e.context();
76  }
77 
79  template <typename ExpansionSet>
80  context
82  {
83  const auto& e = exp->as<ExpansionSet>().valueset();
84  return e.context();
85  }
86 
88  template <typename PolynomialSet>
89  context
91  {
92  const auto& p = poly->as<PolynomialSet>().valueset();
93  return p.context();
94  }
95  }
96  }
97 
98 
99  /*--------.
100  | join. |
101  `--------*/
102 
103  namespace dyn
104  {
105  namespace detail
106  {
108  template <typename Ctx1, typename Ctx2>
109  context
110  join(const context& c1, const context& c2)
111  {
112  return join(c1->as<Ctx1>(), c2->as<Ctx2>());
113  }
114  }
115  }
116 
117 
118 
119  /*--------------------.
120  | make_word_context. |
121  `--------------------*/
122 
123  namespace dyn
124  {
125  namespace detail
126  {
128  template <typename Ctx>
129  context
131  {
132  const auto& c = ctx->as<Ctx>();
134  }
135  }
136  }
137 
138 
139  /*-------------.
140  | num_tapes. |
141  `-------------*/
142 
143  template <typename Ctx>
144  constexpr auto
145  num_tapes(const Ctx&)
146  -> std::enable_if_t<Ctx::is_lat, size_t>
147  {
148  return Ctx::labelset_t::size();
149  }
150 
151  template <typename Ctx>
152  constexpr auto
153  num_tapes(const Ctx&)
154  -> std::enable_if_t<!Ctx::is_lat, size_t>
155  {
156  return 0;
157  }
158 
159  namespace dyn
160  {
161  namespace detail
162  {
164  template <typename Ctx>
165  size_t
167  {
168  return vcsn::num_tapes(ctx->as<Ctx>());
169  }
170  }
171  }
172 }
size_t num_tapes(const context &ctx)
Bridge.
Ctx make_context(const std::string &name)
Build a context from its name.
Definition: make-context.hh:22
context context_of(const automaton &aut)
Bridge.
Definition: make-context.hh:63
size_t size(const ExpSet &rs, const typename ExpSet::value_t &r)
void require(Bool b, Args &&...args)
If b is not verified, raise an error with args as message.
Definition: raise.hh:91
auto & as()
Downcast to the exact type.
Definition: context.hh:36
A dyn Value/ValueSet.
Definition: fwd.hh:23
return res
Definition: multiply.hh:398
context context_of_polynomial(const polynomial &poly)
Bridge (context_of).
Definition: make-context.hh:90
context make_word_context(const context &ctx)
Bridge.
Template-less root for contexts.
Definition: context.hh:16
Definition: a-star.hh:8
A dyn automaton.
Definition: automaton.hh:17
context join(const context &c1, const context &c2)
Bridge.
context make_context(const std::string &name)
Bridge.
Definition: make-context.hh:44
context context_of_expression(const expression &exp)
Bridge (context_of).
Definition: make-context.hh:72
auto & as()
Extract wrapped typed value.
Definition: value.hh:53
auto & as()
Extract wrapped typed automaton.
Definition: automaton.hh:37
context context_of_expansion(const expansion &exp)
Bridge (context_of).
Definition: make-context.hh:81
value_impl< detail::expression_tag > expression
Definition: fwd.hh:25
constexpr auto num_tapes(const Ctx &) -> std::enable_if_t< Ctx::is_lat, size_t >