1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-07 03:12:36 +01:00
openrw/rwlib/source/rw/defines.hpp

65 lines
1.8 KiB
C++
Raw Normal View History

#ifndef _LIBRW_DEFINES_HPP_
#define _LIBRW_DEFINES_HPP_
#if RW_DEBUG
#include <cstdlib>
#include <functional>
extern std::function<void()> _rw_abort_cb[2];
#define SET_RW_ABORT_CB(cb0, cb1) do { _rw_abort_cb[0] = cb0; _rw_abort_cb[1] = cb1;} while (0)
#define RW_ABORT() do { if(_rw_abort_cb[0]) _rw_abort_cb[0](); ::abort(); } while (0)
#define RW_ASSERT(cond) do { if (!(cond)) RW_ABORT();} while (0)
#if defined(RW_WINDOWS)
#include <Windows.h>
#define RW_BREAKPOINT() DebugBreak()
#else
#include <csignal>
#define RW_BREAKPOINT() do { if(_rw_abort_cb[0]) _rw_abort_cb[0](); ::raise(SIGTRAP); if(_rw_abort_cb[1]) _rw_abort_cb[1](); } while (0)
#endif
#define RW_FAILED_NO_ACTION 0
#define RW_FAILED_ABORT_OPTION 1
#define RW_FAILED_BREAKPOINT_OPTION 2
#if RW_FAILED_CHECK_ACTION == RW_FAILED_NO_ACTION
#define _RW_FAILED_CHECK_ACTION()
#elif RW_FAILED_CHECK_ACTION == RW_FAILED_ABORT_OPTION
#define _RW_FAILED_CHECK_ACTION() RW_ABORT()
#elif RW_FAILED_CHECK_ACTION == RW_FAILED_BREAKPOINT_OPTION
#define _RW_FAILED_CHECK_ACTION() RW_BREAKPOINT()
#endif
#else
#define SET_RW_ABORT_CB(cb0, cb1)
#define RW_ABORT()
#define RW_ASSERT(cond)
#define RW_BREAKPOINT()
#define _RW_FAILED_CHECK_ACTION()
#endif
#if RW_DEBUG && RW_VERBOSE_DEBUG_MESSAGES
2016-09-09 22:13:21 +02:00
#include <iostream>
#define RW_MESSAGE(msg) \
std::cout << __FILE__ << ":" << __LINE__ << ": " << msg << std::endl
#define RW_ERROR(msg) \
std::cerr << __FILE__ << ":" << __LINE__ << ": " << msg << std::endl
#else
2016-09-09 22:13:21 +02:00
#define RW_MESSAGE(msg)
#define RW_ERROR(msg)
#endif
#if RW_DEBUG
#define RW_CHECK(cond, msg) \
do { if (!(cond)) { RW_ERROR(msg); _RW_FAILED_CHECK_ACTION();}} while (0)
#else
2016-09-09 22:13:21 +02:00
#define RW_CHECK(cond, msg)
#endif
2016-09-09 22:13:21 +02:00
#define RW_UNUSED(var) (void)var
2016-04-28 01:54:42 +02:00
2016-09-09 22:13:21 +02:00
#define RW_UNIMPLEMENTED(msg) RW_MESSAGE("Unimplemented: " << msg)
#endif