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>
187 auto gmt = std::gmtime(&tt);
190 std::stringstream ss;
191 ss << std::put_time(gmt,
"%F");
195 std::stringstream ss;
196 ss << std::put_time(gmt,
"%TZ");
203 template <
unsigned version = version::fsm_json>
215 template <
unsigned version = version::fsm_json>
227 template <
typename Automaton,
unsigned version = version::fsm_json>
234 auto ctx = aut->context();
235 auto ws = ctx.weightset();
236 auto ls = ctx.labelset();
241 root->
push_back(
"format", json_format<version>());
247 if(!aut->get_name().empty())
250 if(!aut->get_desc().empty())
253 metadata->
push_back(
"creator", json_creator<version>());
255 metadata->
push_back(
"timestamp", json_timestamp<version>());
257 for(
auto p : extra_metadata->fields)
258 metadata->
push_back(p.first, p.second->copy());
270 for(
unsigned i: aut->states()) {
273 if (aut->has_explicit_name(i))
276 if (aut->is_initial(i))
279 ws->template value_to_json<version>(aut->get_initial_weight(i))
281 if (aut->is_final(i))
284 ws->template value_to_json<version>(aut->get_final_weight(i)));
285 states->push_back(one_state);
291 for(
unsigned i: aut->transitions()) {
295 unsigned src = aut->src_of(i);
300 unsigned dst = aut->dst_of(i);
307 ls->template value_to_json<version>(aut->label_of(i)));
310 if(!ws->is_one(aut->weight_of(i)) || ws->show_one()) {
313 ws->template value_to_json<version>(aut->weight_of(i)) );
322 return std::shared_ptr<json::object_t>(root);
326 template <
typename RatExpSet,
unsigned version = version::fsm_json>
330 const typename RatExpSet::ratexp_t& e,
336 root->
push_back(
"format", json_format<version>());
342 metadata->
push_back(
"creator", json_creator<version>());
344 metadata->
push_back(
"timestamp", json_timestamp<version>());
346 for(
auto p : extra_metadata->fields)
347 metadata->
push_back(p.first, p.second->copy());
351 root->
push_back(
"context",rs.context().template to_json<version>());
354 root->
push_back(
"data",rs.value_to_json(e));
356 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:206
json_ast_t aut_to_ast(Automaton aut, json_ast_t extra_metadata=json_ast::empty(), bool full=false)
Definition: js_print.hh:230
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:329
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:218
static const std::string full
Completely version of Awali as a std::string.
Definition: version.hh:40
Main namespace of Awali.
Definition: ato.hh:22
std::shared_ptr< json::object_t > json_ast_t
Definition: json_ast.hh:27