blockfactory  0.8
A framework for wrapping algorithms for dataflow programming
SimulinkBlockInformationImpl.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_MEX_IMPL_SIMULINKBLOCKINFORMATIONIMPL_H
10 #define BLOCKFACTORY_MEX_IMPL_SIMULINKBLOCKINFORMATIONIMPL_H
11 
13 #include "mxpp/MxArray.h"
14 
15 #include <simstruc.h>
16 
17 #include <string>
18 #include <vector>
19 
20 namespace blockfactory {
21  namespace mex {
22  namespace impl {
23  using ContiguousInputSignalRawPtr = const void*;
24  using NonContiguousInputSignalRawPtr = InputPtrsType;
27  } // namespace impl
28  } // namespace mex
29 } // namespace blockfactory
30 
37 {
38 private:
39 public:
40  using ParameterIndex = unsigned;
41 
47 
48  SimStruct* simstruct = nullptr;
49 
50  std::string confBlockName;
51  std::vector<core::ParameterMetadata> paramsMetadata;
52 
53  DataType mapSimulinkToPortType(const DTypeId typeId) const;
54  DTypeId mapPortTypeToSimulink(const DataType dataType) const;
55 
59 
60  bool getUniqueName(std::string& blockUniqueName) const;
61 
62  // =====================
63  // BLOCK OPTIONS METHODS
64  // =====================
65 
66  bool optionFromKey(const std::string& key, double& option) const;
67 
68  // =============
69  // PORTS METHODS
70  // =============
71 
72  bool updateInputPortInfo(const PortInfo& portData);
73  bool updateOutputPortInfo(const PortInfo& portData);
74  bool setNumberOfInputPorts(const size_t numberOfPorts);
75  bool setNumberOfOutputPorts(const size_t numberOfPorts);
76  bool setInputPortType(const PortIndex idx, const DataType type);
77  bool setOutputPortType(const PortIndex idx, const DataType type);
78  bool setInputPortVectorSize(const PortIndex idx, const VectorSize& size);
79  bool setInputPortMatrixSize(const PortIndex idx, const MatrixSize& size);
80  bool setOutputPortVectorSize(const PortIndex idx, const VectorSize& size);
81  bool setOutputPortMatrixSize(const PortIndex idx, const MatrixSize& size);
82  size_t getNrOfInputPortElements(const PortIndex idx) const;
83  size_t getNrOfOutputPortElements(const PortIndex idx) const;
84  PortInfo getInputPortInfo(const PortIndex idx) const;
85  PortInfo getOutputPortInfo(const PortIndex idx) const;
86  bool isInputPortDynamicallySized(const PortIndex idx) const;
87  bool isOutputPortDynamicallySized(const PortIndex idx) const;
88 
89  // ===============
90  // SIGNALS METHODS
91  // ===============
92 
93  bool isInputSignalAtIdxContiguous(const PortIndex idx) const;
98 
99  // =================
100  // SCALAR PARAMETERS
101  // =================
102 
103  bool getScalarParameterAtIndex(const ParameterIndex idx, double& value) const;
104  bool getBooleanParameterAtIndex(const ParameterIndex idx, bool& value) const;
105  bool getStringParameterAtIndex(const ParameterIndex idx, std::string& value) const;
106 
107  // =================================
108  // CELL / STRUCT / VECTOR PARAMETERS
109  // =================================
110 
111  bool getCellAtIndex(const ParameterIndex idx, mxpp::MxCell& value) const;
112  bool getStructAtIndex(const ParameterIndex idx, mxpp::MxStruct& value) const;
113  bool getVectorAtIndex(const ParameterIndex idx, std::vector<double>& value) const;
114 
115  // ===========================
116  // FIELDS OF STRUCT PARAMETERS
117  // ===========================
118 
119  bool getStringFieldAtIndex(const ParameterIndex idx,
120  const std::string& fieldName,
121  std::string& value) const;
122  bool getScalarFieldAtIndex(const ParameterIndex idx,
123  const std::string& fieldName,
124  double& value) const;
125  bool getBooleanFieldAtIndex(const ParameterIndex idx,
126  const std::string& fieldName,
127  bool& value) const;
128  bool getCellFieldAtIndex(const ParameterIndex idx,
129  const std::string& fieldName,
130  mxpp::MxCell& value) const;
132  const std::string& fieldName,
133  std::vector<double>& value) const;
134 };
135 
136 #endif // BLOCKFACTORY_MEX_IMPL_SIMULINKBLOCKINFORMATIONIMPL_H
InputPtrsType NonContiguousInputSignalRawPtr
Definition: SimulinkBlockInformationImpl.h:24
size_t Index
The 0-based index of a port.
Definition: Port.h:39
void * ContiguousOutputSignalRawPtr
Definition: SimulinkBlockInformationImpl.h:25
Definition: Block.h:17
A container of port information.
Definition: Port.h:78
int Vector
Definition: Port.h:98
const void * ContiguousInputSignalRawPtr
Definition: SimulinkBlockInformationImpl.h:23
DataType
Defines allowed port data types.
Definition: Port.h:62
struct{Rows rows Matrix
Definition: Port.h:104