InOut.tpp
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 
25 //==============================================================//
26 // TEMPLATE DERIVED INOUT CLASS TEMPLATE METHODS //
27 //==============================================================//
28 
29 namespace mimmo {
30 
34 template<typename T, typename O>
36  m_var_ = nullptr;
37 };
38 
43 template<typename T, typename O>
45  m_obj_ = nullptr;
46  m_var_ = var_;
47  m_getVar_ = nullptr;
48 };
49 
55 template<typename T, typename O>
56 PortOutT<T,O>::PortOutT(T *var_, DataType datatype){
57  m_obj_ = nullptr;
58  m_var_ = var_;
59  m_getVar_ = nullptr;
60  m_datatype = datatype;
61 };
62 
68 template<typename T, typename O>
69 PortOutT<T,O>::PortOutT(O* obj_, T (O::*getVar_)()){
70  m_obj_ = obj_;
71  m_getVar_ = getVar_;
72  m_var_ = nullptr;
73 };
74 
81 template<typename T, typename O>
82 PortOutT<T,O>::PortOutT(O* obj_, T (O::*getVar_)(), DataType datatype){
83  m_obj_ = obj_;
84  m_getVar_ = getVar_;
85  m_var_ = nullptr;
86  m_datatype = datatype;
87 };
88 
89 
93 template<typename T, typename O>
95  m_obj_ = nullptr;
96  m_var_ = nullptr;
97  m_getVar_ = nullptr;
98 };
99 
103 template<typename T, typename O>
105  m_obj_ = other.m_obj_;
106  m_var_ = other.m_var_;
107  m_getVar_ = other.m_getVar_;
108 };
109 
113 template<typename T, typename O>
115  bool equal = true;
116  equal &= (m_obj_ == other.m_obj_);
117  equal &= (m_var_ == other.m_var_);
118  equal &= (m_getVar_ == other.m_getVar_);
119  return (equal);
120 };
121 
127 template<typename T, typename O>
128 void
130  if (m_getVar_ != nullptr){
131  T temp = ((m_obj_->*m_getVar_)());
132  m_obuffer << temp;
133  return;
134  }
135  if (m_var_ != nullptr){
136  m_obuffer << (*m_var_);
137  }
138 }
139 
140 
141 
145 template<typename T, typename O>
147  m_obj_ = nullptr;
148  m_var_ = nullptr;
149  m_setVar_ = nullptr;
150 };
151 
156 template<typename T, typename O>
158  m_obj_ = nullptr;
159  m_var_ = var_;
160  m_setVar_ = nullptr;
161  m_mandatory = false;
162 };
163 
171 template<typename T, typename O>
172 PortInT<T, O>::PortInT(T *var_, DataType datatype, bool mandatory, int family){
173  m_obj_ = nullptr;
174  m_var_ = var_;
175  m_setVar_ = nullptr;
176  m_datatype = datatype;
177  m_mandatory = mandatory;
178  m_familym = family;
179 };
180 
188 template<typename T, typename O>
189 PortInT<T,O>::PortInT(O* obj_, void (O::*setVar_)(T), bool mandatory, int family){
190  m_obj_ = obj_;
191  m_setVar_ = setVar_;
192  m_var_ = nullptr;
193  m_mandatory = mandatory;
194  m_familym = family;
195 };
196 
205 template<typename T, typename O>
206 PortInT<T,O>::PortInT(O* obj_, void (O::*setVar_)(T), DataType datatype, bool mandatory, int family){
207  m_obj_ = obj_;
208  m_setVar_ = setVar_;
209  m_var_ = nullptr;
210  m_datatype = datatype;
211  m_mandatory = mandatory;
212  m_familym = family;
213 };
214 
218 template<typename T, typename O>
220  m_obj_ = nullptr;
221  m_var_ = nullptr;
222  m_setVar_ = nullptr;
223 };
224 
228 template<typename T, typename O>
230  m_obj_ = other.m_obj_;
231  m_var_ = other.m_var_;
232  m_setVar_ = other.m_setVar_;
233 };
234 
238 template<typename T, typename O>
240  bool equal = true;
241  equal &= (m_obj_ == other.m_obj_);
242  equal &= (m_var_ == other.m_var_);
243  equal &= (m_setVar_ == other.m_setVar_);
244  return (equal);
245 };
246 
251 template<typename T, typename O>
252 void
254  T temp;
255  m_ibuffer >> temp;
256  if (m_setVar_ != nullptr){
257  (m_obj_->*m_setVar_)(temp);
258  return;
259  }
260  if (m_var_ != nullptr){
261  (*m_var_) = temp;
262  }
263 }
264 
265 
266 } //end of mimmo namespace
Class DataType defines the container and the type of data communicated by ports.
Definition: InOut.hpp:53
bool operator==(const PortOutT &other)
Definition: InOut.tpp:114
virtual ~PortInT()
Definition: InOut.tpp:219
void readBuffer()
Definition: InOut.tpp:253
T(O::* m_getVar_)()
Definition: InOut.hpp:161
void writeBuffer()
Definition: InOut.tpp:129
void(O::* m_setVar_)(T)
Definition: InOut.hpp:270
PortOutT is the PIN class to exchange output data from an object to others.
Definition: InOut.hpp:155
bool operator==(const PortInT &other)
Definition: InOut.tpp:239
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 ~PortOutT()
Definition: InOut.tpp:94
PortInT is the PIN class to get input data arriving to an object from other objects.
Definition: InOut.hpp:264