Vcsn  2.0
Be Rational
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
make-context.hh
Go to the documentation of this file.
1 #ifndef VCSN_ALGOS_MAKE_CONTEXT_HH
2 # define VCSN_ALGOS_MAKE_CONTEXT_HH
3 
4 # include <sstream>
5 
7 # include <vcsn/ctx/fwd.hh>
8 # include <vcsn/dyn/automaton.hh>
9 # include <vcsn/dyn/context.hh>
10 # include <vcsn/dyn/ratexpset.hh>
11 # include <vcsn/misc/raise.hh>
12 
13 namespace vcsn
14 {
15 
16  /*---------------.
17  | make_context. |
18  `---------------*/
19 
20  template <typename Ctx>
21  Ctx
22  make_context(const std::string& name)
23  {
24  std::istringstream is{name};
25  auto res = Ctx::make(is);
26  // Something extremely weird is going wrong with str_escape when
27  // called here from Python. I have not been able to understand
28  // what the problem was, and maybe it's actually a problem bw the
29  // compiler (clang 3.4), the c++ lib (libstc++), and Python, and
30  // possibly Boost after all.
31  //
32  // The good news is that this seems to work properly.
33  if (is.peek() != -1)
34  raise(__func__, ": invalid context name: ", str_escape(name),
35  ", unexpected ", str_escape(is.peek()));
36  return res;
37  }
38 
39  namespace dyn
40  {
41  namespace detail
42  {
44  template <typename Ctx>
45  context
46  make_context(const std::string& name)
47  {
48  return dyn::make_context(vcsn::make_context<Ctx>(name));
49  }
50 
52  (const std::string& name) -> context);
53  }
54  }
55 
56 
57  /*-------------.
58  | context_of. |
59  `-------------*/
60 
61  namespace dyn
62  {
63  namespace detail
64  {
66  template <typename Aut>
67  context
68  context_of(const automaton& aut)
69  {
70  const auto& a = aut->as<Aut>();
71  return dyn::make_context(a->context());
72  }
73 
75  (const automaton& aut) -> context);
76 
78  template <typename RatExpSet>
79  context
81  {
82  const auto& e = exp->as<RatExpSet>().ratexpset();
83  return dyn::make_context(e.context());
84  }
85 
87  (const ratexp& exp) -> context);
88  }
89  }
90 
91 
92 
93  /*-----------------.
94  | make_ratexpset. |
95  `-----------------*/
96 
97  namespace dyn
98  {
99  namespace detail
100  {
101 
102  template <typename Ctx, typename Identities>
103  ratexpset
105  {
106  const auto& c = ctx->as<Ctx>();
108  }
109 
111  (const context& ctx, ::vcsn::rat::identities ids)
112  -> ratexpset);
113  }
114  }
115 
116  /*--------------------.
117  | make_word_context. |
118  `--------------------*/
119 
120  namespace dyn
121  {
122  namespace detail
123  {
124 
125  template <typename Ctx>
126  context
128  {
129  const auto& c = ctx->as<Ctx>();
131  }
132 
134  (const context& ctx) -> context);
135  }
136  }
137 
138 } // vcsn::
139 
140 #endif // !VCSN_ALGOS_MAKE_CONTEXT_HH
context make_context(const std::string &name)
Build a context from its name.
Definition: make-context.cc:38
context make_word_context(const context &ctx)
REGISTER_DECLARE(accessible,(const automaton &) -> automaton)
std::shared_ptr< detail::automaton_base > automaton
Definition: automaton.hh:71
word_context_t< context< LabelSet, WeightSet > > make_word_context(const context< LabelSet, WeightSet > &ctx)
The wordset context of a context.
Definition: labelset.hh:88
context make_context(const std::string &name)
Bridge.
Definition: make-context.hh:46
std::ostream & str_escape(std::ostream &os, const std::string &str)
Output a string, escaping special characters.
Definition: escape.cc:43
std::shared_ptr< detail::ratexp_base > ratexp
Definition: fwd.hh:64
context context_of(const automaton &aut)
Bridge.
Definition: make-context.hh:68
context context_of_ratexp(const ratexp &exp)
Bridge.
Definition: make-context.hh:80
std::shared_ptr< const detail::ratexpset_base > ratexpset
Definition: fwd.hh:73
std::istringstream is
The input stream: the specification to translate.
Definition: translate.cc:329
Provide a variadic mul on top of a binary mul(), and one().
Definition: fwd.hh:36
std::shared_ptr< const detail::context_base > context
Definition: context.hh:71
ratexpset make_ratexpset(const context &ctx,::vcsn::rat::identities ids)
identities
A ratexpset can implement several different sets of identities on expressions.
Definition: identities.hh:17
Ctx make_context(const std::string &name)
Definition: make-context.hh:22