Vcsn  2.8
Be Rational
lazy-tuple-automaton.hh
Go to the documentation of this file.
1 #pragma once
2 
3 #include <vcsn/core/automaton.hh>
7 
8 namespace vcsn
9 {
10  namespace detail
11  {
30  template <typename Decorated,
31  bool KeepTransitions,
32  bool Lazy,
33  Automaton Aut, Automaton... Auts>
35  : public automaton_decorator<tuple_automaton<Aut, Auts...>>
36  {
37  public:
38 
40  using tuple_automaton_t = tuple_automaton<Aut, Auts...>;
41  using tuple_automaton_impl = typename tuple_automaton_t::element_type;
44 
45 
46  template <size_t... I>
47  using seq = typename tuple_automaton_impl::template seq<I...>;
48 
51 
53  using decorated_t = Decorated;
54 
56 
57  using super_t::aut_;
58 
59  // Clang 3.5 is wrong about ws_ being used before being defined.
60 #if defined __clang__
61 # pragma clang diagnostic push
62 # pragma clang diagnostic ignored "-Wuninitialized"
63 #endif
64  lazy_tuple_automaton(Aut aut, const Auts&... auts)
65  : super_t{make_tuple_automaton(aut, auts...)}
67  {
68  if (Lazy)
69  this->set_lazy(this->pre());
70  }
71 #if defined __clang__
72 # pragma clang diagnostic pop
73 #endif
74  template <typename... T>
75  static symbol sname_(const T&... t)
76  {
77  static auto res = symbol{tuple_automaton_impl::sname_(t...)};
78  return res;
79  }
80 
81 
83  auto origins() const
84  -> decltype(aut_->origins())
85  {
86  return aut_->origins();
87  }
88 
90  void complete_(state_t s) const
91  {
92  const auto& orig = origins();
93  state_name_t sn = orig.at(s);
94  auto& self = static_cast<decorated_t&>(const_cast<self_t&>(*this));
95  if (Lazy)
96  self.set_lazy(s, false);
97  self.add_transitions(s, sn);
98  }
99 
101  auto all_out(state_t s) const
102  -> decltype(all_out(aut_, s))
103  {
104  if (this->is_lazy(s))
105  complete_(s);
106  return vcsn::detail::all_out(aut_, s);
107  }
108 
109  protected:
110 
113  template <Automaton A>
115  false, true,
116  KeepTransitions>;
117 
119  template <typename... Args>
120  state_t state(Args&&... args)
121  {
122  return aut_->template state<Lazy>(std::forward<Args>(args)...);
123  }
124 
126  std::tuple<typename transition_map_t<Auts>::map_t&...>
127  out_(const state_name_t& ss)
128  {
129  return out_(ss, aut_->indices);
130  }
131 
132  template <size_t... I>
133  std::tuple<typename transition_map_t<Auts>::map_t&...>
135  {
136  return std::tie(std::get<I>(transition_maps_)[std::get<I>(ss)]...);
137  }
138 
139 
141  const weightset_t& ws_ = *aut_->weightset();
142 
144  std::tuple<transition_map_t<Auts>...> transition_maps_;
145  };
146  }
147 }
auto make_tuple_automaton(const Auts &... auts) -> tuple_automaton< Auts... >
typename detail::weightset_t_of_impl< base_t< ValueSet > >::type weightset_t_of
Definition: traits.hh:67
Decorator implementing the laziness for an algorithm.
Build the (accessible part of the) product.
Definition: conjunction.hh:36
std::tuple< state_t_of< Auts >... > state_name_t
State names: Tuple of states of input automata.
lazy_tuple_automaton(Aut aut, const Auts &... auts)
state_t state(Args &&... args)
Conversion from state name to state number.
boost::flyweight< std::string, boost::flyweights::no_tracking, boost::flyweights::intermodule_holder > symbol
An internalized string.
Definition: symbol.hh:21
automaton_t aut_
The wrapped automaton, possibly const.
tuple_automaton< Aut, Auts... > tuple_automaton_t
The underlying automaton, output and inputs.
void complete_(state_t s) const
Complete a state: find its outgoing transitions.
static symbol sname_(const T &... t)
auto all_out(const Aut &aut, state_t_of< Aut > s)
Indexes of transitions leaving state s.
Definition: automaton.hh:67
static constexpr auto pre(Args &&... args) -> decltype(element_type::pre(std::forward< Args >(args)...))
auto origins() const -> decltype(aut_->origins())
A map from result state to tuple of original states.
Cache the outgoing transitions of an automaton as efficient maps label -> vector<(weight, dst)>.
Definition: a-star.hh:8
std::shared_ptr< detail::tuple_automaton_impl< Auts... > > tuple_automaton
A tuple automaton as a shared pointer.
auto set_lazy(Args &&... args) -> decltype(aut_-> set_lazy(std::forward< Args >(args)...))
Aggregate an automaton, and forward calls to it.
std::tuple< typename transition_map_t< Auts >::map_t &... > out_(const state_name_t &ss)
The outgoing tuple of transitions from state tuple ss.
typename super_t::state_t state_t
Result state type.
std::tuple< transition_map_t< Auts >... > transition_maps_
Transition caches.
#define Automaton
Definition: automaton.hh:23
auto all_out(state_t s) const -> decltype(all_out(aut_, s))
All the outgoing transitions.
std::tuple< typename transition_map_t< Auts >::map_t &... > out_(const state_name_t &ss, seq< I... >)
const weightset_t & ws_
The resulting weightset.
static std::string sname_(const T &... t)
The sname of the sub automata.
return res
Definition: multiply.hh:399
auto is_lazy(Args &&... args) const -> decltype(aut_-> is_lazy(std::forward< Args >(args)...))