Awali
Another Weighted Automata library
options.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_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 
98  options_t() {};
99 
105  : options_t( {pair})
106  {}
107 
108 
113  template<typename T>
115  : options_t((internal::option_value_pair_t) opt) {}
116 
123 
124 
132 
133 
139  template<typename T>
142 // auto value = map.find(option.id);
143 // if (value == map.end())
144 // value = map.emplace(option.id, option.get_default_value()).first;
145 // return ((typename internal::option_t<T>::value_t&) value->second);
146  auto value = map.find(option.id);
147  if (value == map.end())
148  return option.get_default_value();
149  return ((typename internal::option_t<T>::value_t) value->second);
150  }
151 
163 
164 
174  options_t operator+(options_t const& other) const;
175 
176  };
177 
178 
179 }} //end of namespaces awali::dyn, and awali
180 
181 
182 
183 #endif
Definition: option.hh:73
const size_t id
Definition: option.hh:76
value_t get_default_value()
Definition: option.hh:171
T value_t
Definition: option.hh:75
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:104
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:114
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:98
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