blockfactory  0.8
A framework for wrapping algorithms for dataflow programming
Parameters.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2018 Istituto Italiano di Tecnologia (IIT)
3  * All rights reserved.
4  *
5  * This software may be modified and distributed under the terms of the
6  * GNU Lesser General Public License v2.1 or any later version.
7  */
8 
9 #ifndef BLOCKFACTORY_CORE_PARAMETERS_H
10 #define BLOCKFACTORY_CORE_PARAMETERS_H
11 
12 #include <memory>
13 #include <string>
14 #include <vector>
15 
16 namespace blockfactory {
17  namespace core {
18  template <typename T>
19  class Parameter;
20  class ParameterMetadata;
21  class Parameters;
22  const int PARAM_INVALID_INDEX = -1;
23  const std::string PARAM_INVALID_NAME = {};
24  } // namespace core
25 } // namespace blockfactory
26 
35 {
36 public:
37  using ParamIndex = int;
38  using ParamName = std::string;
39 
40 private:
41 #ifndef DOXYGEN_SHOULD_SKIP_THIS
42  class impl;
43  std::unique_ptr<impl> pImpl;
44 #endif
45 
46 public:
47  Parameters();
49  Parameters& operator=(const Parameters& other);
50 
51  ~Parameters();
52 
58  ParamName getParamName(const ParamIndex& index) const;
59 
65  ParamIndex getParamIndex(const ParamName& name) const;
66 
72  unsigned getNumberOfParameters() const;
73 
80  bool existName(const ParamName& name) const;
81 
91  template <typename T>
92  bool storeParameter(const T& param, const blockfactory::core::ParameterMetadata& paramMetadata);
93 
103  template <typename T>
104  bool storeParameter(const std::vector<T>& param,
105  const blockfactory::core::ParameterMetadata& paramMetadata);
106 
116  template <typename T>
117  bool storeParameter(const Parameter<T>& parameter);
118 
128  template <typename T>
129  bool getParameter(const ParamName& name, T& param) const;
130 
140  template <typename T>
141  bool getParameter(const ParamName& name, std::vector<T>& param) const;
142 
148  std::vector<Parameter<int>> getIntParameters() const;
149 
155  std::vector<Parameter<bool>> getBoolParameters() const;
156 
162  std::vector<Parameter<double>> getDoubleParameters() const;
163 
169  std::vector<Parameter<std::string>> getStringParameters() const;
170 
180 };
181 
182 // ============
183 // GETPARAMETER
184 // ============
185 
186 // SCALAR
187 namespace blockfactory {
188  namespace core {
189  // Explicit declaration for numeric types
190  extern template bool Parameters::getParameter<int>(const Parameters::ParamName& name,
191  int& param) const;
192  extern template bool Parameters::getParameter<bool>(const Parameters::ParamName& name,
193  bool& param) const;
194  extern template bool Parameters::getParameter<double>(const Parameters::ParamName& name,
195  double& param) const;
196  // Explicit specialization for std::string
197  template <>
198  bool Parameters::getParameter<std::string>(const Parameters::ParamName& name,
199  std::string& param) const;
200  } // namespace core
201 } // namespace blockfactory
202 
203 // VECTOR
204 namespace blockfactory {
205  namespace core {
206  // Explicit declaration for numeric types
207  extern template bool Parameters::getParameter<int>(const Parameters::ParamName& name,
208  std::vector<int>& param) const;
209  extern template bool Parameters::getParameter<bool>(const Parameters::ParamName& name,
210  std::vector<bool>& param) const;
211  extern template bool Parameters::getParameter<double>(const Parameters::ParamName& name,
212  std::vector<double>& param) const;
213  extern template bool
214  Parameters::getParameter<std::string>(const Parameters::ParamName& name,
215  std::vector<std::string>& param) const;
216  } // namespace core
217 } // namespace blockfactory
218 
219 // ==============
220 // STOREPARAMETER
221 // ==============
222 
223 // SCALAR
224 namespace blockfactory {
225  namespace core {
226  // Explicit declaration for numeric types
227  extern template bool
228  Parameters::storeParameter<int>(const int& param, const ParameterMetadata& paramMetadata);
229  extern template bool
230  Parameters::storeParameter<bool>(const bool& param, const ParameterMetadata& paramMetadata);
231  extern template bool
232  Parameters::storeParameter<double>(const double& param,
233  const ParameterMetadata& paramMetadata);
234  // Explicit specialization for std::string
235  template <>
236  bool Parameters::storeParameter<std::string>(const std::string& param,
237  const ParameterMetadata& paramMetadata);
238  } // namespace core
239 } // namespace blockfactory
240 
241 // VECTOR
242 namespace blockfactory {
243  namespace core {
244  // Explicit declaration for numeric types
245  extern template bool
246  Parameters::storeParameter<int>(const std::vector<int>& param,
247  const ParameterMetadata& paramMetadata);
248  extern template bool
249  Parameters::storeParameter<bool>(const std::vector<bool>& param,
250  const ParameterMetadata& paramMetadata);
251  extern template bool
252  Parameters::storeParameter<double>(const std::vector<double>& param,
253  const ParameterMetadata& paramMetadata);
254  extern template bool
255  Parameters::storeParameter<std::string>(const std::vector<std::string>& param,
256  const ParameterMetadata& paramMetadata);
257  } // namespace core
258 } // namespace blockfactory
259 
260 // PARAMETER
261 namespace blockfactory {
262  namespace core {
263  // Explicit declaration for numeric types
264  extern template bool Parameters::storeParameter<int>(const Parameter<int>& parameter);
265  extern template bool Parameters::storeParameter<bool>(const Parameter<bool>& parameter);
266  extern template bool Parameters::storeParameter<double>(const Parameter<double>& parameter);
267  extern template bool
268  Parameters::storeParameter<std::string>(const Parameter<std::string>& parameter);
269  } // namespace core
270 } // namespace blockfactory
271 
272 #endif // BLOCKFACTORY_CORE_PARAMETERS_H
bool storeParameter(const T &param, const blockfactory::core::ParameterMetadata &paramMetadata)
Store a scalar parameter.
Class for storing parameter metadata.
Definition: Parameter.h:59
ParamName getParamName(const ParamIndex &index) const
Get the name of a stored parameter from its index.
Class for storing a generic parameter.
Definition: Parameter.h:19
Parameters & operator=(const Parameters &other)
std::vector< Parameter< bool > > getBoolParameters() const
Get all the boolean parameters.
ParamIndex getParamIndex(const ParamName &name) const
Get the index of a stored parameter from its name.
bool existName(const ParamName &name) const
Check if a parameter with a given name is stored.
std::vector< Parameter< int > > getIntParameters() const
Get all the integer parameters.
Class for storing block&#39;s parameters.
Definition: Parameters.h:34
blockfactory::core::ParameterMetadata getParameterMetadata(const ParamName &name)
Get the metadata associated to a stored parameter.
Definition: Block.h:17
int ParamIndex
Definition: Parameters.h:37
std::vector< Parameter< double > > getDoubleParameters() const
Get all the double parameters.
const std::string PARAM_INVALID_NAME
Definition: Parameters.h:23
std::vector< Parameter< std::string > > getStringParameters() const
Get all the string parameters.
const int PARAM_INVALID_INDEX
Definition: Parameters.h:22
unsigned getNumberOfParameters() const
Get the number of stored parameters.
std::string ParamName
Definition: Parameters.h:38
bool getParameter(const ParamName &name, T &param) const
Get a scalar parameter.