Vcsn  2.0
Be Rational
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
read.cc
Go to the documentation of this file.
1 #include <stdexcept>
2 
3 #include <vcsn/ctx/fwd.hh>
4 #include <vcsn/dyn/algos.hh>
5 #include <vcsn/algos/read.hh>
6 #include <lib/vcsn/rat/read.hh>
7 #include <lib/vcsn/dot/driver.hh>
8 #include <lib/vcsn/algos/fwd.hh>
10 
11 namespace vcsn
12 {
13 
14  namespace dyn
15  {
16 
17  /*-----------------.
18  | read_automaton. |
19  `-----------------*/
20 
21  namespace
22  {
23  automaton read_dot(std::istream& is)
24  {
26  auto res = d.parse(is);
27  if (!d.errors.empty())
28  raise(d.errors);
29  return res;
30  }
31  }
32 
33  automaton
34  read_automaton(std::istream& is, const std::string& t)
35  {
36  if (t == "dot" || t == "default" || t == "")
37  return read_dot(is);
38  else if (t == "efsm")
39  return read_efsm(is);
40  else if (t == "fado")
41  return read_fado(is);
42  else
43  raise(t + ": unknown format");
44  }
45 
46  /*-------------.
47  | read_label. |
48  `-------------*/
49 
50  REGISTER_DEFINE(read_label);
51  label
52  read_label(std::istream& is, const dyn::context& ctx)
53  {
54  return detail::read_label_registry().call(is, ctx);
55  }
56 
57  /*--------------.
58  | read_ratexp. |
59  `--------------*/
60 
61  ratexp
62  read_ratexp(std::istream& is, const ratexpset& rs,
63  const std::string& t)
64  {
65  if (t == "text" || t == "default" || t == "")
66  return rat::read(is, rs);
67  else
68  raise("invalid input format for ratexp: ", t);
69  }
70 
71 
72  /*------------------.
73  | read_polynomial. |
74  `------------------*/
75 
76  REGISTER_DEFINE(read_polynomial);
78  read_polynomial(std::istream& is, const dyn::context& ctx)
79  {
80  return detail::read_polynomial_registry().call(ctx, is);
81  }
82 
83  /*--------------.
84  | read_weight. |
85  `--------------*/
86 
87  REGISTER_DEFINE(read_weight);
88  weight
89  read_weight(std::istream& is, const dyn::context& ctx)
90  {
91  return detail::read_weight_registry().call(ctx, is);
92  }
93 
94  }
95 
96 } // vcsn::
label read_label(std::istream &is, const context &ctx)
Read a label from a stream.
Definition: read.cc:52
std::shared_ptr< detail::automaton_base > automaton
Definition: automaton.hh:71
State and public interface for Dot parsing.
Definition: driver.hh:21
automaton read_fado(std::istream &is)
Definition: fado.cc:24
std::shared_ptr< const detail::weight_base > weight
Definition: fwd.hh:82
std::shared_ptr< detail::ratexp_base > ratexp
Definition: fwd.hh:64
dyn::ratexp read(std::istream &is, const dyn::ratexpset &rs, const location &l)
The ratexp in stream is, with rs as default ratexpset.
Definition: read.cc:12
std::string errors
The error messages.
Definition: driver.hh:37
std::shared_ptr< const detail::ratexpset_base > ratexpset
Definition: fwd.hh:73
weight read_weight(std::istream &is, const context &ctx)
Read a weight from a stream.
Definition: read.cc:89
std::istringstream is
The input stream: the specification to translate.
Definition: translate.cc:329
polynomial read_polynomial(std::istream &is, const context &ctx)
Read a polynomial from a stream.
Definition: read.cc:78
std::shared_ptr< const detail::label_base > label
Definition: fwd.hh:46
std::shared_ptr< const detail::context_base > context
Definition: context.hh:71
automaton read_automaton(std::istream &is, const std::string &format="default")
Read an automaton from a stream.
Definition: read.cc:34
ratexp read_ratexp(std::istream &is, const ratexpset &rs, const std::string &format="default")
Read a ratexp from a stream.
Definition: read.cc:62
dyn::automaton parse(std::istream &is, const location_t &l=location_t{})
Parse this stream.
Definition: driver.cc:30
std::shared_ptr< const detail::polynomial_base > polynomial
Definition: fwd.hh:55
automaton read_efsm(std::istream &is)
Definition: efsm.cc:72