blockfactory  0.8
A framework for wrapping algorithms for dataflow programming
Parameter.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_PARAMETER_H
10 #define BLOCKFACTORY_CORE_PARAMETER_H
11 
12 #include <string>
13 #include <vector>
14 
15 namespace blockfactory {
16  namespace core {
17  class ParameterMetadata;
18  template <typename T>
19  class Parameter;
20  enum class ParameterType;
21  } // namespace core
22 } // namespace blockfactory
23 
29 {
30  // Scalar / Vector / Matrix
31  INT,
32  BOOL,
33  DOUBLE,
34  STRING,
35  // Cell
36  CELL_INT,
37  CELL_BOOL,
40  // Struct
41  STRUCT_INT,
49 };
50 
60 {
61 public:
62  enum
63  {
64  DynamicSize = -1
65  };
66 
67  const unsigned index;
68  const std::string name;
69 
70  int rows;
71  int cols;
73 
74  ParameterMetadata() = delete;
75  ~ParameterMetadata() = default;
76 
78  const unsigned& ParamIndex,
79  const int& paramRows,
80  const int& paramCols,
81  const std::string& ParamName = {});
82  ParameterMetadata(const ParameterMetadata& paramMD);
83  ParameterMetadata(ParameterMetadata&& paramMD);
84 
85  ParameterMetadata& operator=(const ParameterMetadata& paramMD);
86  ParameterMetadata& operator=(ParameterMetadata&& paramMD);
87  bool operator==(const ParameterMetadata& rhs) const;
88  inline bool operator!=(const ParameterMetadata& rhs) const { return !(*this == rhs); }
89 };
90 
101 template <typename T>
103 {
104 private:
105  using ParamVector = std::vector<T>;
106 
111 
112 public:
113  enum class Type;
114  Parameter() = delete;
115  ~Parameter() = default;
116 
118  : m_isScalar(true)
119  , m_valueScalar(value)
120  , m_metadata(md)
121  {}
123  : m_isScalar(false)
124  , m_valueVector(valueVec)
125  , m_metadata(md)
126  {}
127 
128  bool isScalar() const { return m_isScalar; }
129  T getScalarParameter() const { return m_valueScalar; }
130  ParamVector getVectorParameter() const { return m_valueVector; }
131  blockfactory::core::ParameterMetadata getMetadata() const { return m_metadata; }
132 };
133 
134 #endif // BLOCKFACTORY_CORE_PARAMETER_H
ParamVector m_valueVector
Definition: Parameter.h:109
bool operator!=(const ParameterMetadata &rhs) const
Definition: Parameter.h:88
Class for storing parameter metadata.
Definition: Parameter.h:59
Class for storing a generic parameter.
Definition: Parameter.h:19
ParamVector getVectorParameter() const
Definition: Parameter.h:130
Parameter(const T &value, const blockfactory::core::ParameterMetadata &md)
Definition: Parameter.h:117
std::vector< T > ParamVector
Definition: Parameter.h:105
int rows
Definition: Parameter.h:70
blockfactory::core::ParameterMetadata m_metadata
Definition: Parameter.h:110
int cols
Definition: Parameter.h:71
blockfactory::core::ParameterMetadata getMetadata() const
Definition: Parameter.h:131
Definition: Block.h:17
const unsigned index
Definition: Parameter.h:67
Parameter(const ParamVector &valueVec, const blockfactory::core::ParameterMetadata &md)
Definition: Parameter.h:122
ParameterType
Defines the types of parameters supported by core::Parameter.
Definition: Parameter.h:28
T getScalarParameter() const
Definition: Parameter.h:129
bool isScalar() const
Definition: Parameter.h:128
blockfactory::core::ParameterType type
Definition: Parameter.h:72
T m_valueScalar
Definition: Parameter.h:108
const std::string name
Definition: Parameter.h:68
bool m_isScalar
Definition: Parameter.h:107