Awali
Another Weighted Automata library
options.hh
Go to the documentation of this file.
1 // This file is part of Awali.
2 // Copyright 2016-2021 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 <unordered_map>
21 #include <typeinfo>
22 
23 #include <awali/common/priority.hh>
24 #include <awali/common/enums.hh>
28 
29 namespace awali {
30  namespace dyn {
31 
32 
86  class options_t {
87  std::unordered_map<size_t, internal::opt_any_t> map;
88 
89  public:
90 
96  options_t(std::initializer_list<internal::option_value_pair_t> list);
97 
103  : options_t( {pair})
104  {}
105 
106 
111  template<typename T>
113  : options_t((internal::option_value_pair_t) opt) {}
114 
121 
122 
130 
131 
137  template<typename T>
140  auto value = map.find(option.id);
141  if (value == map.end())
142  return option.get_default_value();
143  return ((typename internal::option_t<T>::value_t) value->second);
144  }
145 
157 
158 
168  options_t operator+(options_t const& other) const;
169 
170  };
171 
172 
173 }} //end of namespaces awali::dyn, and awali
174 
175 
176 
177 #endif
Definition: option.hh:70
const size_t id
Definition: option.hh:73
value_t get_default_value()
Definition: option.hh:168
T value_t
Definition: option.hh:72
An options_t is a set of optional parameters that is passed on to called functions.
Definition: options.hh:86
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:102
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:139
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:112
options_t & operator+=(internal::option_value_pair_t const &other)
Adds an option/value pair to this options_t, possibly overriding a previous value.
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