/usr/include/tulip/ForEach.h is in libtulip-dev 3.1.2-2.3ubuntu3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | //-*-c++-*-
/**
Authors: David Auber, Patrick Mary, Morgan Mathiaut
from the LaBRI Visualization Team
Email : auber@tulip-software.org
Last modification : 13/03/2009
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
*/
#ifndef Tulip_FOREACH_H
#define Tulip_FOREACH_H
#include <assert.h>
#include <tulip/Iterator.h>
#include <tulip/StableIterator.h>
#ifndef DOXYGEN_NOTFOR_DEVEL
namespace tlp {
template<typename TYPE>
struct _TLP_IT {
_TLP_IT(TYPE &_n, Iterator<TYPE> *_it, void (*_d) (void *)) : _d(_d), _it(_it), _n(_n) {
}
~_TLP_IT() {
delete _it;
}
void (*_d) (void *);
Iterator<TYPE> *_it;
TYPE &_n;
};
template <typename TYPE>
static void _tlp_delete_it(void *_it) {
delete (_TLP_IT<TYPE>*)_it;
}
template <typename TYPE>
inline void * _tlp_get_it(TYPE &n, Iterator<TYPE> *_it) {
return (void *)new _TLP_IT<TYPE>(n, _it, (void (*) (void *)) &_tlp_delete_it<TYPE>);
}
template <typename TYPE>
inline void * _tlp_get_stable_it(TYPE &n, Iterator<TYPE> *_it) {
return (void *)new _TLP_IT<TYPE>(n, new StableIterator<TYPE>(_it),
(void (*) (void *)) &_tlp_delete_it<TYPE>);
}
template<typename TYPE>
inline bool _tlp_if_test(TYPE &, void *_it) {
assert(((_TLP_IT<TYPE>*)_it)->_it !=0);
if(((_TLP_IT<TYPE>*)_it)->_it->hasNext()) {
((_TLP_IT<TYPE>*)_it)->_n = ((_TLP_IT<TYPE>*)_it)->_it->next();
return true;
}
else {
delete (_TLP_IT<TYPE>*)_it;
return false;
}
}
}
#endif //DOXYGEN_NOTFOR_DEVEL
/**
* Warning, do not use break or return inside a for each block;
* it causes a memory leak; use breakForEach pr returnForEachInstead
*/
#define forEach(A, B) \
for(void *_it_foreach = tlp::_tlp_get_it(A, B); tlp::_tlp_if_test(A, _it_foreach);)
#define stableForEach(A, B) \
for(void *_it_foreach = tlp::_tlp_get_stable_it(A, B); tlp::_tlp_if_test(A, _it_foreach);)
#define _delete_it_foreach ((**((void (**) (void *)) _it_foreach))(_it_foreach))
#define breakForEach {_delete_it_foreach; break;}
#define returnForEach(VAL) {_delete_it_foreach; return VAL;}
#endif
|