17 #ifndef AWALI_ALGOS_JS_PRINT_EXP_HH
18 # define AWALI_ALGOS_JS_PRINT_EXP_HH
34 namespace awali {
namespace sttc {
178 template <
unsigned version = version::fsm_json>
183 version::check_fsmjson<version>();
188 auto gmt = std::gmtime(&tt);
191 std::stringstream ss;
192 ss << std::put_time(gmt,
"%F");
196 std::stringstream ss;
197 ss << std::put_time(gmt,
"%TZ");
204 template <
unsigned version = version::fsm_json>
209 version::check_fsmjson<version>();
217 template <
unsigned version = version::fsm_json>
222 version::check_fsmjson<version>();
230 template <
typename Automaton,
unsigned version = version::fsm_json>
237 version::check_fsmjson<version>();
238 auto ctx = aut->context();
239 auto ws = ctx.weightset();
240 auto ls = ctx.labelset();
245 root->
push_back(
"format", json_format<version>());
251 if(!aut->get_name().empty())
254 if(!aut->get_desc().empty())
257 metadata->
push_back(
"creator", json_creator<version>());
259 metadata->
push_back(
"timestamp", json_timestamp<version>());
261 for(
auto p : extra_metadata->fields)
262 metadata->
push_back(p.first, p.second->copy());
274 for(
unsigned i: aut->states()) {
277 if (aut->has_explicit_name(i))
280 if (aut->is_initial(i))
283 ws->template value_to_json<version>(aut->get_initial_weight(i))
285 if (aut->is_final(i))
288 ws->template value_to_json<version>(aut->get_final_weight(i)));
289 if (aut->has_history(i)) {
290 std::stringstream ss;
291 aut->print_state_history(i,ss);
294 states->push_back(one_state);
300 for(
unsigned i: aut->transitions()) {
304 unsigned src = aut->src_of(i);
309 unsigned dst = aut->dst_of(i);
316 ls->template value_to_json<version>(aut->label_of(i)));
319 if(!ws->is_one(aut->weight_of(i)) || ws->show_one()) {
322 ws->template value_to_json<version>(aut->weight_of(i)) );
331 return std::shared_ptr<json::object_t>(root);
335 template <
typename RatExpSet,
unsigned version = version::fsm_json>
339 const typename RatExpSet::ratexp_t& e,
342 version::check_fsmjson<version>();
346 root->
push_back(
"format", json_format<version>());
352 metadata->
push_back(
"creator", json_creator<version>());
354 metadata->
push_back(
"timestamp", json_timestamp<version>());
356 for(
auto p : extra_metadata->fields)
357 metadata->
push_back(p.first, p.second->copy());
361 root->
push_back(
"context",rs.context().template to_json<version>());
364 root->
push_back(
"data",rs.value_to_json(e));
366 return std::shared_ptr<json::object_t>(root);
object_t * push_back(std::string key, node_t *node)
carries the algebraic settings of automata
Definition: context.hh:40
std::vector< transition_t > transitions(abstract_automaton_t const *aut, bool all)
std::vector< state_t > states(abstract_automaton_t const *aut, bool all)
json_ast_t empty()
Builds an empty json_ast_t.
Definition: json_ast.hh:33
std::string to_string(identities i)
json::object_t * json_creator()
Definition: js_print.hh:207
json_ast_t aut_to_ast(Automaton aut, json_ast_t extra_metadata=json_ast::empty(), bool full=false)
Definition: js_print.hh:233
json::object_t * json_timestamp()
Definition: js_print.hh:181
json_ast_t ratexp_to_ast(const RatExpSet &rs, const typename RatExpSet::ratexp_t &e, json_ast_t extra_metadata=json_ast::empty())
Definition: js_print.hh:338
auto format(const ValueSet &vs, const typename ValueSet::value_t &v, Args &&... args) -> std::string
Format v via vs.print.
Definition: stream.hh:109
json::object_t * json_format()
Definition: js_print.hh:220
static const std::string full
Completely version of Awali as a std::string.
Definition: version.hh:42
Main namespace of Awali.
Definition: ato.hh:22
std::shared_ptr< json::object_t > json_ast_t
Definition: json_ast.hh:27