Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
38 lines (31 sloc) 958 Bytes
// ensure.h - assert replacement that throws instead of calling abort()
// Copyright (c) KALX, LLC. All rights reserved. No warranty made.
// #define NENSURE before including to turn ensure checking off
#pragma once
#ifdef _WIN32
#define NOMINMAX
#define VC_EXTRALEAN
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#endif
#include <limits>
#include <stdexcept>
// Define NENSURE to turn off ensure.
#ifdef NENSURE
#define ensure(x)
#endif
#ifndef ensure
#define ENSURE_HASH_(x) #x
#define ENSURE_STRZ_(x) ENSURE_HASH_(x)
#define ENSURE_FILE "file: " __FILE__
#ifdef __FUNCTION__
#define ENSURE_FUNC "\nfunction: " __FUNCTION__
#else
#define ENSURE_FUNC ""
#endif
#define ENSURE_LINE "\nline: " ENSURE_STRZ_(__LINE__)
#define ENSURE_SPOT ENSURE_FILE ENSURE_LINE ENSURE_FUNC
#define ensure(e) if (!(e)) { \
throw std::runtime_error(ENSURE_SPOT "\nensure: \"" #e "\" failed"); \
} else (void)0;
#endif // ensure
You can’t perform that action at this time.