Awali
Another Weighted Automata library
enum_utils.hh
Go to the documentation of this file.
1 // This file is part of Awali.
2 // Copyright 2016-2023 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_COMMON_ENUMS_UTILS_HH
18 #define AWALI_COMMON_ENUMS_UTILS_HH
19 
20 
21 #include <awali/common/enums.hh>
22 
23 #include <vector>
24 #include <string>
25 
26 namespace awali {
27 
34  direction_t make_direction(std::string const& name);
35 
36 
38  std::string name_of(direction_t val);
39 
40 
47  layout_t make_layout(std::string const& name);
48 
49 
51  std::string name_of(layout_t val);
52 
53 
62  quotient_algo_t make_quotient_algo(std::string const& name);
63 
64 
68  std::string name_of(quotient_algo_t val);
69 
70 
79  exp_to_aut_algo_t make_exp_to_aut_algo(std::string const& name);
80 
81 
85  std::string name_of(exp_to_aut_algo_t val);
86 
87 
96  io_format_t make_io_format(std::string const& name);
97 
98 
100  std::string name_of(io_format_t val);
101 
102 
105 
106 
115  state_elim_order_t make_state_elim_order_t(std::string const& name);
116 
117 
121  std::string name_of(state_elim_order_t val);
122 
123  namespace internal {
124 
125  using enum_join_t=long;
126 
127  enum_join_t enum_of_string (const std::string& enum_name,
128  const std::string& value);
129 
130  std::vector<enum_join_t> enum_values (std::string const& enum_name);
131 
132 
133  unsigned short index_of_enum(std::string enum_name);
134 
135 #define GENERATE_MAKE_ENUM(id,enum_t) \
136  template<typename T=enum_t> \
137  auto make_enum(std::string const& str) \
138  -> typename std::enable_if<std::is_same<T,enum_t>::value,T>::type \
139  { return (enum_t) enum_of_string(#enum_t,str); } \
140  \
141  template<typename T=enum_t> \
142  auto values_of() \
143  -> typename std::enable_if<std::is_same<T,enum_t>::value, \
144  std::vector<T> const&>::type \
145  { static std::vector<enum_t> values; \
146  if (values.empty()) \
147  for (auto v : enum_values(#enum_t)) \
148  values.push_back((enum_t) v); \
149  return values; } \
150  \
151  template<typename T=enum_t> \
152  constexpr auto index_of() \
153  -> typename std::enable_if<std::is_same<T,enum_t>::value, \
154  short unsigned>::type \
155  {return id;}
156 
157 
158 
167 
168 
169 #undef GENERATE_MAKE_ENUM
170 
171 
172 
173  }//end of namespace awali::internal
174 } // end of namespace awali
175 
176 #endif
#define GENERATE_MAKE_ENUM(id, enum_t)
Definition: enum_utils.hh:135
direction_t
Used in some algorithms in which one may considers transitions forward or backwards.
Definition: enums.hh:35
state_elim_order_t
The different strategies for choosing which state to eliminate first when transforming an automaton i...
Definition: enums.hh:107
layout_t
The different layout that we may pass to program dot to compute geometry of automata.
Definition: enums.hh:44
quotient_algo_t
The different algorithms for computing the minimal quotient.
Definition: enums.hh:64
star_status_t
The different behaviours a weightset may have with respect to the star.
Definition: enums.hh:163
minim_algo_t
The different algorithms for computing the minimal automaton.
Definition: enums.hh:55
io_format_t
The different format for input/output of automata and expressions.
Definition: enums.hh:123
exp_to_aut_algo_t
The different algorithms for transforming an expression into an automaton.
Definition: enums.hh:70
unsigned short index_of_enum(std::string enum_name)
std::vector< enum_join_t > enum_values(std::string const &enum_name)
long enum_join_t
Definition: enum_utils.hh:125
enum_join_t enum_of_string(const std::string &enum_name, const std::string &value)
static constexpr TOP< void > value
Definition: priority.hh:93
Main namespace of Awali.
Definition: ato.hh:22
exp_to_aut_algo_t make_exp_to_aut_algo(std::string const &name)
Builds a exp_to_aut_algo_t from a string describing its name.
layout_t make_layout(std::string const &name)
Builds a layout_t from a string describing its name.
direction_t make_direction(std::string const &name)
Builds a direction_t from a string describing its name.
quotient_algo_t make_quotient_algo(std::string const &name)
Builds a quotient_algo_t from a string describing its name.
io_format_t make_io_format(std::string const &name)
Builds a io_format_t from a string describing its name.
std::string name_of(direction_t val)
Return the canonical string reprensation of given direction_t.
std::string default_extension_of(io_format_t val)
Return the default extension of a file written in given format.
state_elim_order_t make_state_elim_order_t(std::string const &name)
Builds a state_elim_order_t from a string describing its name.