8 #include <boost/bimap.hpp>
9 #include <boost/bimap/unordered_set_of.hpp>
49 o <<
"tuple_automaton";
64 using label_t =
typename labelset_t::value_t;
65 using weight_t =
typename weightset_t::value_t;
93 format fmt = {},
bool delimit =
false)
109 using bimap_t = boost::bimap<boost::bimaps::unordered_set_of<state_name_t>, boost::bimaps::unordered_set_of<state_t>>;
110 using map_t =
typename bimap_t::left_map;
123 template <std::size_t... I>
131 template <
typename... T>
134 std::string res =
"<" ;
135 using swallow =
int[];
136 const char* sep =
"";
139 (res += sep + t, sep =
", ", 0)...
156 template <
size_t... I>
161 aut_->print_set(o, fmt);
163 const char* sep =
"";
164 using swallow =
int[];
176 state_name_t pre_() const
178 return pre_(indices);
181 template <size_t... I>
182 state_name_t pre_(seq<I...>) const
184 // clang 3.4 on top of libstdc++ wants this ctor to be
185 // explicitly called.
186 return state_name_t{(std::get<I>(auts_)->pre())...};
190 state_name_t post_() const
192 return post_(indices);
195 template <size_t... I>
196 state_name_t post_(seq<I...>) const
198 // clang 3.4 on top of libstdc++ wants this ctor to be
199 // explicitly called.
200 return state_name_t{(std::get<I>(auts_)->post())...};
209 template <bool Lazy = false>
210 state_t state(const state_name_t& state)
212 auto lb = pmap_().find(state);
213 if (lb == pmap_().end())
215 state_t s = aut_->new_state();
217 aut_->set_lazy(s, true);
218 lb = pmap_().insert(lb, {state, s});
219 todo_.emplace_back(state, s);
224 template <bool Lazy = false>
225 state_t state(state_t_of<Auts>... ss)
227 return state<Lazy>(std::make_tuple(ss...));
230 template <size_t... I>
232 print_state_name_(typename super_t::state_t s, std::ostream& o,
236 const auto& origs = origins();
237 auto i = origs.find(s);
238 if (i == std::end(origs))
239 this->print_state(s, o);
242 const char* sep = "";
243 using swallow = int[];
247 std::get<I>(auts_)->print_state_name(std::get<I>(i->second),
268 mutable bimap_t bimap_;
271 std::deque<std::pair<state_name_t, state_t>> todo_;
276 template <Automaton... Auts>
277 using tuple_automaton
278 = std::shared_ptr<detail::tuple_automaton_impl<Auts...>>;
280 template <Automaton... Auts>
282 make_tuple_automaton(const Auts&... auts)
283 -> tuple_automaton<Auts...>
285 using res_t = tuple_automaton<Auts...>;
286 return make_shared_ptr<res_t>(auts...);
ValueSet::value_t tuple(const ValueSet &vs, const typename ValueSets::value_t &...v)
automata_t auts_
Input automata, supplied at construction time.
bimap_t bimap_
Bijective map state_name_t -> state_t.
state_t_of< automaton_t > state_t
Result state type.
map_t & pmap_()
A map from original state and status (spontaneous or proper state) to result state.
labelset_t_of< context_t > labelset_t
std::ostream & print_set(std::ostream &o, format fmt={}) const
typename detail::weightset_t_of_impl< base_t< ValueSet >>::type weightset_t_of
state_t_of< automaton_t > state_t
const origins_t & origins() const
A map from result state to tuple of original states.
std::remove_cv_t< std::remove_reference_t< T >> base_t
T without reference or const/volatile qualifiers.
automaton_t aut_
The wrapped automaton, possibly const.
typename detail::labelset_t_of_impl< base_t< ValueSet >>::type labelset_t_of
An input/output format for valuesets.
bool state_has_name(typename super_t::state_t s) const
static std::string sname_(const T &...t)
The sname of the sub automata.
std::tuple< state_t_of< Auts >... > state_name_t
State names: Tuple of states of input automata.
static constexpr indices_t indices
std::tuple< Auts... > automata_t
The type of input automata.
base_t< tuple_element_t< I, automata_t >> input_automaton_t
The type of the Ith input automaton, unqualified.
context_t_of< Aut > context_t
The type of context of the result.
typename detail::state_t_of_impl< base_t< ValueSet >>::type state_t_of
Aut automaton_t
The type of the resulting automaton.
typename bimap_t::left_map map_t
std::ostream & print_state_name(typename super_t::state_t s, std::ostream &o, format fmt={}, bool delimit=false) const
boost::flyweight< std::string, boost::flyweights::no_tracking, boost::flyweights::intermodule_holder > symbol
An internalized string.
Aggregate an automaton, and forward calls to it.
tuple_automaton_impl(const automaton_t &aut, const Auts &...auts)
state_name_t pre_() const
The name of the pre of the output automaton.
std::ostream & print_set_(std::ostream &o, format fmt) const
The setname of the sub automata.
std::ostream & print_state_name_(typename super_t::state_t s, std::ostream &o, format fmt, seq< I... >) const
boost::bimap< boost::bimaps::unordered_set_of< state_name_t >, boost::bimaps::unordered_set_of< state_t >> bimap_t
An automaton whose states are tuples of states of automata.
typename detail::context_t_of_impl< base_t< ValueSet >>::type context_t_of
std::ostream & print_set_(std::ostream &o, format fmt, seq< I... >) const
typename bimap_t::right_map origins_t
weightset_t_of< context_t > weightset_t
ATTRIBUTE_PURE bool has(const boost::container::flat_set< Key, Compare, Allocator > &s, const Key &e)
Whether e is member of s.
typename weightset_t::value_t weight_t
typename labelset_t::value_t label_t
state_name_t post_() const
The name of the post of the output automaton.