cisst-saw
Loading...
Searching...
No Matches
cmnAssert.h
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/* ex: set filetype=cpp softtabstop=4 shiftwidth=4 tabstop=4 cindent expandtab: */
3
4/*
5 Author(s): Ankur Kapoor
6 Created on: 2003-06-25
7
8 (C) Copyright 2003-2019 Johns Hopkins University (JHU), All Rights Reserved.
9
10--- begin cisst license - do not edit ---
11
12This software is provided "as is" under an open source license, with
13no warranty. The complete license can be found in license.txt and
14http://www.cisst.org/cisst/license.txt.
15
16--- end cisst license ---
17*/
18
19
24#pragma once
25
26#ifndef _cmnAssert_h
27#define _cmnAssert_h
28
29
32
33#include <assert.h>
34#include <cstdlib>
35#include <sstream>
36
38
75#if defined(CISST_CMN_ASSERT_DISABLED) || defined(NDEBUG)
76 #define CMN_ASSERT_IS_DEFINED 0
77 #define CMN_ASSERT(expr)
78#else // CISST_CMN_ASSERT_DISABLED || NDEBUG
79
80 #define CMN_ASSERT_IS_DEFINED 1
81
82#ifdef CISST_CMN_ASSERT_THROWS_EXCEPTION
83
84#define CMN_ASSERT(expr) \
85 { \
86 if (!(expr)) { \
87 std::stringstream messageBuffer; \
88 messageBuffer << __FILE__ << ": Assertion '" << #expr \
89 << "' failed in: " << CMN_PRETTY_FUNCTION \
90 << ", line #" << __LINE__; \
91 cmnThrow(std::logic_error(messageBuffer.str())); \
92 } \
93 }
94
95#else // CISST_CMN_ASSERT_THROWS_EXCEPTION
96
97#define CMN_ASSERT(expr) \
98 { \
99 if (!(expr)) { \
100 std::stringstream messageBuffer; \
101 messageBuffer << __FILE__ << ": Assertion '" << #expr \
102 << "' failed in: " << CMN_PRETTY_FUNCTION \
103 << ", line #" << __LINE__; \
104 std::cerr << messageBuffer.str() << std::endl; \
105 CMN_LOG_INIT_ERROR << messageBuffer.str() << std::endl; \
106 abort(); \
107 } \
108 }
109
110#endif // CISST_CMN_ASSERT_THROWS_EXCEPTION
111
112#endif // CISST_CMN_ASSERT_DISABLED
113
114
115#endif // _cmnAssert_h
Declaration of cmnLogger amd macros for human readable logging.
Portability across compilers and operating systems tools.
Declaration of the template function cmnThrow.