Awali
Another Weighted Automata library
value.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_VALUE_HH
18 #define AWAlI_DYN_OPTIONS_VALUE_HH
19 
20 
21 namespace awali { namespace dyn { namespace internal {
22 
24  {
26  virtual opt_untyped_value* clone() const = 0;
27  virtual ~opt_untyped_value() {}
28  };
29 
30  template <typename T>
32  {
33  T value;
34 
35  opt_typed_value(const T& val) : value(val) {}
36 
37  opt_typed_value* clone() const override
38  {
39  return new opt_typed_value(value);
40  }
41  };
42 
43 
44  struct opt_any_t
45  {
46  private:
47  opt_untyped_value* value;
48 
49  public:
50  template <typename T>
51  opt_any_t(const T& val) : value(new opt_typed_value<T>(val))
52  {}
53 
54  opt_any_t(char const* s) : value(new opt_typed_value<std::string>(s)) {}
55 
56  opt_any_t(opt_any_t const& a) : value(a.value->clone()) {}
57 
59  {
60  if (&t != this) {
61  delete value;
62  value = t.value->clone();
63  }
64  return (*this);
65  }
66 
67  ~opt_any_t() { delete (value); }
68 
69 
70  template <typename T>
71  explicit operator T() const
72  {
73  const opt_typed_value<T>& test
74  = dynamic_cast<const opt_typed_value<T>&>(*(this->value));
75  return test.value;
76  }
77  };
78 
80  {
81  size_t id;
84  option_value_pair_t(std::string const&, std::string const&);
85  };
86 
87 }}} // namespace awali::dyn::internal
88 #endif
Main namespace of Awali.
Definition: ato.hh:22
Definition: value.hh:45
opt_any_t(char const *s)
Definition: value.hh:54
~opt_any_t()
Definition: value.hh:67
opt_any_t(opt_any_t const &a)
Definition: value.hh:56
opt_any_t & operator=(opt_any_t const &t)
Definition: value.hh:58
opt_any_t(const T &val)
Definition: value.hh:51
opt_typed_value(const T &val)
Definition: value.hh:35
T value
Definition: value.hh:33
opt_typed_value * clone() const override
Definition: value.hh:37
virtual ~opt_untyped_value()
Definition: value.hh:27
virtual opt_untyped_value * clone() const =0
opt_untyped_value()
Definition: value.hh:25
option_value_pair_t(std::string const &, std::string const &)
internal::opt_any_t value
Definition: value.hh:82
size_t id
Definition: value.hh:81
option_value_pair_t(size_t i, internal::opt_any_t v)
Definition: value.hh:83