BOSS 6.6.4.p01
BESIII Offline Software System
Loading...
Searching...
No Matches
Event/ers/ers-00-00-02/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
19namespace {
20 ers::Issue *create_issue() { return new ers::Assertion(); }
22}
23
24/** Key for assertion condition description
25 */
26
27const char * const ers::Assertion::ASSERT_CONDITION_KEY = "ASSERTION_CONDITION" ;
28const char * const ers::Assertion::CLASS_NAME = "ers::Assertion" ;
29const char * const ers::Assertion::MESSAGE_ELEMENTS[] = { "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, 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
56void 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
64const 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
76std::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
XmlRpcServer s
Definition: HelloServer.cpp:11
This Issue represents a basic assertion.
static const char *const CLASS_NAME
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)
static const char *const MESSAGE_ELEMENTS[]
static const char *const ASSERT_CONDITION_KEY
Source context for Issue.
Definition: Context.h:42
bool register_issue(const std::string &name, CreateIssueCallback creator)
register an issue factory
static IssueFactory * instance()
method to access singleton
Root Issue class.
@ resp_server
Definition: Core.h:25
enum ers::_severity_t severity_t