CGEM BOSS 6.6.5.i
BESIII Offline Software System
Loading...
Searching...
No Matches
ers::Assertion Class Reference

This Issue represents a basic assertion. More...

#include <Assertion.h>

+ Inheritance diagram for ers::Assertion:

Public Member Functions

virtual const char * get_class_name () const throw ()
 Get key for class (used for serialisation)
 
 Assertion ()
 
 Assertion (const Context &context, severity_t s, const char *condition, const std::string &message, bool constant_expression=false)
 
- Public Member Functions inherited from ers::Issue
 Issue ()
 
 Issue (const Issue &issue)
 
 Issue (const string_map_type &values)
 
 Issue (const Context &context, severity_t s, const std::string &message)
 
 Issue (const Context &context, severity_t s, const std::exception *cause)
 
virtual ~Issue () throw ()
 
Issueclone () const
 
const Issuecause () const throw ()
 return the cause Issue of this Issue
 
void cause (const std::exception *cause=0)
 Initialises the cause field.
 
 operator std::string () const
 Converts the issue into a string.
 
Issue operator= (const Issue &issue)
 Affectation operator.
 
bool operator== (const Issue &other) const throw ()
 Equality operator.
 
const std::string & operator[] (const std::string &key) const throw ()
 
const std::string & get_value (const std::string &key, const std::string &def) const throw ()
 Reads the property list.
 
const std::string & get_value (const std::string &key) const throw ()
 
int get_int_value (const std::string &key, int def=0) const throw ()
 Get a value of the table as an integer.
 
long get_long_value (const std::string &key, long def=0) const throw ()
 Get a value of the table as a long integer.
 
double get_double_value (const std::string key, double def) const throw ()
 Get a value of the table as double.
 
void set_value (const std::string &key, uint8_t value) throw ()
 Sets a value 8 bit unsigned.
 
void set_value (const std::string &key, uint16_t value) throw ()
 
void set_value (const std::string &key, uint32_t value) throw ()
 
void set_value (const std::string &key, uint64_t value) throw ()
 
void set_value (const std::string &key, int8_t value) throw ()
 
void set_value (const std::string &key, int16_t value) throw ()
 
void set_value (const std::string &key, int32_t value) throw ()
 
void set_value (const std::string &key, int64_t value) throw ()
 
void set_value (const std::string &key, double value) throw ()
 Sets a value (double float)
 
void set_value (const std::string &key, const std::string &value) throw ()
 Sets a value (string)
 
void set_value (const std::string &key, const char *value) throw ()
 Sets a value (c-string)
 
void set_value (const std::string &key, const void *ptr) throw ()
 
int values_number () const
 How many key / values.
 
const string_map_typeget_value_table () const
 extract value table
 
severity_t severity () const throw ()
 severity_t of the issue
 
void severity (severity_t s)
 sets the severity_t of the issue
 
bool is_error ()
 is the issue an error (or fatal).
 
std::string severity_message () const
 message associated with the severity_t of the issue
 
void responsibility (responsibility_t r)
 set the responsability of the issue
 
responsibility_t responsibility () const throw ()
 get the responsability level of the issue
 
void transience (bool tr)
 sets if the issue is transient
 
int transience () const throw ()
 is the issue transient
 
const std::string & human_description () const throw ()
 Human description message.
 
const char * what () const throw ()
 Human description message.
 
const std::string & message () const throw ()
 Message.
 
virtual int exit_value () const throw ()
 value to pass to exit
 
void add_qualifier (const std::string &qualif)
 adds a qualifier to the issue
 
std::vector< std::string > qualifiers () const
 return array of qualifiers
 

Static Public Attributes

static const char *const ASSERT_CONDITION_KEY = "ASSERTION_CONDITION"
 
static const char *const CLASS_NAME = "ers::Assertion"
 
- Static Public Attributes inherited from ers::Issue
static const char *const CLASS_KEY = "ISSUE_CLASS"
 key for class information
 
static const char *const COMPILATION_TIME_KEY = "COMPILATION_TIME"
 key for compilation time
 
static const char *const COMPILATION_TARGET_KEY = "COMPILATION_TARGET"
 key for compilation target
 
static const char *const COMPILER_KEY = "COMPILER"
 key for compilator type
 
static const char *const COMPILATION_DEBUG_LVL_KEY = "COMPILATION_DEBUG_LVL"
 
static const char *const CPP_CLASS_KEY = "ISSUE_CPP_CLASS"
 key for c++ class (might be mangled)
 
static const char *const ERS_VERSION_KEY = "ERS_VERSION"
 key for ERS version
 
static const char *const HOST_NAME_KEY = "HOST_NAME"
 key for hostname
 
static const char *const HOST_TYPE_KEY = "HOST_TYPE"
 key for host type (architecture / os)
 
static const char *const HOST_IP_ADDR_KEY = "HOST_IP"
 key for host ip address
 
static const char *const MESSAGE_KEY = "MESSAGE"
 key for human readable
 
static const char *const PROCESS_ID_KEY = "PROCESS_ID"
 key for the process id (number)
 
static const char *const PROCESS_PWD_KEY = "PROCESS_PWD"
 key for the process working directory
 
static const char *const PROGRAM_NAME_KEY = "PROGRAM_NAME"
 key for the name of the program
 
static const char *const RESPONSIBILITY_KEY = "RESPONSIBILITY"
 key for the responsibility of the issue (text)
 
static const char *const SEVERITY_KEY = "SEVERITY"
 key for the severity_t of the issue
 
static const char *const SOURCE_POSITION_KEY = "SOURCE_POSITION"
 key for position in the source code
 
static const char *const SOURCE_PACKAGE_KEY = "SOURCE_PACKAGE"
 package name associated with source code
 
static const char *const TIME_KEY = "TIME"
 key for the time of the issue (text)
 
static const char *const TRANSIENCE_KEY = "TRANSIENCE"
 key for the transience of the issue (text)
 
static const char *const USER_ID_KEY = "USER_ID"
 key for the user-id of the owner of the process
 
static const char *const USER_NAME_KEY = "USER_NAME"
 key for the user-name of the owner of the process
 
static const char *const CAUSE_PSEUDO_KEY = "CAUSE"
 key used when serializing the cause issue, this key is not used in the value table
 
static const char *const CAUSE_TEXT_KEY = "CAUSE_TEXT"
 key used to store the cause issue's message
 
static const char *const QUALIFIER_LIST_KEY = "QUALIFIERS"
 key used to store the qualifier list
 
static const char *const EXIT_VALUE_KEY = "EXIT_VALUE"
 key used to store the exit value
 
static const char *const ISSUE_CLASS_NAME = "ers::issue"
 name of the class, used for serialisation
 

Protected Member Functions

virtual std::string build_message (const char *condition_text, const std::string &msg, bool constant_expression=false) throw ()
 
 Assertion (const Context &context, severity_t s)
 
void setup (const char *condition, const std::string &message, bool constant_expression)
 
- Protected Member Functions inherited from ers::Issue
void insert (const Context *context) throw ()
 Inserts the context.
 
void insert_time () throw ()
 Inserts current time.
 
void setup_common (const Context *context) throw ()
 Sets up the common fields.
 
void finish_setup (const std::string &message) throw ()
 Finishes the setup of the Issue.
 
 Issue (const Context &context, severity_t s)
 Constructor for subclasses.
 
void set_values (const string_map_type &values) throw ()
 sets the value table
 

Static Protected Attributes

static const char *const MESSAGE_ELEMENTS [] = { "Assertion '", "' failed: ", " (this condition is constant)" }
 

Additional Inherited Members

- Protected Attributes inherited from ers::Issue
Issuem_cause
 Issue that caused the current issue.
 
std::string m_class_name
 class name
 
std::string m_human_description
 Human readable description (cache)
 
string_map_type m_value_table
 Optional properties.
 

Detailed Description

This Issue represents a basic assertion.

This class represents an assertion in the code, it is an issue with two fields:

  • A condition
  • A message describing the condition

If the condition is not verified, an Issue is trown.

Author
Matthias Wiesmann
Version
1.0

Definition at line 32 of file Event/ers/ers-00-00-03/ers/Assertion.h.

Constructor & Destructor Documentation

◆ Assertion() [1/3]

ers::Assertion::Assertion ( const Context & context,
severity_t s )
protected

Constructor for subclasses

Definition at line 39 of file Event/ers/ers-00-00-03/src/Assertion.cxx.

39: Issue(context,s) {}
XmlRpcServer s

◆ Assertion() [2/3]

ers::Assertion::Assertion ( )

Empty constructor for deserialisation / factory

Definition at line 34 of file Event/ers/ers-00-00-03/src/Assertion.cxx.

34: Issue() {}

◆ Assertion() [3/3]

ers::Assertion::Assertion ( const Context & context,
severity_t s,
const char * condition_text,
const std::string & msg,
bool constant_expression = false )

Constructor

Parameters
condition_textthe text of the assertion's condition
msgmessage describing the assertion's condition
sseverity_t of the assertion
contextposition in the code where the assertion failed, should be the MRS_HERE macro
constant_expressionis the expression constant (as detected by the compiler).

Definition at line 49 of file Event/ers/ers-00-00-03/src/Assertion.cxx.

49 : Issue(context,s) {
50 setup(condition_text,msg,constant_expression);
51} // Assertion
void setup(const char *condition, const std::string &message, bool constant_expression)

Member Function Documentation

◆ build_message()

std::string ers::Assertion::build_message ( const char * condition_text,
const std::string & msg,
bool constant_expression = false )
throw ( )
protectedvirtual

Builds the message associated with an assertion

Returns
message describing the failure of the assertion
Parameters
condition_textthe condition in textual form
msgthe message associated with the condition
constant_expressionis the assertion a constant expression as detected by the compiler.
Returns
an human readable message

Reimplemented in ers::NotImplemented, and ers::Precondition.

Definition at line 76 of file Event/ers/ers-00-00-03/src/Assertion.cxx.

76 {
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
static const char *const MESSAGE_ELEMENTS[]

◆ get_class_name()

const char * ers::Assertion::get_class_name ( ) const
throw ( )
virtual

Get key for class (used for serialisation)

Returns the key used to describe this particular class when serializing This method tries to build a meaningfull class name out of C++ RTTI. This depends on the compiler providing information in a format similar to gcc. For more safety. If the gcc unmangling fails the default (ers::Issue) is used.

Reimplemented from ers::Issue.

Reimplemented in ers::NotImplemented, and ers::Precondition.

Definition at line 64 of file Event/ers/ers-00-00-03/src/Assertion.cxx.

64 {
65 return CLASS_NAME ;
66} // get_class_name
static const char *const CLASS_NAME

◆ setup()

void ers::Assertion::setup ( const char * condition_text,
const std::string & msg,
bool constant_expression )
protected

Setup method, should be called at the end of the constructor by class and subclasses

Definition at line 56 of file Event/ers/ers-00-00-03/src/Assertion.cxx.

56 {
57 m_value_table[ASSERT_CONDITION_KEY] = *condition_text ;
59 set_value(EXIT_VALUE_KEY,EX_SOFTWARE);
60 transience( ! constant_expression);
61 finish_setup(build_message(condition_text,msg,constant_expression));
62} // setup
virtual std::string build_message(const char *condition_text, const std::string &msg, bool constant_expression=false)
static const char *const ASSERT_CONDITION_KEY
responsibility_t responsibility() const
get the responsability level of the issue
void set_value(const std::string &key, uint8_t value)
Sets a value 8 bit unsigned.
static const char *const EXIT_VALUE_KEY
key used to store the exit value
void finish_setup(const std::string &message)
Finishes the setup of the Issue.
int transience() const
is the issue transient
string_map_type m_value_table
Optional properties.
@ resp_server
Definition Core.h:25

Referenced by Assertion(), ers::NotImplemented::NotImplemented(), and ers::Precondition::Precondition().

Member Data Documentation

◆ ASSERT_CONDITION_KEY

const char *const ers::Assertion::ASSERT_CONDITION_KEY = "ASSERTION_CONDITION"
static

Key for assertion condition description

Definition at line 39 of file Event/ers/ers-00-00-03/ers/Assertion.h.

◆ CLASS_NAME

const char *const ers::Assertion::CLASS_NAME = "ers::Assertion"
static

Definition at line 40 of file Event/ers/ers-00-00-03/ers/Assertion.h.

◆ MESSAGE_ELEMENTS

const char *const ers::Assertion::MESSAGE_ELEMENTS = { "Assertion '", "' failed: ", " (this condition is constant)" }
staticprotected

Definition at line 29 of file Event/ers/ers-00-00-03/ers/Assertion.h.

32: public ers::Issue {
33protected:
34 virtual std::string build_message(const char* condition_text, const std::string &msg, bool constant_expression=false) throw() ;
35 Assertion(const Context &context, severity_t s);
36 void setup(const char *condition, const std::string &message, bool constant_expression);
37 static const char* const MESSAGE_ELEMENTS[] ;
38public:
39 static const char* const ASSERT_CONDITION_KEY ;
40 static const char* const CLASS_NAME ;
41
42 virtual const char*get_class_name() const throw() ;
43 Assertion();
44 Assertion(const Context &context, severity_t s, const char*condition, const std::string &message, bool constant_expression=false) ;
45} ;
46
47/** This structure is simply used to trigger compile-time assertion errors
48 * The \c true template instanciation is implemented, but not the false, this means that if the template
49 * is instanciated with \c false, we get a compile-time error.
50 * \brief compile time error structure.
51 */
52
53template <bool> struct Compile_time_error ;
54
55/** \brief compile time error structure */
56
57template<> struct Compile_time_error<true> { };
58
59} // ers
60
61
62
63/** \def ERS_STATIC_ASSERT(expr) This macro inserts a compile-time assertion into the code.
64 * Compile time assertion can only be done on constant factors (i.e compile-time known quantities).
65 *
66 */
67
68#ifndef N_ERS_STATIC_ASSERT
69#define ERS_STATIC_ASSERT(expr) { ers::Compile_time_error <((expr) != 0)> ERROR_ASSERTION_FAILED ; (void) ERROR_ASSERTION_FAILED ; }
70#else
71#define ERS_STATIC_ASSERT(expr)
72#endif
73
74
75/** \def ERS_ASSERT(expr,msg,...) This macro inserts an assertion than checks condition e,
76 * if e is not true, then an issue of type ers::Asertion is thrown with message msg.
77 * The msg is actually a formatting string, like printf, that can be used with subsequent parameters.
78 * If the compiler is gcc, then the transient field of the assertion is set according to the transcience of the expression.
79 * This means that if the expression is detected by the compiler as being constant,
80 * \note This macro is disabled if the \c N_ERS_ASSERT macro is defined
81 */
82#ifndef N_ERS_ASSERT
83#ifdef __GNUC__
84#define ERS_ASSERT(expr,...) { if(!(expr)) { char assertion_buffer[256] ; snprintf(assertion_buffer,sizeof(assertion_buffer), __VA_ARGS__) ; ers::Assertion failed_assertion(ERS_HERE, ers::error, #expr,assertion_buffer,__builtin_constant_p(expr)) ; throw failed_assertion ; } }
85#else
86#define ERS_ASSERT(expr,...) { if(!(expr)) { char assertion_buffer[256] ; snprintf(assertion_buffer,sizeof(assertion_buffer), __VA_ARGS__) ; ers::Assertion failed_assertion(ERS_HERE, ers::error,#expr,assertion_buffer,false) ; throw failed_assertion ; } }
87#endif
88#else
89#define ERS_ASSERT(expr,...) ((void) (expr))
90#endif
91
92#endif
93
virtual const char * get_class_name() const
Get key for class (used for serialisation)
Root Issue class.
const std::string & message() const
Message.
enum ers::_severity_t severity_t

The documentation for this class was generated from the following files: