Awali
Another Weighted Automata library
string_history.hh
Go to the documentation of this file.
1 // This file is part of Awali.
2 // Copyright 2016-2022 Sylvain Lombardy, Victor Marsault, Jacques Sakarovitch
3 //
4 // Awali is a free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 #ifndef AWALI_STRING_HISTORY_HH
18 #define AWALI_STRING_HISTORY_HH
19 
20 # include <string>
21 # include <map>
23 
24 namespace awali {
25  namespace sttc {
26 
27  //Make every state in relation with a string
28  class string_history final : public history_base
29  {
30  private:
31  using origins_t = std::map<state_t, std::string>;
32  origins_t origins_;
33  std::string name_;
34  std::string desc_;
35  public:
37  {}
38 
39  history_kind_t get_nature() const override
40  {
42  }
43 
44  std::ostream&
45  print_state_name(state_t s, std::ostream& o,
46  const std::string&/*fmt*/) const override
47  {
48  auto i = origins().find(s);
49  o << i->second;
50  return o;
51  }
52 
53  const std::string& get_state_name(state_t s) const
54  {
55  auto i = origins().find(s);
56  return i->second;
57  }
58 
59  void set_name(const std::string& n) {
60  name_ = n;
61  }
62 
63  void set_desc(const std::string& d) {
64  desc_ = d;
65  }
66 
67  const std::string& get_name() const {
68  return name_;
69  }
70 
71  const std::string& get_desc() const {
72  return desc_;
73  }
74 
75  const origins_t& origins() const
76  {
77  return origins_;
78  }
79 
80  bool remove_history(state_t s) override {
81  return origins_.erase(s);
82  };
83 
84  bool has_history(state_t s) const override {
85  return (origins_.find(s)!=origins_.end());
86  }
87 
88  void
89  add_state(state_t s,const std::string& str)
90  {
91  origins_[s] = str;
92  }
93 
95  throw std::runtime_error("Origin state not available");
96  }
97 
98  std::vector<state_t> get_state_set(state_t) override {
99  throw std::runtime_error("Origin state set not available");
100  }
101  };
102 
103  }
104 }//end of ns awali::stc
105 
106 #endif // !AWALI_STRING_HISTORY_HH
base type for history of automata
Definition: history.hh:40
The semiring of Natural numbers.
Definition: n.hh:34
Definition: string_history.hh:29
bool remove_history(state_t s) override
Definition: string_history.hh:80
bool has_history(state_t s) const override
Definition: string_history.hh:84
const origins_t & origins() const
Definition: string_history.hh:75
std::vector< state_t > get_state_set(state_t) override
Definition: string_history.hh:98
history_kind_t get_nature() const override
Definition: string_history.hh:39
const std::string & get_name() const
Definition: string_history.hh:67
const std::string & get_desc() const
Definition: string_history.hh:71
void set_name(const std::string &n)
Definition: string_history.hh:59
state_t get_state(state_t) override
Definition: string_history.hh:94
const std::string & get_state_name(state_t s) const
Definition: string_history.hh:53
std::ostream & print_state_name(state_t s, std::ostream &o, const std::string &) const override
Definition: string_history.hh:45
void set_desc(const std::string &d)
Definition: string_history.hh:63
void add_state(state_t s, const std::string &str)
Definition: string_history.hh:89
string_history()
Definition: string_history.hh:36
history_kind_t
The different kinds of history.
Definition: enums.hh:178
@ STRING
The state history is expressed directy as a string.
Main namespace of Awali.
Definition: ato.hh:22
unsigned state_t
Definition: types.hh:21