NimbleSM
NimbleSM is a solid mechanics simulation code for dynamic systems
Loading...
Searching...
No Matches
nimble_macros.h
Go to the documentation of this file.
1/*
2//@HEADER
3// ************************************************************************
4//
5// NimbleSM
6// Copyright 2018
7// National Technology & Engineering Solutions of Sandia, LLC (NTESS)
8//
9// Under the terms of Contract DE-NA0003525 with NTESS, the U.S. Government
10// retains certain rights in this software.
11//
12// Redistribution and use in source and binary forms, with or without
13// modification, are permitted provided that the following conditions are
14// met:
15//
16// 1. Redistributions of source code must retain the above copyright
17// notice, this list of conditions and the following disclaimer.
18//
19// 2. Redistributions in binary form must reproduce the above copyright
20// notice, this list of conditions and the following disclaimer in the
21// documentation and/or other materials provided with the distribution.
22//
23// 3. Neither the name of the Corporation nor the names of the
24// contributors may be used to endorse or promote products derived from
25// this software without specific prior written permission.
26//
27// THIS SOFTWARE IS PROVIDED BY NTESS "AS IS" AND ANY EXPRESS OR IMPLIED
28// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
29// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
30// NO EVENT SHALL NTESS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
32// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37//
38// Questions? Contact David Littlewood (djlittl@sandia.gov)
39//
40// ************************************************************************
41//@HEADER
42*/
43
44#ifndef NIMBLE_MACROS_H
45#define NIMBLE_MACROS_H
46
47#include <iostream> // For std::cerr
48
49#define NIMBLE_ASSERT_IMPL(cond, msg, ...) \
50 do { \
51 if (!(cond)) { \
52 std::cerr << #cond " NIMBLE_ASSERT failed at "; \
53 std::cerr << __FILE__ << " +" << __LINE__ << "\n" << msg << '\n'; \
54 abort(); \
55 } \
56 } while (0)
57
58#define NIMBLE_PANIC_IMPL(cond, msg, ...) \
59 do { \
60 if ((cond)) { \
61 std::cerr << #cond " NIMBLE_PANIC condition at "; \
62 std::cerr << __FILE__ << " +" << __LINE__ << "\n" << msg << '\n'; \
63 abort(); \
64 } \
65 } while (0)
66
67#define NIMBLE_ABORT_IMPL(msg, ...) \
68 do { \
69 std::cerr << " NIMBLE_ABORT statement at "; \
70 std::cerr << __FILE__ << " +" << __LINE__ << "\n" << msg << '\n'; \
71 abort(); \
72 } while (0)
73
74#define NIMBLE_TRACE_IMPL(msg, ...) \
75 do { \
76 std::cerr << "********** NIMBLE_TRACE at "; \
77 std::cerr << __FILE__ << " +" << __LINE__ << "\n" << msg << '\n'; \
78 } while (0)
79
80#define NIMBLE_DUMP_IMPL(msg, ...) \
81 do { \
82 std::cerr << msg; \
83 } while (0)
84
85#define NIMBLE_ASSERT(...) NIMBLE_ASSERT_IMPL(__VA_ARGS__, "")
86#define NIMBLE_PANIC(...) NIMBLE_PANIC_IMPL(__VA_ARGS__, "")
87#define NIMBLE_ABORT(...) NIMBLE_ABORT_IMPL(__VA_ARGS__, "")
88#define NIMBLE_TRACE(...) NIMBLE_TRACE_IMPL(__VA_ARGS__, "")
89#define NIMBLE_DUMP(...) NIMBLE_DUMP_IMPL(__VA_ARGS__, "")
90
91#ifndef NIMBLE_DEBUG
92#define NIMBLE_EXPECT(...)
93#else
94#define NIMBLE_EXPECT(...) NIMBLE_ASSERT(__VA_ARGS__)
95#endif
96
97#define NIMBLE_ALWAYS_ASSERT(cond) NIMBLE_ASSERT(cond)
98#define NIMBLE_ALWAYS_ASSERT_VERBOSE(cond, msg) NIMBLE_ASSERT(cond, msg)
99#define NIMBLE_DEBUG_ASSERT(cond) NIMBLE_EXPECT(cond)
100#define NIMBLE_DEBUG_ASSERT_VERBOSE(cond, msg) NIMBLE_EXPECT(cond, msg)
101
102#endif // NIMBLE_MACROS_H