eoFunctor: protected member and security warning in debug mode when storing the same pointer several times

This commit is contained in:
nojhan 2012-04-03 15:41:07 +02:00
commit 854c65f582

View file

@ -28,6 +28,9 @@
#define _eoFunctorStore_h #define _eoFunctorStore_h
#include <vector> #include <vector>
#include<algorithm>
#include "utils/eoLogger.h"
class eoFunctorBase; class eoFunctorBase;
@ -52,6 +55,13 @@ public:
template <class Functor> template <class Functor>
Functor& storeFunctor(Functor* r) Functor& storeFunctor(Functor* r)
{ {
#ifndef NDEBUG
unsigned int existing = std::count( vec.begin(), vec.end(), r );
if( existing > 0 ) {
eo::log << eo::warnings << "WARNING: you asked eoFunctorStore to store the functor " << r << " "
<< existing + 1 << " times, a segmentation fault may occur in the destructor." << std::endl;
}
#endif
// If the compiler complains about the following line, // If the compiler complains about the following line,
// check if you really are giving it a pointer to an // check if you really are giving it a pointer to an
// eoFunctorBase derived object // eoFunctorBase derived object
@ -67,6 +77,7 @@ private :
/** no assignment allowed */ /** no assignment allowed */
eoFunctorStore operator=(const eoFunctorStore&); eoFunctorStore operator=(const eoFunctorStore&);
protected:
std::vector<eoFunctorBase*> vec; std::vector<eoFunctorBase*> vec;
}; };