2013-07-03 02:52:38 +00:00
|
|
|
/* Copyright (c) 2008-2013, Avian Contributors
|
2013-02-12 01:51:39 +00:00
|
|
|
|
|
|
|
Permission to use, copy, modify, and/or distribute this software
|
|
|
|
for any purpose with or without fee is hereby granted, provided
|
|
|
|
that the above copyright notice and this permission notice appear
|
|
|
|
in all copies.
|
|
|
|
|
|
|
|
There is NO WARRANTY for this software. See license.txt for
|
|
|
|
details. */
|
|
|
|
|
|
|
|
#ifndef AVIAN_UTIL_ABORT_H
|
|
|
|
#define AVIAN_UTIL_ABORT_H
|
|
|
|
|
2014-02-25 18:32:17 +00:00
|
|
|
// TODO: remove reference back into the source directory!
|
|
|
|
// Note: this is needed for UNLIKELY
|
|
|
|
#include <avian/common.h>
|
|
|
|
|
2013-02-20 05:42:07 +00:00
|
|
|
namespace avian {
|
|
|
|
namespace util {
|
|
|
|
|
2013-02-12 01:51:39 +00:00
|
|
|
class Aborter {
|
|
|
|
public:
|
|
|
|
virtual void NO_RETURN abort() = 0;
|
|
|
|
};
|
|
|
|
|
2014-02-25 22:15:37 +00:00
|
|
|
inline Aborter* getAborter(Aborter* a)
|
|
|
|
{
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2013-02-12 01:51:39 +00:00
|
|
|
template<class T>
|
|
|
|
inline void NO_RETURN abort(T t) {
|
|
|
|
getAborter(t)->abort();
|
|
|
|
::abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
inline void expect(T t, bool v) {
|
|
|
|
if(UNLIKELY(!v)) {
|
|
|
|
abort(t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef NDEBUG
|
|
|
|
#define assert(t, v)
|
|
|
|
#else
|
|
|
|
template<class T>
|
|
|
|
inline void assert(T t, bool v) {
|
|
|
|
expect(t, v);
|
|
|
|
}
|
|
|
|
#endif
|
2014-02-25 22:15:37 +00:00
|
|
|
|
2013-02-20 05:42:07 +00:00
|
|
|
} // namespace util
|
|
|
|
} // namespace avian
|
2013-02-12 01:51:39 +00:00
|
|
|
|
2013-02-20 05:42:07 +00:00
|
|
|
#endif // AVIAN_UTIL_ABORT_H
|