Awali
Another Weighted Automata library
sys.hh
Go to the documentation of this file.
1 // This file is part of Awali.
2 // Copyright 2016-2022 Sylvain Lombardy, Victor Marsault, Jacques Sakarovitch
3 //
4 // Awali is a free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 #ifndef DYN_ALGOS_SYS_HH
18 #define DYN_ALGOS_SYS_HH
19 
20 #include<stdio.h>
21 
22 #include <awali/common/json_ast.hh>
23 
25 #include <awali/dyn/core/ratexp.hh>
28 
29 namespace awali {
30 namespace dyn {
31 
32 // /** Computes geometry of \p aut with program dot and displays it with dotty.
33 // * @param aut Automaton to display
34 // * @param opts A set of options; {@link KEEP_HISTORY},
35 // * {@link LAYOUT} are meaningful.
36 // */
37 // void display(automaton_t aut, options_t opts = {});
38 
39 
46  void pdfdisplay(automaton_t aut, options_t opts = {});
47 
48 
54  automaton_t parse_automaton(std::istream& in, options_t opts = {});
55 
56 
65  std::ostream& put(automaton_t aut, std::ostream& o, options_t opts = {});
66 
67  std::ostream& put(ratexp_t aut, std::ostream& o, options_t opts = {});
68 
69 
78  void save(const automaton_t aut, const std::string& path, options_t opts ={});
79 
80 
86  automaton_t load(const std::string& path, options_t opts={});
87 
89  ratexp_t load_exp(const std::string& filepath);
90 
91  namespace internal {
92  // This function returns by reference into b whether the automaton is an
93  // example automaton.
94  automaton_t load(const std::string& filename,
95  bool& is_example,
97  }
98 
100  extern std::ostream *error_stream ;
101 
103  extern std::ostream *warning_stream;
104 
106  void set_error_stream(std::ostream & o);
107 
109  void set_warning_stream(std::ostream & o);
110 
111 
112  namespace internal {
114  private :
115  io_format_t format;
116  std::ostream& o;
117  public :
118  formatted_ostream(io_format_t fmt, std::ostream& o)
119  : format(fmt), o(o) {}
120 
121  std::ostream& operator<<(ratexp_t aut);
122  std::ostream& operator<<(automaton_t aut);
123  std::ostream& operator<<(transducer_t aut);
124  };
125 
127  private :
128  io_format_t format;
129  std::istream& i;
130  public :
131  formatted_istream(io_format_t fmt, std::istream& i)
132  : format(fmt), i(i) {}
133 
134  std::istream& operator>>(automaton_t& aut);
135  };
136  }
137 
138  std::ostream& operator<<(std::ostream& o, automaton_t aut);
139  std::ostream& operator<<(std::ostream& o, transducer_t aut);
141  io_format_t const fmt);
142  std::istream& operator>>(std::istream& i, automaton_t& aut);
144  io_format_t const fmt);
145 
146 
147  namespace internal {
153  json_ast_t load_json_ast(bool& found, std::string const& filename,
154  bool recurse = false);
155 
157  json_ast_t load_json_ast(std::string const& filename,
158  bool recurse= false);
159 
160 
161  struct aut_or_exp_t {
162  bool is_aut = true;
163  union {
164  automaton_t aut;
165  ratexp_t exp;
166  };
167  aut_or_exp_t() : is_aut(true), aut() {}
169  aut_or_exp_t(aut_or_exp_t const& other);
170  aut_or_exp_t(ratexp_t e) : is_aut(false), exp(e) {}
171  aut_or_exp_t(automaton_t a) : is_aut(true), aut(a) {}
172 
174 
183  };
184 
185 
186  aut_or_exp_t load_aut_or_exp(std::string const& name, bool recurse = false);
188 
189  }
192 
193 }}//end of ns awali::dyn
194 
195 
196 
197 #endif
An automaton_t is essentially a shared pointer to an abstract_automaton_t, but also contains static f...
Definition: automaton.hh:93
An options_t is a set of optional parameters that is passed on to called functions.
Definition: options.hh:86
Main class for representing rational expresson at the dynamical layer.
Definition: ratexp.hh:66
io_format_t
The different format for input/output of automata and expressions.
Definition: enums.hh:123
@ JSON
The current Awali format.
Definition: enums.hh:128
automaton_t load(const std::string &filename, bool &is_example, io_format_t format=JSON)
aut_or_exp_t load_aut_or_exp(std::string const &name, bool recurse=false)
json_ast_t load_json_ast(bool &found, std::string const &filename, bool recurse=false)
Loads a json file as an AST (possibly an example).
aut_or_exp_t parse_aut_or_exp(json_ast_t ast)
automaton_t load(const std::string &path, options_t opts={})
Loads an automaton from file pointed by path.
std::ostream & operator<<(std::ostream &o, automaton_t aut)
std::istream & operator>>(std::istream &i, automaton_t &aut)
automaton_t parse_automaton(std::istream &in, options_t opts={})
Parse an automaton from.
ratexp_t load_exp(const std::string &filepath)
Loads a ratexp_t from file filepath
void set_warning_stream(std::ostream &o)
Setter for the warning_stream of the dynamical layer.
std::ostream * error_stream
A pointer to the error_stream used at dynamical layer.
std::ostream * warning_stream
A pointer to the error_stream used at dynamical layer.
std::ostream & put(automaton_t aut, std::ostream &o, options_t opts={})
Write aut to output stream o.
void pdfdisplay(automaton_t aut, options_t opts={})
Computes geometry of aut with program dot and displays with a pdf-viewer.
void save(const automaton_t aut, const std::string &path, options_t opts={})
Writes aut to file pointed by path.
ratexp_t parse_ratexp(json_ast_t ast)
void set_error_stream(std::ostream &o)
Setter for the error_stream of the dynamical layer.
auto format(const ValueSet &vs, const typename ValueSet::value_t &v, Args &&... args) -> std::string
Format v via vs.print.
Definition: stream.hh:109
Main namespace of Awali.
Definition: ato.hh:22
std::shared_ptr< json::object_t > json_ast_t
Definition: json_ast.hh:27
aut_or_exp_t()
Definition: sys.hh:167
aut_or_exp_t(aut_or_exp_t const &other)
bool split_case(automaton_t &a, ratexp_t &e)
Returns field is_aut and assign either a or e to the content of this.
aut_or_exp_t(automaton_t a)
Definition: sys.hh:171
bool is_aut
Definition: sys.hh:162
aut_or_exp_t & operator=(aut_or_exp_t const &other)
aut_or_exp_t(ratexp_t e)
Definition: sys.hh:170
formatted_istream(io_format_t fmt, std::istream &i)
Definition: sys.hh:131
std::istream & operator>>(automaton_t &aut)
std::ostream & operator<<(transducer_t aut)
formatted_ostream(io_format_t fmt, std::ostream &o)
Definition: sys.hh:118
std::ostream & operator<<(automaton_t aut)
std::ostream & operator<<(ratexp_t aut)
Definition: transducer.hh:30