BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
Event/ers/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#include <iostream>
11#include <sstream>
12#include <sysexits.h>
13
14#include "ers/Assertion.h"
15#include "ers/Issue.h"
16
17namespace {
18 ers::Issue* create_issue() { return new ers::Assertion(); }
20 create_issue );
21} // namespace
22
23/** Key for assertion condition description
24 */
25
26const char* const ers::Assertion::ASSERT_CONDITION_KEY = "ASSERTION_CONDITION";
27const char* const ers::Assertion::CLASS_NAME = "ers::Assertion";
28const char* const ers::Assertion::MESSAGE_ELEMENTS[] = {
29 "Assertion '", "' failed: ", " (this condition is constant)" };
30
31/** Empty constructor for deserialisation / factory
32 */
33
35
36/** Constructor for subclasses
37 */
38
39ers::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
49ers::Assertion::Assertion( const Context& context, severity_t s, const char* condition_text,
50 const std::string& msg, bool constant_expression )
51 : Issue( context, s ) {
52 setup( condition_text, msg, constant_expression );
53} // Assertion
54
55/** Setup method, should be called at the end of the constructor by class and subclasses
56 */
57
58void ers::Assertion::setup( const char* condition_text, const std::string& msg,
59 bool constant_expression ) {
60 m_value_table[ASSERT_CONDITION_KEY] = *condition_text;
62 set_value( EXIT_VALUE_KEY, EX_SOFTWARE );
63 transience( !constant_expression );
64 finish_setup( build_message( condition_text, msg, constant_expression ) );
65} // setup
66
67const char* ers::Assertion::get_class_name() const throw() {
68 return CLASS_NAME;
69} // get_class_name
70
71/** Builds the message associated with an assertion
72 * \return message describing the failure of the assertion
73 * \param condition_text the condition in textual form
74 * \param msg the message associated with the condition
75 * \param constant_expression is the assertion a constant expression as detected by the
76 * compiler. \return an human readable message
77 */
78
79std::string ers::Assertion::build_message( const char* condition_text, const std::string& msg,
80 bool constant_expression ) throw() {
81 std::ostringstream m;
82 m << MESSAGE_ELEMENTS[0] << condition_text << MESSAGE_ELEMENTS[1] << msg;
83 if ( constant_expression ) { m << MESSAGE_ELEMENTS[2]; } // constant expression
84 return m.str();
85} // build_message
XmlRpcServer s
This Issue represents a basic assertion.
static const char *const MESSAGE_ELEMENTS[]
static const char *const CLASS_NAME
static const char *const ASSERT_CONDITION_KEY
void setup(const char *condition, const std::string &message, bool constant_expression)
virtual const char * get_class_name() const
Get key for class (used for serialisation).
virtual std::string build_message(const char *condition_text, const std::string &msg, bool constant_expression=false)
Source context for Issue.
bool register_issue(const std::string &name, CreateIssueCallback creator)
register an issue factory
static IssueFactory * instance()
method to access singleton
Root Issue class.
void set_value(const std::string &key, uint8_t value)
Sets a value 8 bit unsigned.
void finish_setup(const std::string &message)
Finishes the setup of the Issue.
void transience(bool tr)
sets if the issue is transient
Issue(const Context &context, severity_t s)
Constructor for subclasses.
static const char *const EXIT_VALUE_KEY
key used to store the exit value
void responsibility(responsibility_t r)
set the responsability of the issue
string_map_type m_value_table
Optional properties.
enum ers::_severity_t severity_t