1
0
mirror of https://github.com/stefanocasazza/ULib.git synced 2025-09-28 19:05:55 +08:00
ULib/include/ulib/debug/error_memory.h
stefanocasazza 1517b842c4 sync
2019-05-07 19:08:34 +02:00

50 lines
1.2 KiB
C++

// ============================================================================
//
// = LIBRARY
// ULib - c++ library
//
// = FILENAME
// error_memory.h
//
// = AUTHOR
// Stefano Casazza
//
// ============================================================================
#ifndef ULIB_ERROR_MEMORY_H
#define ULIB_ERROR_MEMORY_H 1
#include <ulib/debug/macro.h>
// CLASS FOR MEMORY CORRUPTION TEST
class U_EXPORT UMemoryError {
public:
const void* _this;
// CONSTRUCTOR
UMemoryError() { _this = (void*)U_CHECK_MEMORY_SENTINEL; }
~UMemoryError() { U_ASSERT_MACRO(invariant(), "ERROR ON MEMORY", getErrorType(this)) _this = U_NULLPTR; }
UMemoryError(const UMemoryError& m) { _this = m._this; }
// ASSIGNMENT
UMemoryError& operator=(const UMemoryError& o)
{
U_ASSERT_MACRO(o.invariant(), "ERROR ON MEMORY", o.getErrorType(&o))
U_ASSERT_MACRO( invariant(), "ERROR ON MEMORY", getErrorType(this))
return *this;
}
// TEST FOR MEMORY CORRUPTION
bool invariant() const { return (_this == (void*)U_CHECK_MEMORY_SENTINEL); }
const char* getErrorType(const void* pobj) const;
};
#endif