The MAUVE Toolchain
Property.hpp
1 /*
2  * Copyright 2017 ONERA
3  *
4  * This file is part of the MAUVE Runtime project.
5  *
6  * MAUVE Runtime is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License version 3 as
8  * published by the Free Software Foundation.
9  *
10  * MAUVE Runtime is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with MAUVE. If not, see <https://www.gnu.org/licenses/lgpl-3.0>.
17  */
18 #ifndef MAUVE_RUNTIME_PROPERTY_HPP
19 #define MAUVE_RUNTIME_PROPERTY_HPP
20 
21 #include <string>
22 
23 namespace mauve {
24  namespace runtime {
25 
26  class HasProperty;
27 
29  enum property_type { INTEGRAL, FLOATING_POINT, STRING, OTHER };
30 
33  public:
38  AbstractProperty(HasProperty* container, std::string const & name);
39  virtual ~AbstractProperty() noexcept;
40 
42  virtual property_type get_type() const = 0;
43 
45  const std::string name;
47  virtual std::string type_name() const = 0;
48 
49  protected:
50  const HasProperty* container;
51  };
52 
53  // ------------------------- Integral -------------------------
54 
57  public:
62  AbstractIntegralProperty(HasProperty* container, std::string const & name);
64  virtual ~AbstractIntegralProperty() noexcept;
65 
67  property_type get_type() const override;
68 
70  virtual long get() const = 0;
72  virtual bool set(long value) = 0;
73  };
74 
75  template <typename T>
76  class IntegralProperty final : public AbstractIntegralProperty {
77  public:
78  IntegralProperty(HasProperty* container, std::string const & name, T init_value);
79  IntegralProperty(IntegralProperty const & other) = delete;
80  ~IntegralProperty() noexcept;
81 
82  std::string type_name() const override;
83 
84  T get_value() const;
85  bool set_value(T value);
86 
87  long get() const override;
88  bool set(long value) override;
89 
90  operator T&();
91  operator T() const;
92  IntegralProperty<T> & operator=(T value);
93  IntegralProperty<T> & operator=(IntegralProperty<T> const & other);
94 
95  private:
96  T value;
97  };
98 
99  // ------------------------- Floating Point -------------------------
100 
103  public:
108  AbstractFloatingPointProperty(HasProperty* container, std::string const & name);
110  virtual ~AbstractFloatingPointProperty() noexcept;
111 
113  property_type get_type() const override;
114 
116  virtual double get() const = 0;
118  virtual bool set(double value) = 0;
119  };
120 
121  template <typename T>
123  public:
124  FloatingPointProperty(HasProperty* container, std::string const & name, T init_value);
125  FloatingPointProperty(FloatingPointProperty const & other) = delete;
126  ~FloatingPointProperty() noexcept;
127 
128  std::string type_name() const override;
129 
130  T get_value() const;
131  bool set_value(T value);
132 
133  double get() const override;
134  bool set(double value) override;
135 
136  operator T&();
137  operator T() const;
138  FloatingPointProperty<T> & operator=(T value);
139  FloatingPointProperty<T> & operator=(FloatingPointProperty<T> const & other);
140 
141  private:
142  T value;
143  };
144 
145  // ------------------------- String -------------------------
146 
147  class StringProperty final : public AbstractProperty {
148  public:
149  StringProperty(HasProperty* container, std::string const & name, std::string init_value);
150  StringProperty(StringProperty const & other) = delete;
151  ~StringProperty() noexcept;
152 
153  property_type get_type() const override;
154 
155  std::string type_name() const override;
156 
157  std::string get_value() const;
158  bool set_value(std::string const & value);
159 
160  operator std::string&();
161  operator std::string() const;
162  StringProperty & operator=(std::string const & value);
163  StringProperty & operator=(StringProperty const & other);
164 
165  private:
166  std::string value;
167  };
168 
169  // ------------------------- Other -------------------------
170 
171  template <typename T>
172  class OtherProperty final : public AbstractProperty {
173  public:
174  OtherProperty(HasProperty* container, std::string const & name, T init_value);
175  OtherProperty(OtherProperty const & other) = delete;
176  ~OtherProperty() noexcept;
177 
178  property_type get_type() const override;
179 
180  std::string type_name() const override;
181 
182  T get_value() const;
183  bool set_value(T value);
184 
185  operator T&();
186  operator T() const;
187  OtherProperty<T> & operator=(T value);
188  OtherProperty<T> & operator=(OtherProperty<T> const & other);
189 
190  private:
191  T value;
192  };
193 
194  }
195 }
196 
197 #include "ipp/IntegralProperty.ipp"
198 #include "ipp/FloatingPointProperty.ipp"
199 #include "ipp/OtherProperty.ipp"
200 
201 
202 #endif
Definition: HasProperty.hpp:34
AbstractProperty(HasProperty *container, std::string const &name)
Constructor.
const std::string name
Property name.
Definition: Property.hpp:45
Abstract class for a Floating point property.
Definition: Property.hpp:102
virtual std::string type_name() const =0
Get the property type name.
Abstract class for a Integral property.
Definition: Property.hpp:56
Definition: HasProperty.hpp:32
Definition: HasProperty.hpp:53
Definition: HasProperty.hpp:33
The MAUVE namespace.
Definition: tracing.hpp:24
virtual property_type get_type() const =0
Get the property type.
property_type
Property types.
Definition: Property.hpp:29
Abstract property class.
Definition: Property.hpp:32
Definition: Property.hpp:147