IntaRNA 3.4.1
RNA-RNA interaction prediction | C++ API
Loading...
Searching...
No Matches
OutputHandlerHub.h
Go to the documentation of this file.
1
2#ifndef INTARNA_OUTPUTHANDLERHUB_H_
3#define INTARNA_OUTPUTHANDLERHUB_H_
4
6
7#include <list>
8
9namespace IntaRNA {
10
17{
18protected:
19
21 std::list< OutputHandler * > outList;
22
26
27public:
28
37 , const bool deleteOutListOnDestruction = true );
38
44 OutputHandlerHub( const OutputHandlerHub & toCopy );
45
46
50 virtual ~OutputHandlerHub();
51
52
59 virtual
60 void
61 add( const Interaction & interaction );
62
68 virtual
69 size_t
70 reported() const;
71
81 virtual
82 void
83 incrementZ( const Z_type subZ );
84
91 virtual
92 Z_type
93 getZ() const;
94
99 virtual
100 void
101 addOutputHandler( OutputHandler * handler );
102
108 virtual
109 void
110 setDeleteOnDestruction( const bool deleteOnDestruction );
111
117 virtual
118 bool
119 isDeleteOnDestruction() const;
120
121
132 operator= ( const OutputHandlerHub & toCopy);
133
134
135};
136
137
139
140inline
141OutputHandlerHub
142::OutputHandlerHub( const OutputConstraint & outConstraint
143 , const bool deleteOnDestruction )
144 : OutputHandler(outConstraint)
145 , outList()
146 , deleteOutListOnDestruction(deleteOnDestruction)
147{
148}
149
151
152inline
153OutputHandlerHub
154::OutputHandlerHub( const OutputHandlerHub & toCopy )
155 : OutputHandler( toCopy.outConstraint )
156 , outList( toCopy.outList )
157 // dont delete on destruction (should be done by original) to avoid double cleanup
158 , deleteOutListOnDestruction(false)
159{
160}
161
163
164inline
167{
168 // check if something is to be done
169 if (isDeleteOnDestruction()) {
170 // delete all handler
171 for( auto it = outList.begin(); it != outList.end(); it++ ) {
172 INTARNA_CLEANUP( (*it) );
173 }
174 }
175}
176
177
178
180
181inline
182void
185{
186#if INTARNA_IN_DEBUG_MODE
187 if (handler != NULL) {
188 // check if already present
189 for (auto it=outList.begin(); it!=outList.end(); it++) {
190 if (handler == (*it)) {
191 throw std::runtime_error("OutputHandlerHub::addOutputHandler() : repeated adding of the same OutputHandler pointer");
192 }
193 }
194 }
195#endif
196 // add if not null
197 if (handler != NULL) {
198 outList.push_back(handler);
199 }
200}
201
203
204inline
205void
207add( const Interaction & inter )
208{
209 // forward to all in list
210 for (auto it=outList.begin(); it!=outList.end(); it++) {
211 (*it)->add(inter);
212 }
213}
214
216
217inline
218size_t
220reported() const
221{
222 size_t maxReported = 0;
223 // get maximal number of reports among all handlers
224 for (auto it=outList.begin(); it!=outList.end(); it++) {
225 maxReported = std::max( maxReported, (*it)->reported() );
226 }
227 // return maximum
228 return maxReported;
229}
230
232
233inline
234void
236incrementZ( const Z_type subZ )
237{
238 // forward to all in list
239 for (auto it=outList.begin(); it!=outList.end(); it++) {
240 (*it)->incrementZ(subZ);
241 }
242}
243
245
246inline
247Z_type
249getZ( ) const
250{
251 Z_type maxZ = 0;
252 // find max from all in list
253 for (auto it=outList.begin(); it!=outList.end(); it++) {
254 if ((*it)->getZ() > maxZ) {
255 maxZ = (*it)->getZ();
256 }
257 }
258 return maxZ;
259}
260
262
263inline
264void
266setDeleteOnDestruction( const bool deleteOnDestruction )
267{
268 this->deleteOutListOnDestruction = deleteOnDestruction;
269}
270
272
273inline
274bool
280
282
283inline
286operator= ( const OutputHandlerHub & toCopy)
287{
288 // clean up current content
289 if (this->deleteOutListOnDestruction) {
290 for (auto it=outList.begin(); it!=outList.end(); it++) {
291 INTARNA_CLEANUP( (*it) );
292 }
293 }
294 outList.clear();
295
296 // copy data
297 outList = toCopy.outList;
298 // ensure this copy doesnt delete the list content
300
301 // modified object access
302 return *this;
303}
304
306
307} // namespace
308
309#endif /* OUTPUTHANDLERHUB_H_ */
Definition Interaction.h:28
Definition OutputConstraint.h:19
Definition OutputHandlerHub.h:17
OutputHandlerHub & operator=(const OutputHandlerHub &toCopy)
Definition OutputHandlerHub.h:286
virtual ~OutputHandlerHub()
Definition OutputHandlerHub.h:166
virtual void addOutputHandler(OutputHandler *handler)
Definition OutputHandlerHub.h:184
virtual bool isDeleteOnDestruction() const
Definition OutputHandlerHub.h:276
bool deleteOutListOnDestruction
Definition OutputHandlerHub.h:25
virtual Z_type getZ() const
Definition OutputHandlerHub.h:249
virtual void setDeleteOnDestruction(const bool deleteOnDestruction)
Definition OutputHandlerHub.h:266
virtual size_t reported() const
Definition OutputHandlerHub.h:220
virtual void incrementZ(const Z_type subZ)
Definition OutputHandlerHub.h:236
virtual void add(const Interaction &interaction)
Definition OutputHandlerHub.h:207
std::list< OutputHandler * > outList
list of OutputHandler objects to forward to
Definition OutputHandlerHub.h:21
Definition OutputHandler.h:20
const OutputConstraint outConstraint
the output constraints to be applied
Definition OutputHandler.h:103
void INTARNA_CLEANUP(T *&pointer)
Definition general.h:30
Definition Accessibility.h:13
double Z_type
type for probabilities, RT and Boltzmann values
Definition general.h:88