Awali
Another Weighted Automata library
options.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_DYN_OPTIONS_OPTIONS_HH
18 #define AWALI_DYN_OPTIONS_OPTIONS_HH
19 
20 #include <string>
21 #include <typeinfo>
22 #include <unordered_map>
23 
26 #include <awali/common/enums.hh>
27 #include <awali/common/priority.hh>
29 
30 namespace awali { namespace dyn {
31 
32 
87  class options_t
88  {
89  std::unordered_map<size_t, internal::opt_any_t> map;
90 
91  public:
97  options_t(std::initializer_list<internal::option_value_pair_t> list);
98 
99  options_t(){};
100 
106 
107 
112  template <typename T>
114  : options_t((internal::option_value_pair_t) opt)
115  {}
116 
123 
124 
132 
133 
139  template <typename T>
142  {
143  // auto value = map.find(option.id);
144  // if (value == map.end())
145  // value = map.emplace(option.id,
146  // option.get_default_value()).first;
147  // return ((typename internal::option_t<T>::value_t&)
148  // value->second);
149  auto value = map.find(option.id);
150  if (value == map.end())
151  return option.get_default_value();
152  return ((typename internal::option_t<T>::value_t) value->second);
153  }
154 
166 
167 
177  options_t operator+(options_t const& other) const;
178  };
179 
180 
181 }} // namespace awali::dyn
182 
183 
184 #endif
Definition: option.hh:74
const size_t id
Definition: option.hh:77
value_t get_default_value()
Definition: option.hh:197
T value_t
Definition: option.hh:76
An options_t is a set of optional parameters that is passed on to called functions.
Definition: options.hh:88
options_t operator+(options_t const &other) const
Creates a new options_t that is the union of this options_t with another options_t.
options_t(std::initializer_list< internal::option_value_pair_t > list)
Creates an options_t from a list of option/value pairs.
options_t(internal::option_value_pair_t pair)
Creates an options_t from one option/value pair.
Definition: options.hh:105
internal::option_t< T >::value_t operator[](internal::option_t< T > option)
Gets the value associated by to given option by this options_t.
Definition: options.hh:141
options_t operator+(internal::option_value_pair_t const &pair) const
Creates a new options_t that is the union of this options_t with another option/value pair.
options_t & operator+=(options_t const &other)
Adds all option/value mapping in other to this options_t, possibly overriding previous values.
options_t(internal::option_t< T > opt)
Creates an options_t from an internal::option_t by mapping it to its default value.
Definition: options.hh:113
options_t & operator+=(internal::option_value_pair_t const &other)
Adds an option/value pair to this options_t, possibly overriding a previous value.
options_t()
Definition: options.hh:99
static constexpr TOP< void > value
Definition: priority.hh:93
pair_automaton< Aut > pair(const Aut &aut, bool keep_initials=false)
Definition: synchronizing_word.hh:266
Main namespace of Awali.
Definition: ato.hh:22