BOSS
7.0.8
BESIII Offline Software System
Loading...
Searching...
No Matches
Event/ers/ers-00-00-03/ers/Assertion.h
Go to the documentation of this file.
1
/*
2
* Assertion.h
3
* ers
4
*
5
* Created by Matthias Wiesmann on 26.11.04.
6
* Copyright 2004 CERN. All rights reserved.
7
*
8
*/
9
10
/** \file Assertion.h
11
* This file defines the assertion class and the associated macros.
12
*/
13
14
#ifndef ERS_ASSERTION
15
#define ERS_ASSERTION
16
17
#include <stdio.h>
18
#include "
ers/Issue.h
"
19
20
namespace
ers
{
21
22
/** This class represents an assertion in the code, it is an issue with two fields:
23
* \li A condition
24
* \li A message describing the condition
25
*
26
* If the condition is not verified, an Issue is trown.
27
* \author Matthias Wiesmann
28
* \version 1.0
29
* \brief This Issue represents a basic assertion
30
*/
31
32
class
Assertion
:
public
ers::Issue
{
33
protected
:
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
[] ;
38
public
:
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
53
template <
bool
> struct
Compile_time_error
;
54
55
/** \brief compile time error structure */
56
57
template<> 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
true
#define true
Definition:
BesCxxPolicy/BesCxxPolicy-00-01-01/CxxFeatures/config.h:19
false
#define false
Definition:
BesCxxPolicy/BesCxxPolicy-00-01-01/CxxFeatures/config.h:22
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:37
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::Issue
Root Issue class.
Definition:
ers/ers-00-00-03/ers/Issue.h:40
ers::Issue::message
const std::string & message() const
Message.
Definition:
ers/ers-00-00-03/src/Issue.cxx:689
Issue.h
ers
Definition:
Event/ers/ers-00-00-03/ers/Assertion.h:20
ers::severity_t
enum ers::_severity_t severity_t
std
Definition:
RootEventData_rootcint.cxx:16
ers::Compile_time_error
compile time error structure.
Definition:
Event/ers/ers-00-00-03/ers/Assertion.h:53
source
Event
ers
ers-00-00-03
ers
Assertion.h
Generated by
1.9.6