8 #include <boost/bimap.hpp>
9 #include <boost/bimap/unordered_set_of.hpp>
57 using label_t =
typename labelset_t::value_t;
58 using weight_t =
typename weightset_t::value_t;
68 o <<
"tuple_automaton";
99 format fmt = {},
bool delimit =
false)
const
107 format fmt = {},
bool delimit =
false)
const
113 = boost::bimap<boost::bimaps::unordered_set_of<state_name_t>,
114 boost::bimaps::unordered_set_of<state_t>>;
115 using map_t =
typename bimap_t::left_map;
128 template <std::size_t... I>
136 template <
typename... T>
139 std::string
res =
"<" ;
140 using swallow =
int[];
141 const char* sep =
"";
144 (res += sep + t, sep =
", ", 0)...
161 template <
size_t... I>
166 aut_->print_set(o, fmt);
168 const char* sep =
"";
169 using swallow =
int[];
181 state_name_t pre_() const
183 return pre_(indices);
186 template <size_t... I>
187 state_name_t pre_(seq<I...>) const
189 // clang 3.4 on top of libstdc++ wants this ctor to be
190 // explicitly called.
191 return state_name_t{(std::get<I>(auts_)->pre())...};
195 state_name_t post_() const
197 return post_(indices);
200 template <size_t... I>
201 state_name_t post_(seq<I...>) const
203 // clang 3.4 on top of libstdc++ wants this ctor to be
204 // explicitly called.
205 return state_name_t{(std::get<I>(auts_)->post())...};
214 template <bool Lazy = false>
215 state_t state(const state_name_t& state)
217 auto lb = pmap_().find(state);
218 if (lb == pmap_().end())
220 state_t s = aut_->new_state();
222 aut_->set_lazy(s, true);
223 lb = pmap_().insert(lb, {state, s});
224 todo_.emplace_back(state, s);
229 template <bool Lazy = false>
230 state_t state(state_t_of<Auts>... ss)
232 return state<Lazy>(std::make_tuple(ss...));
235 template <size_t... I>
237 print_state_name_(state_t s, std::ostream& o, format fmt,
238 bool delimit, seq<I...> indices) const
240 const auto& origs = origins();
241 auto i = origs.find(s);
242 if (i == std::end(origs))
243 this->print_state(s, o);
245 print_state_name_(i->second, o, fmt, delimit, indices);
249 template <size_t... I>
251 print_state_name_(const state_name_t& sn, std::ostream& o,
252 format fmt, bool delimit, seq<I...>) const
256 const char* sep = "";
257 using swallow = int[];
261 std::get<I>(auts_)->print_state_name(std::get<I>(sn),
283 mutable bimap_t bimap_;
286 std::deque<std::pair<state_name_t, state_t>> todo_;
291 template <Automaton... Auts>
292 using tuple_automaton
293 = std::shared_ptr<detail::tuple_automaton_impl<Auts...>>;
295 template <Automaton... Auts>
297 make_tuple_automaton(const Auts&... auts)
298 -> tuple_automaton<Auts...>
300 using res_t = tuple_automaton<Auts...>;
301 return make_shared_ptr<res_t>(auts...);
const origins_t & origins() const
A map from result state to tuple of original states.
map_t & pmap_()
A map from original state and status (spontaneous or proper state) to result state.
automata_t auts_
Input automata, supplied at construction time.
boost::flyweight< std::string, boost::flyweights::no_tracking, boost::flyweights::intermodule_holder > symbol
An internalized string.
typename bimap_t::right_map origins_t
base_t< tuple_element_t< I, automata_t >> input_automaton_t
The type of the Ith input automaton, unqualified.
weightset_t_of< context_t > weightset_t
state_t_of< automaton_t > state_t
std::ostream & print_set_(std::ostream &o, format fmt, seq< I... >) const
typename detail::labelset_t_of_impl< base_t< ValueSet >>::type labelset_t_of
Aggregate an automaton, and forward calls to it.
typename detail::context_t_of_impl< base_t< ValueSet >>::type context_t_of
state_name_t post_() const
The name of the post of the output automaton.
boost::bimap< boost::bimaps::unordered_set_of< state_name_t >, boost::bimaps::unordered_set_of< state_t >> bimap_t
std::ostream & print_set(std::ostream &o, format fmt={}) const
typename super_t::state_t state_t
Result state type.
std::ostream & print_state_name(const state_name_t &sn, std::ostream &o, format fmt={}, bool delimit=false) const
Print a state name from its state name.
labelset_t_of< context_t > labelset_t
An automaton whose states are tuples of states of automata.
state_name_t pre_() const
The name of the pre of the output automaton.
context_t_of< Aut > context_t
The type of context of the result.
std::tuple< state_t_of< Auts >... > state_name_t
State names: Tuple of states of input automata.
typename weightset_t::value_t weight_t
ATTRIBUTE_PURE bool has(const boost::container::flat_set< Key, Compare, Allocator > &s, const Key &e)
Whether e is member of s.
bool state_has_name(state_t s) const
static std::string sname_(const T &...t)
The sname of the sub automata.
std::ostream & print_state_name_(state_t s, std::ostream &o, format fmt, bool delimit, seq< I... > indices) const
An input/output format for valuesets.
tuple_automaton_impl(const automaton_t &aut, const Auts &...auts)
std::tuple< Auts... > automata_t
The type of input automata.
typename bimap_t::left_map map_t
std::ostream & print_set_(std::ostream &o, format fmt) const
The setname of the sub automata.
std::remove_cv_t< std::remove_reference_t< T >> base_t
T without reference or const/volatile qualifiers.
automaton tuple(const std::vector< automaton > &as)
Bridge.
Aut automaton_t
The type of the resulting automaton.
typename labelset_t::value_t label_t
typename detail::weightset_t_of_impl< base_t< ValueSet >>::type weightset_t_of
automaton_t aut_
The wrapped automaton, possibly const.
bimap_t bimap_
Bijective map state_name_t -> state_t.
static constexpr indices_t indices
std::ostream & print_state_name(state_t s, std::ostream &o, format fmt={}, bool delimit=false) const
Print a state name from its state index.