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
30 void setExactPartition(bool exact) override;
31
40 , const bool deleteOutListOnDestruction = true );
41
47 OutputHandlerHub( const OutputHandlerHub & toCopy );
48
49
53 virtual ~OutputHandlerHub() override;
54
55
62 virtual
63 void
64 add( const Interaction & interaction ) override;
65
71 virtual
72 size_t
73 reported() const override;
74
84 virtual
85 void
86 incrementZ( const Z_type subZ ) override;
87
94 virtual
95 Z_type
96 getZ() const override;
97
102 virtual
103 void
104 addOutputHandler( OutputHandler * handler );
105
111 virtual
112 void
113 setDeleteOnDestruction( const bool deleteOnDestruction );
114
120 virtual
121 bool
122 isDeleteOnDestruction() const;
123
124
135 operator= ( const OutputHandlerHub & toCopy);
136
137
138};
139
140
142
143inline
144OutputHandlerHub
145::OutputHandlerHub( const OutputConstraint & outConstraint
146 , const bool deleteOnDestruction )
147 : OutputHandler(outConstraint)
148 , outList()
149 , deleteOutListOnDestruction(deleteOnDestruction)
150{
151}
152
154
155inline
156OutputHandlerHub
157::OutputHandlerHub( const OutputHandlerHub & toCopy )
158 : OutputHandler( toCopy.outConstraint )
159 , outList( toCopy.outList )
160 // dont delete on destruction (should be done by original) to avoid double cleanup
161 , deleteOutListOnDestruction(false)
162{
164}
165
167
168inline
171{
172 // check if something is to be done
173 if (isDeleteOnDestruction()) {
174 // delete all handler
175 for( auto it = outList.begin(); it != outList.end(); it++ ) {
176 INTARNA_CLEANUP( (*it) );
177 }
178 }
179}
180
181
182
184
185inline
186void
189{
190#if INTARNA_IN_DEBUG_MODE
191 if (handler != NULL) {
192 // check if already present
193 for (auto it=outList.begin(); it!=outList.end(); it++) {
194 if (handler == (*it)) {
195 throw std::runtime_error("OutputHandlerHub::addOutputHandler() : repeated adding of the same OutputHandler pointer");
196 }
197 }
198 }
199#endif
200 // add if not null
201 if (handler != NULL) {
203 outList.push_back(handler);
204 }
205}
206
208
209inline
210void
212add( const Interaction & inter )
213{
214 // forward to all in list
215 for (auto it=outList.begin(); it!=outList.end(); it++) {
216 (*it)->add(inter);
217 }
218}
219
221
222inline
223size_t
225reported() const
226{
227 size_t maxReported = 0;
228 // get maximal number of reports among all handlers
229 for (auto it=outList.begin(); it!=outList.end(); it++) {
230 maxReported = std::max( maxReported, (*it)->reported() );
231 }
232 // return maximum
233 return maxReported;
234}
235
237
238inline
239void
241incrementZ( const Z_type subZ )
242{
243 // forward to all in list
244 for (auto it=outList.begin(); it!=outList.end(); it++) {
245 (*it)->incrementZ(subZ);
246 }
247}
248
250
251inline
252Z_type
254getZ( ) const
255{
256 Z_type maxZ = 0;
257 // find max from all in list
258 for (auto it=outList.begin(); it!=outList.end(); it++) {
259 if ((*it)->getZ() > maxZ) {
260 maxZ = (*it)->getZ();
261 }
262 }
263 return maxZ;
264}
265
267
268inline
269void
271setDeleteOnDestruction( const bool deleteOnDestruction )
272{
273 this->deleteOutListOnDestruction = deleteOnDestruction;
274}
275
277
278inline
279bool
285
287
288inline
291operator= ( const OutputHandlerHub & toCopy)
292{
293 // clean up current content
294 if (this->deleteOutListOnDestruction) {
295 for (auto it=outList.begin(); it!=outList.end(); it++) {
296 INTARNA_CLEANUP( (*it) );
297 }
298 }
299 outList.clear();
300
301 // copy data
303 outList = toCopy.outList;
304 // ensure this copy doesnt delete the list content
306
307 // modified object access
308 return *this;
309}
310
312
313inline void OutputHandlerHub::setExactPartition(bool exact) {
315 for (auto handler:outList) handler->setExactPartition(exact);
316}
317
318} // namespace
319
320#endif /* OUTPUTHANDLERHUB_H_ */
Definition Interaction.h:28
Definition OutputConstraint.h:19
Definition OutputHandlerHub.h:17
virtual ~OutputHandlerHub() override
Definition OutputHandlerHub.h:170
OutputHandlerHub & operator=(const OutputHandlerHub &toCopy)
Definition OutputHandlerHub.h:291
virtual void addOutputHandler(OutputHandler *handler)
Definition OutputHandlerHub.h:188
void setExactPartition(bool exact) override
Definition OutputHandlerHub.h:313
virtual bool isDeleteOnDestruction() const
Definition OutputHandlerHub.h:281
bool deleteOutListOnDestruction
Definition OutputHandlerHub.h:25
virtual Z_type getZ() const override
Definition OutputHandlerHub.h:254
virtual size_t reported() const override
Definition OutputHandlerHub.h:225
virtual void setDeleteOnDestruction(const bool deleteOnDestruction)
Definition OutputHandlerHub.h:271
virtual void incrementZ(const Z_type subZ) override
Definition OutputHandlerHub.h:241
virtual void add(const Interaction &interaction) override
Definition OutputHandlerHub.h:212
std::list< OutputHandler * > outList
list of OutputHandler objects to forward to
Definition OutputHandlerHub.h:21
Definition OutputHandler.h:22
const OutputConstraint outConstraint
the output constraints to be applied
Definition OutputHandler.h:116
bool usesExactPartition() const
Definition OutputHandler.h:212
bool exactPartition
scoped to a supported sequence-pair ensemble, legacy outputs default false
Definition OutputHandler.h:113
virtual void setExactPartition(bool exact)
Definition OutputHandler.h:211
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