Limi
list_automaton.h
1 /*
2  * Copyright 2016, IST Austria
3  *
4  * This file is part of Limi.
5  *
6  * Limi is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Limi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with Limi. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef LIMI_LIST_AUTOMATON_H
21 #define LIMI_LIST_AUTOMATON_H
22 
23 #include <memory>
24 
25 #include "automaton.h"
26 #include "internal/helpers.h"
27 #include <vector>
28 #include <iostream>
29 #include <cassert>
30 
31 namespace Limi {
32 
33 
43 template <class Symbol>
44 class list_automaton : public Limi::automaton<unsigned,Symbol,list_automaton<Symbol>> {
45 protected:
46  typedef typename Limi::automaton<unsigned,Symbol,list_automaton<Symbol>>::State_vector State_vector;
47  typedef typename Limi::automaton<unsigned,Symbol,list_automaton<Symbol>>::Symbol_vector Symbol_vector;
48 
49 protected:
50  std::vector<Symbol> symbol_list;
51  const printer_base<Symbol>& symbol_printer_;
52  printer<unsigned> state_printer_;
53 public:
64  template <class InputIterator>
65  list_automaton(InputIterator first, InputIterator last, const printer_base<Symbol>& symbol_printer = printer<Symbol>()) : Limi::automaton<unsigned,Symbol,list_automaton<Symbol>>(false, false), symbol_printer_(symbol_printer) {
66  symbol_list.insert(symbol_list.begin(), first, last);
67  }
68 
69  bool int_is_final_state(const unsigned& state) const { return state >= symbol_list.size(); }
70 
71  void int_initial_states(State_vector& states) const { states.push_back(0); }
72 
73  void int_successors(const unsigned& state, const Symbol& sigma, State_vector& successors) const
74  {
75  if (state < symbol_list.size() && std::equal_to<Symbol>()(symbol_list[state], sigma))
76  successors.push_back(state+1);
77  }
78 
79  void int_next_symbols(const unsigned& state, Symbol_vector& symbols) const {
80  if (state < symbol_list.size())
81  symbols.push_back(symbol_list[state]);
82  }
83 
84  inline const printer_base<Symbol>& symbol_printer() const { return symbol_printer_; }
85 
86  inline bool int_is_epsilon(const Symbol& symbol) const { return false; }
87 
88 };
89 }
90 
91 #endif
The main namespace of the library.
Definition: antichain_algo.h:40
This automaton represents accepts exactly one word.
Definition: list_automaton.h:44
list_automaton(InputIterator first, InputIterator last, const printer_base< Symbol > &symbol_printer=printer< Symbol >())
Constructs an automaton that accepts a specified word.
Definition: list_automaton.h:65
void successors(const unsigned &state, const Symbol &sigma, State_vector &successors1) const
Returns the successor for a specific state.
Definition: automaton.h:201
Automata need to inherit from this class and implement certain methods.
Definition: automaton.h:49