4 #include <unordered_map> 14 #include <vcsn/dyn/fwd.hh> 58 virtual bool open(
bool o) = 0;
64 virtual void reset() = 0;
83 template <Automaton Aut>
111 return const_cast<labelset_t&
>(*res_->context().labelset()).
open(o);
125 res_->state(s, res_->pre());
132 res_->state(s, res_->post());
138 res_->add_initial(state_(s), weight_(
weight));
144 res_->add_final(state_(s), weight_(
weight));
156 auto s = state_(src);
157 auto d = state_(dst);
158 res_->add_transition(s, d, label_(label), weight_(
weight));
165 auto s = state_(src);
166 auto d = state_(dst);
167 require(s != res_->pre() || d != res_->post(),
168 "edit_automaton: invalid transition from pre to post: ",
169 src,
" -> ", dst,
" (", entry,
")");
170 if (s == res_->pre() || d == res_->post())
172 if (entry.get().empty())
173 res_->add_transition(s, d, res_->prepost_label());
183 && (res_->labelset()->is_special(
label_of(*i))
184 || res_->labelset()->is_one(
label_of(*i))),
185 "edit_automaton: invalid ",
186 s == res_->pre() ?
"initial" :
"final",
187 " entry: ", entry.get());
188 res_->add_transition(s, d,
194 auto p = emap_.emplace(entry,
entry_t{});
196 p.first->second =
conv(ps_, entry,
sep_);
197 for (
auto e: p.first->second)
222 const auto& ls = *res_->labelset();
223 auto p = lmap_.emplace(l,
label_t{});
225 p.first->second =
conv(ls, l);
226 return p.first->second;
233 const auto& ws = *res_->weightset();
234 auto p = wmap_.emplace(w,
weight_t{});
236 p.first->second = w.get().empty() ? ws.one() :
conv(ws, w);
237 return p.first->second;
244 return res_->state(k);
253 using entry_map = std::unordered_map<string_t, entry_t>;
256 using label_map = std::unordered_map<string_t, label_t>;
298 std::string result_context()
const;
322 using transition_t = std::tuple<string_t, string_t, string_t, string_t>;
333 bool weighted_ =
false;
347 template <
typename Ctx>
351 const auto& c = ctx->
as<Ctx>();
typename detail::context_t_of_impl< base_t< ValueSet > >::type context_t_of
std::unordered_map< string_t, weight_t > weight_map
Memoize weight conversion.
void weightset(weightset_type t)
Specify the weightset type.
std::tuple< string_t, string_t, string_t, string_t > transition_t
The collected transitions: (Source, Destination, Label, Weight).
weight_t weight_(string_t w)
Convert a weight string to its value.
state_t state_(string_t k)
Convert a state name to a state handler.
weightset_type
Weightset types.
void add_pre(string_t s) override final
Register that state named s is preinitial.
virtual void add_entry(string_t src, string_t dst, string_t entry)=0
Add an entry from src to dst, with value entry.
auto label_of(const welement< Label, Weight > &m) -> decltype(m.label())
The label of a welement.
void add_state(string_t s) override final
Register the existence of state named s.
std::vector< transition_t > transitions_
void add_initial(string_t s, string_t weight=string_t{}) override final
super_t::string_t string_t
virtual dyn::automaton result()=0
The final result.
void add_entry(string_t src, string_t dst, string_t entry) override final
Add transitions from src to dst, labeled by entry.
typename detail::labelset_t_of_impl< base_t< ValueSet > >::type labelset_t_of
#define VCSN_REQUIRE(Cond,...)
A macro similar to require.
virtual void add_state(string_t s)=0
Register the existence of state named s.
auto conv(const ValueSet &vs, const std::string &str, Args &&... args) -> decltype(vs.conv(std::declval< std::istream &>(), std::forward< Args >(args)...))
Parse str via vs.conv.
virtual void add_pre(string_t s)=0
Declare that s denotes the preinitial state in entries.
std::unordered_map< string_t, label_t > label_map
Memoize label conversion.
edit_automaton(const context_t &ctx)
char sep_
The label separator.
void add_final(string_t s, string_t weight=string_t{}) override final
labelset_type
Labelset types, increasing generality.
typename detail::label_t_of_impl< base_t< ValueSet > >::type label_t_of
SharedPtr make_shared_ptr(Args &&... args)
Same as std::make_shared, but parameterized by the shared_ptr type, not the (pointed to) element_type...
virtual void add_transition(string_t src, string_t dst, string_t label, string_t weight=string_t{})=0
Add a transition from src to dst.
virtual void reset()=0
Forget about the current automaton, but do not free it.
auto weight_of(const welement< Label, Weight > &m) -> decltype(m.weight())
The weight of a welement.
void add_transition(string_t src, string_t dst, string_t label, string_t weight=string_t{}) override final
Add a transition from src to dst.
std::unordered_map< string_t, entry_t > entry_map
Memoize entry conversion.
automaton_editor * make_automaton_editor(const context &ctx)
Bridge.
std::vector< std::pair< string_t, string_t > > initial_states_
The collected initial states: (State, Weight).
typename polynomialset< context_t >::value_t entry_t
label_t_of< automaton_t > label_t
Abstract Builder (the design pattern) for automata.
virtual void add_post(string_t s)=0
Declare that s denotes the postfinal state in entries.
Template-less root for contexts.
auto & as()
Downcast to the exact type.
labelset_t_of< automaton_t > labelset_t
value_impl< detail::weight_tag > weight
automaton_t res_
The automaton under construction.
label_t label_(string_t l)
Convert a label string to its value.
void require(Bool b, Args &&... args)
If b is not verified, raise an error with args as message.
virtual void add_initial(string_t s, string_t w)=0
value_impl< detail::label_tag > label
dyn::automaton result() override final
Return the built automaton.
std::vector< std::pair< string_t, string_t > > final_states_
The collected final states: (State, Weight).
context_t_of< automaton_t > context_t
void reset() override final
Detach the built automaton.
virtual ~automaton_editor()
boost::flyweight< std::string, boost::flyweights::no_tracking, boost::flyweights::intermodule_holder > symbol
An internalized string.
automaton_editor::string_t string_t
A hash-cons'ed string type.
typename detail::state_t_of_impl< base_t< ValueSet > >::type state_t_of
Provide a variadic mul on top of a binary mul(), and one().
state_t_of< automaton_t > state_t
typename detail::weight_t_of_impl< base_t< ValueSet > >::type weight_t_of
weight_t_of< automaton_t > weight_t
void set_separator(char c)
Set the label separator. Defaults to '+'.
std::shared_ptr< detail::name_automaton_impl< Aut > > name_automaton
void add_post(string_t s) override final
Register that state named s is postfinal.
Build an automaton with unknown context.
name_automaton< Aut > automaton_t
polynomialset< context_t > ps_
Entries handler.
bool open(bool o) override final
Whether unknown letters should be added, or rejected.
virtual bool open(bool o)=0
Whether unknown letters should be added, or rejected.
virtual void add_final(string_t s, string_t w)=0
Concrete Builder (the design pattern) for automata.