BOSS
7.1.1
BESIII Offline Software System
Loading...
Searching...
No Matches
Event/ers/ers-00-00-03/src/Assertion.cxx
Go to the documentation of this file.
1
/*
2
* Assertion.cxx
3
* ers
4
*
5
* Created by Matthias Wiesmann on 26.11.04.
6
* Copyright 2004 CERN. All rights reserved.
7
*
8
*/
9
10
11
#include <iostream>
12
#include <sstream>
13
#include <sysexits.h>
14
15
#include "
ers/Assertion.h
"
16
#include "
ers/Issue.h
"
17
18
19
namespace
{
20
ers::Issue
*create_issue() {
return
new
ers::Assertion
(); }
21
bool
registered =
ers::IssueFactory::instance
()->
register_issue
(
ers::Assertion::CLASS_NAME
,create_issue) ;
22
}
23
24
/** Key for assertion condition description
25
*/
26
27
const
char
*
const
ers::Assertion::ASSERT_CONDITION_KEY
=
"ASSERTION_CONDITION"
;
28
const
char
*
const
ers::Assertion::CLASS_NAME
=
"ers::Assertion"
;
29
const
char
*
const
ers::Assertion::MESSAGE_ELEMENTS
[] = {
"Assertion '"
,
"' failed: "
,
" (this condition is constant)"
} ;
30
31
/** Empty constructor for deserialisation / factory
32
*/
33
34
ers::Assertion::Assertion
() :
Issue
() {}
35
36
/** Constructor for subclasses
37
*/
38
39
ers::Assertion::Assertion
(
const
Context
&context,
severity_t
s
) :
Issue
(context,
s
) {}
40
41
/** Constructor
42
* \param condition_text the text of the assertion's condition
43
* \param msg message describing the assertion's condition
44
* \param s severity_t of the assertion
45
* \param context position in the code where the assertion failed, should be the MRS_HERE macro
46
* \param constant_expression is the expression constant (as detected by the compiler).
47
*/
48
49
ers::Assertion::Assertion
(
const
Context
&context,
severity_t
s
,
const
char
* condition_text,
const
std::string &msg,
bool
constant_expression) :
Issue
(context,
s
) {
50
setup
(condition_text,msg,constant_expression);
51
}
// Assertion
52
53
/** Setup method, should be called at the end of the constructor by class and subclasses
54
*/
55
56
void
ers::Assertion::setup
(
const
char
*condition_text,
const
std::string &msg,
bool
constant_expression) {
57
m_value_table[ASSERT_CONDITION_KEY] = *condition_text ;
58
responsibility(
resp_server
);
59
set_value(EXIT_VALUE_KEY,EX_SOFTWARE);
60
transience( ! constant_expression);
61
finish_setup(build_message(condition_text,msg,constant_expression));
62
}
// setup
63
64
const
char
*
ers::Assertion::get_class_name
()
const
throw (){
65
return
CLASS_NAME ;
66
}
// get_class_name
67
68
/** Builds the message associated with an assertion
69
* \return message describing the failure of the assertion
70
* \param condition_text the condition in textual form
71
* \param msg the message associated with the condition
72
* \param constant_expression is the assertion a constant expression as detected by the compiler.
73
* \return an human readable message
74
*/
75
76
std::string
ers::Assertion::build_message
(
const
char
* condition_text,
const
std::string &msg,
bool
constant_expression)
throw
() {
77
std::ostringstream m ;
78
m << MESSAGE_ELEMENTS[0] << condition_text << MESSAGE_ELEMENTS[1] << msg ;
79
if
(constant_expression) {
80
m << MESSAGE_ELEMENTS[2] ;
81
}
// constant expression
82
return
m.str();
83
}
// build_message
84
Assertion.h
s
XmlRpcServer s
Definition
HelloServer.cpp:11
ers::Assertion
This Issue represents a basic assertion.
Definition
Event/ers/ers-00-00-03/ers/Assertion.h:32
ers::Assertion::CLASS_NAME
static const char *const CLASS_NAME
Definition
Event/ers/ers-00-00-03/ers/Assertion.h:40
ers::Assertion::setup
void setup(const char *condition, const std::string &message, bool constant_expression)
Definition
Event/ers/ers-00-00-03/src/Assertion.cxx:56
ers::Assertion::get_class_name
virtual const char * get_class_name() const
Get key for class (used for serialisation)
Definition
Event/ers/ers-00-00-03/src/Assertion.cxx:64
ers::Assertion::Assertion
Assertion()
Definition
Event/ers/ers-00-00-03/src/Assertion.cxx:34
ers::Assertion::build_message
virtual std::string build_message(const char *condition_text, const std::string &msg, bool constant_expression=false)
Definition
Event/ers/ers-00-00-03/src/Assertion.cxx:76
ers::Assertion::MESSAGE_ELEMENTS
static const char *const MESSAGE_ELEMENTS[]
Definition
Event/ers/ers-00-00-03/ers/Assertion.h:29
ers::Assertion::ASSERT_CONDITION_KEY
static const char *const ASSERT_CONDITION_KEY
Definition
Event/ers/ers-00-00-03/ers/Assertion.h:39
ers::Context
Source context for Issue.
Definition
Context.h:42
ers::IssueFactory::register_issue
bool register_issue(const std::string &name, CreateIssueCallback creator)
register an issue factory
Definition
IssueFactory.cxx:47
ers::IssueFactory::instance
static IssueFactory * instance()
method to access singleton
Definition
IssueFactory.cxx:28
ers::Issue
Root Issue class.
Definition
ers/ers-00-00-03/ers/Issue.h:40
Issue.h
ers::resp_server
@ resp_server
Definition
Core.h:25
ers::severity_t
enum ers::_severity_t severity_t
7.1.1
Event
ers
ers-00-00-03
src
Assertion.cxx
Generated by
1.12.0