InOut.hpp
1 /*---------------------------------------------------------------------------*\
2 *
3 * mimmo
4 *
5 * Copyright (C) 2015-2021 OPTIMAD engineering Srl
6 *
7 * -------------------------------------------------------------------------
8 * License
9 * This file is part of mimmo.
10 *
11 * mimmo is free software: you can redistribute it and/or modify it
12 * under the terms of the GNU Lesser General Public License v3 (LGPL)
13 * as published by the Free Software Foundation.
14 *
15 * mimmo is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18 * License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with mimmo. If not, see <http://www.gnu.org/licenses/>.
22 *
23 \*---------------------------------------------------------------------------*/
24 #ifndef __INOUT_HPP__
25 #define __INOUT_HPP__
26 
27 #include <mimmo_binary_stream.hpp>
28 #include <functional>
29 
30 namespace mimmo{
31 
33 
38 typedef std::string PortID;
39 typedef std::string containerTAG;
40 typedef std::string dataTAG;
53 class DataType{
54 public:
58 public:
59  DataType();
60  DataType(containerTAG conType, dataTAG dataType);
61  virtual ~DataType();
62 
64  DataType(const DataType&) = default;
66  DataType& operator=(const DataType&) = default;
67 
68  bool operator==(const DataType & other);
69 
70 };
71 
96 class PortOut{
97 public:
98  //members
100  std::vector<BaseManipulation*> m_objLink;
101  std::vector<PortID> m_portLink;
104 public:
105  PortOut();
106  virtual ~PortOut();
107 
108  PortOut(const PortOut & other);
109  bool operator==(const PortOut & other);
110 
111  std::vector<BaseManipulation*> getLink();
112  std::vector<PortID> getPortLink();
114 
118  virtual void writeBuffer() = 0;
119  void cleanBuffer();
120 
121  void clear();
122  void clear(int j);
123 
124  void exec();
125 
126 };
127 
128 
129 //==============================================================//
130 // TEMPLATE DERIVED INOUT CLASS //
131 //==============================================================//
132 
154 template<typename T, typename O>
155 class PortOutT: public PortOut {
156 
157 public:
158 
159  O* m_obj_;
160  T *m_var_;
161  T (O::*m_getVar_)();
163 public:
164  PortOutT();
165  PortOutT(T *var_);
166  PortOutT(T *var_, DataType datatype);
167  PortOutT(O* obj_, T (O::*getVar_)());
168  PortOutT(O* obj_, T (O::*getVar_)(), DataType datatype);
169  virtual ~PortOutT();
170 
171  PortOutT(const PortOutT & other);
172  bool operator==(const PortOutT & other);
173 
174  void writeBuffer();
175 
176 };
177 
178 
179 
201 class PortIn{
202 public:
203  //members
205  std::vector<BaseManipulation*> m_objLink;
207  bool m_mandatory;
208  int m_familym;
212 public:
213  PortIn();
214  virtual ~PortIn();
215 
216  PortIn(const PortIn & other);
217  bool operator==(const PortIn & other);
218 
219  std::vector<mimmo::BaseManipulation*> getLink();
221  bool isMandatory();
222  int getFamily();
223 
224  void clear();
225  void clear(int j);
226 
230  virtual void readBuffer() = 0;
231  void cleanBuffer();
232 
233 };
234 
235 
236 //==============================================================//
237 // TEMPLATE DERIVED INOUT CLASS //
238 //==============================================================//
239 
263 template<typename T, typename O>
264 class PortInT: public PortIn {
265 
266 public:
267 
268  O* m_obj_;
269  T *m_var_;
270  void (O::*m_setVar_)(T);
272 public:
273  PortInT();
274  PortInT(T *var_);
275  PortInT(T *var_, DataType datatype, bool mandatory = false, int family = 0);
276  PortInT(O* obj_, void (O::*setVar_)(T), bool mandatory = false, int family = 0);
277  PortInT(O* obj_, void (O::*setVar_)(T), DataType datatype, bool mandatory = false, int family = 0);
278  virtual ~PortInT();
279 
280  PortInT(const PortInT & other);
281  bool operator==(const PortInT & other);
282 
283  void readBuffer();
284 
285 };
286 
287 }
288 
289 #include "InOut.tpp"
290 
291 #endif /* __INOUT_HPP__ */
std::vector< BaseManipulation * > m_objLink
Definition: InOut.hpp:205
DataType getDataType()
Definition: InOut.cpp:234
Class DataType defines the container and the type of data communicated by ports.
Definition: InOut.hpp:53
std::vector< BaseManipulation * > getLink()
Definition: InOut.cpp:111
std::string dataTAG
Definition: InOut.hpp:40
bool operator==(const PortOutT &other)
Definition: InOut.tpp:114
void clear()
Definition: InOut.cpp:260
virtual ~PortInT()
Definition: InOut.tpp:219
void readBuffer()
Definition: InOut.tpp:253
T(O::* m_getVar_)()
Definition: InOut.hpp:161
std::string containerTAG
Definition: InOut.hpp:39
void writeBuffer()
Definition: InOut.tpp:129
std::vector< BaseManipulation * > m_objLink
Definition: InOut.hpp:100
bool operator==(const PortIn &other)
Definition: InOut.cpp:211
bool operator==(const PortOut &other)
Definition: InOut.cpp:98
std::vector< PortID > m_portLink
Definition: InOut.hpp:101
virtual ~PortOut()
Definition: InOut.cpp:82
virtual void writeBuffer()=0
void cleanBuffer()
Definition: InOut.cpp:137
void(O::* m_setVar_)(T)
Definition: InOut.hpp:270
virtual ~DataType()
Definition: InOut.cpp:54
mimmo custom derivation of bitpit OBinaryStream (see relative doc)
DataType getDataType()
Definition: InOut.cpp:129
void clear()
Definition: InOut.cpp:145
BaseManipulation is the base class of any manipulation object of the library.
PortOutT is the PIN class to exchange output data from an object to others.
Definition: InOut.hpp:155
void exec()
Definition: InOut.cpp:168
DataType m_datatype
Definition: InOut.hpp:206
int getFamily()
Definition: InOut.cpp:252
bool operator==(const PortInT &other)
Definition: InOut.tpp:239
bool operator==(const DataType &other)
Definition: InOut.cpp:60
PortIn is the abstract PIN base class dedicated to carry data to a target class from other ones (inpu...
Definition: InOut.hpp:201
PortOut is the abstract PIN base class dedicated to exchange data from a target class to other ones (...
Definition: InOut.hpp:96
virtual ~PortIn()
Definition: InOut.cpp:194
std::vector< PortID > getPortLink()
Definition: InOut.cpp:120
mimmo::OBinaryStream m_obuffer
Definition: InOut.hpp:99
virtual ~PortOutT()
Definition: InOut.tpp:94
std::vector< mimmo::BaseManipulation * > getLink()
Definition: InOut.cpp:225
DataType m_datatype
Definition: InOut.hpp:102
bool isMandatory()
Definition: InOut.cpp:243
DataType & operator=(const DataType &)=default
containerTAG m_conType
Definition: InOut.hpp:55
std::string PortID
Definition: InOut.hpp:32
mimmo custom derivation of bitpit IBinaryStream (see relative doc)
virtual void readBuffer()=0
bool m_mandatory
Definition: InOut.hpp:207
mimmo::IBinaryStream m_ibuffer
Definition: InOut.hpp:204
void cleanBuffer()
Definition: InOut.cpp:280
int m_familym
Definition: InOut.hpp:208
PortInT is the PIN class to get input data arriving to an object from other objects.
Definition: InOut.hpp:264
dataTAG m_dataType
Definition: InOut.hpp:56