Files

42 lines
1.3 KiB
C++
Raw Permalink Normal View History

2022-03-25 12:32:36 -07:00
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef LEAKDETECTOR_H
#define LEAKDETECTOR_H
#include <QObject>
2023-07-15 14:19:48 -07:00
#ifdef MZ_DEBUG
# define MZ_COUNT_CTOR(_type) \
2022-03-25 12:32:36 -07:00
do { \
static_assert(std::is_class<_type>(), \
"Token '" #_type "' is not a class type."); \
LeakDetector::logCtor((void*)this, #_type, sizeof(*this)); \
} while (0)
2023-07-15 14:19:48 -07:00
# define MZ_COUNT_DTOR(_type) \
2022-03-25 12:32:36 -07:00
do { \
static_assert(std::is_class<_type>(), \
"Token '" #_type "' is not a class type."); \
LeakDetector::logDtor((void*)this, #_type, sizeof(*this)); \
} while (0)
#else
2023-07-15 14:19:48 -07:00
# define MZ_COUNT_CTOR(_type)
# define MZ_COUNT_DTOR(_type)
2022-03-25 12:32:36 -07:00
#endif
class LeakDetector {
public:
LeakDetector();
~LeakDetector();
2023-07-15 14:19:48 -07:00
#ifdef MZ_DEBUG
2022-03-25 12:32:36 -07:00
static void logCtor(void* ptr, const char* typeName, uint32_t size);
static void logDtor(void* ptr, const char* typeName, uint32_t size);
#endif
};
#endif // LEAKDETECTOR_H