Files
Upsilon/apps/shared/expiring_pointer.h
Émilie Feral e8b58a2b5b [shared] Create ExpiringPointer: in DEBUG, check that pointers to
memoized functions are not used when invalid
2018-11-23 12:04:03 +01:00

38 lines
643 B
C++

#ifndef SHARED_EXPIRING_POINTER_H
#define SHARED_EXPIRING_POINTER_H
#include <escher.h>
namespace Shared {
template <class T>
class ExpiringPointer {
public:
ExpiringPointer(T * rawPointer, bool reinitGlobal = true) : m_rawPointer(rawPointer) {
#if DEBUG
s_global = rawPointer;
#endif
}
T *operator->() {
#if DEBUG
assert(m_rawPointer != nullptr && m_rawPointer == s_global);
#endif
return m_rawPointer;
}
T &operator*() {
#if DEBUG
assert(m_rawPointer != nullptr && m_rawPointer == s_global);
#endif
return *m_rawPointer;
}
private:
#if DEBUG
static T * s_global;
#endif
T * m_rawPointer;
};
}
#endif