ATLAS Offline Software
Loading...
Searching...
No Matches
Assert.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7//
8// includes
9//
10
12
13#include <cstdlib>
14#include <string>
17
18//
19// method implementations
20//
21
22namespace RCU
23{
24 namespace Check
25 {
26 const char * const typeLiteral [typeNum] =
27 {
28 "assertion failed",
29 "assertion failed",
30 "assertion failed",
31
32 "requirement failed",
33 "requirement failed",
34 "requirement failed",
35
36 "postcondition violated",
37 "postcondition violated",
38 "postcondition violated",
39
40 "invariant violated"
41 };
42
43
44
45 const bool typeAbort [typeNum] =
46 {
47 false,
48 true,
49 true,
50
51 false,
52 true,
53 true,
54
55 false,
56 true,
57 true,
58
59 true,
60 };
61
62
63
64 void fail (const char *file, unsigned line,
65 Type type, const char *error)
66 {
67 RCU_REQUIRE (file != 0);
68 RCU_REQUIRE (line != 0);
70 RCU_REQUIRE (error != 0);
71
73 msg.file = file;
74 msg.line = line;
76
77 std::string mymessage = typeLiteral[type];
78 mymessage += ": ";
79 mymessage += error;
80 msg.message = mymessage.c_str();
81
82 msg.send();
83 }
84
85
86
87 TestInvariant ::
88 TestInvariant (TestInvariantFunction function,
89 const void *object)
90 : m_function (function), m_object (object)
91 {
92 (*m_function) (m_object);
93 }
94
95
96
97 TestInvariant ::
98 ~TestInvariant ()
99 {
100 (*m_function) (m_object);
101 }
102
103
104
106 const void *object)
107 {
108 using namespace msgRootCoreUtils;
109
110 try
111 {
112 (*function) (object);
113 return false;
114 } catch (std::exception& e)
115 {
116 ANA_MSG_ERROR ("caught exception in invariant test: " << e.what());
117 return true;
118 };
119 }
120 }
121}
#define RCU_REQUIRE(x)
Definition Assert.h:196
#define ANA_MSG_ERROR(xmsg,...)
Macro printing error messages.
const bool typeAbort[typeNum]
Definition Assert.cxx:45
const int typeNum
Definition Assert.h:67
bool testInvariantPrint(TestInvariantFunction function, const void *object)
Definition Assert.cxx:105
void(* TestInvariantFunction)(const void *object)
effects: apply the test invariant method on an object guarantee: no-fail availability: experts only r...
Definition Assert.h:90
const char *const typeLiteral[typeNum]
Definition Assert.cxx:26
void fail(const char *file, unsigned line, Type type, const char *error)
effects: report the error and abort either by exception or assert like guarantee: all-fail failures: ...
Definition Assert.cxx:64
This module defines a variety of assert style macros.
Definition Assert.cxx:23
@ MESSAGE_ABORT
description: print and abort
Definition MessageType.h:31
@ MESSAGE_EXCEPTION
description: send out an exception
Definition MessageType.h:28
const void * m_object
Definition Assert.h:111
TestInvariantFunction m_function
Definition Assert.h:110
MsgStream & msg
Definition testRead.cxx:32
TFile * file