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 *package, 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.package = package;
74 msg.file = file;
75 msg.line = line;
77
78 std::string mymessage = typeLiteral[type];
79 mymessage += ": ";
80 mymessage += error;
81 msg.message = mymessage.c_str();
82
83 msg.send();
84 }
85
86
87
88 TestInvariant ::
89 TestInvariant (TestInvariantFunction function,
90 const void *object)
91 : m_function (function), m_object (object)
92 {
93 (*m_function) (m_object);
94 }
95
96
97
98 TestInvariant ::
99 ~TestInvariant ()
100 {
101 (*m_function) (m_object);
102 }
103
104
105
107 const void *object)
108 {
109 try
110 {
111 (*function) (object);
112 return false;
113 } catch (std::exception& e)
114 {
115 RCU_ERROR_MSG (e.what());
116 return true;
117 };
118 }
119 }
120}
#define RCU_REQUIRE(x)
Definition Assert.h:203
#define RCU_ERROR_MSG(message)
Definition PrintMsg.h:50
const bool typeAbort[typeNum]
Definition Assert.cxx:45
const int typeNum
Definition Assert.h:70
void fail(const char *package, 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
bool testInvariantPrint(TestInvariantFunction function, const void *object)
Definition Assert.cxx:106
void(* TestInvariantFunction)(const void *object)
effects: apply the test invariant method on an object guarantee: no-fail availability: experts only r...
Definition Assert.h:93
const char *const typeLiteral[typeNum]
Definition Assert.cxx:26
This module defines a variety of assert style macros.
Definition Assert.cxx:23
@ MESSAGE_ABORT
description: print and abort
Definition MessageType.h:33
@ MESSAGE_EXCEPTION
description: send out an exception
Definition MessageType.h:30
const void * m_object
Definition Assert.h:114
TestInvariantFunction m_function
Definition Assert.h:113
MsgStream & msg
Definition testRead.cxx:32
TFile * file