Vcsn  2.0
Be Rational
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
partition-automaton.hh
Go to the documentation of this file.
1 #ifndef VCSN_CORE_PARTITION_AUTOMATON_HH
2 # define VCSN_CORE_PARTITION_AUTOMATON_HH
3 
4 # include <map>
5 # include <set>
6 # include <vector>
7 
9 
10 namespace vcsn
11 {
12  namespace detail
13  {
14 
19  template <typename Aut>
21  : public automaton_decorator<typename Aut::element_type::automaton_nocv_t>
22  {
23  public:
24  using automaton_t = Aut;
25  using automaton_nocv_t = typename automaton_t::element_type::automaton_nocv_t;
29 
32 
34  using state_name_t = std::set<state_t>;
35 
36  private:
38  using origins_t = std::map<state_t, state_name_t>;
40 
43 
44  public:
46  : super_t(input->context())
47  , input_(input)
48  {}
49 
51  static std::string sname()
52  {
53  return "partition_automaton<" + automaton_t::element_type::sname() + ">";
54  }
55 
57  std::string vname(bool full = true) const
58  {
59  return "partition_automaton<" + input_->vname(full) + ">";
60  }
61 
62  bool state_has_name(state_t s) const
63  {
64  return s != super_t::pre() && s != super_t::post();
65  }
66 
67  std::ostream&
68  print_state_name(state_t s, std::ostream& o,
69  const std::string& fmt = "text",
70  bool delimit = false) const
71  {
72  const auto& set = origins_.at(s);
73  const char* separator = "";
74  if (delimit)
75  o << '{';
76  for (auto s : set)
77  {
78  o << separator;
79  input_->print_state_name(s, o, fmt, true);
80  separator = ", ";
81  }
82  if (delimit)
83  o << '}';
84  return o;
85  }
86 
87  using super_t::new_state;
88 
91  state_t
92  new_state(const state_name_t& set)
93  {
94  state_t res = new_state();
95  origins_[res] = set;
96  return res;
97  }
98 
99  state_t
100  new_state(const std::vector<state_t>& v)
101  {
102  state_name_t set;
103  for (auto s: v)
104  set.emplace(s);
105  return new_state(std::move(set));
106  }
107  }; // class
108  } // namespace detail
109 
111  template <typename Aut>
112  using partition_automaton
113  = std::shared_ptr<detail::partition_automaton_impl<Aut>>;
114 
115 } // namespace vcsn
116 
117 #endif // !VCSN_CORE_PARTITION_AUTOMATON_HH
std::set< state_t > state_name_t
The state names: a set of the original automaton states.
partition_automaton_impl(const automaton_t &input)
std::ostream & print_state_name(state_t s, std::ostream &o, const std::string &fmt="text", bool delimit=false) const
std::map< state_t, state_name_t > origins_t
A map from each state to the origin state set it stands for.
static std::string sname()
Static name.
std::string sname()
Definition: name.hh:31
state_t_of< automaton_t > state_t
The underlying state type.
auto new_state(Args &&...args) -> decltype(aut_-> new_state(std::forward< Args >(args)...))
typename detail::context_t_of_impl< base_t< ValueSet >>::type context_t_of
Definition: traits.hh:32
Aggregate an automaton, and forward calls to it.
std::string vname(bool full=true) const
Dynamic name.
typename detail::label_t_of_impl< base_t< ValueSet >>::type label_t_of
Definition: traits.hh:33
state_t new_state(const state_name_t &set)
Make a new state representing the given input state set, which is required to be new – no error-chec...
state_t new_state(const std::vector< state_t > &v)
static constexpr auto pre(Args &&...args) -> decltype(automaton_t::element_type::pre(std::forward< Args >(args)...))
typename detail::state_t_of_impl< base_t< ValueSet >>::type state_t_of
Definition: traits.hh:35
std::shared_ptr< detail::partition_automaton_impl< Aut >> partition_automaton
A partition automaton as a shared pointer.
typename automaton_t::element_type::automaton_nocv_t automaton_nocv_t
An automaton wrapper whose states form a partition of the state set of another automaton.
static constexpr auto post(Args &&...args) -> decltype(automaton_t::element_type::post(std::forward< Args >(args)...))
const automaton_t input_
The input automaton.