BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
Event/ers/include/ers/Precondition.h
Go to the documentation of this file.
1/*
2 * Precondition.h
3 * ers
4 *
5 * Created by Matthias Wiesmann on 08.12.04.
6 * Copyright 2004 CERN. All rights reserved.
7 *
8 */
9
10#ifndef ERS_PRECONDITION
11
12# include "ers/Assertion.h"
13# include <stdio.h>
14
15namespace ers {
16
17 /** A precondition is a special type of assertion that checks the entry condition for a
18 * function. Typically, precondition check entry values for function, and members state in
19 * object methods \author Matthias Wiesmann \version 1.0 \brief Precondition issue.
20 */
21
22 class Precondition : public Assertion {
23 protected:
24 virtual std::string build_message( const char* condition_text, const std::string& message,
25 bool constant_expression = false ) throw();
26 Precondition( const Context& context, severity_t s );
27
28 public:
29 static const char* const PRECONDITION_CLASS;
31 Precondition( const Context& context, severity_t s, const char* condition,
32 const std::string& message, bool constant_expression = false );
33 virtual const char* get_class_name() const throw();
34 }; // Precondition
35} // namespace ers
36
37/** \def ERS_PRECONDITION(expr,msg,params) This macro inserts an assertion than checks
38 * condition e, if e is not true, then an issue of type ers::Asertion is thrown with message m.
39 * If the compiler is gcc, then the transient field of the assertion is set according to the
40 * transcience of the expression. This means that if the expression is detected by the compiler
41 * as being constant. If the macro \c N_DEBUG is defined then the macros are disabled.
42 */
43
44# ifndef N_ERS_ASSERT
45# ifdef __GNUC__
46# define ERS_PRECONDITION( expr, ... ) \
47 { \
48 if ( !( expr ) ) \
49 { \
50 char precondition_buffer[256]; \
51 snprintf( precondition_buffer, 256, __VA_ARGS__ ); \
52 ers::Precondition failed_precondition( ERS_HERE, ers::error, #expr, \
53 precondition_buffer, \
54 __builtin_constant_p( expr ) ); \
55 throw failed_precondition; \
56 } \
57 }
58# else
59# define ERS_PRECONDITION( expr, ... ) \
60 { \
61 if ( !( expr ) ) \
62 { \
63 char precondition_buffer[256]; \
64 snprintf( precondition_buffer, 256, __VA_ARGS__ ); \
65 ers::Precondition failed_precondition( ERS_HERE, ers::error, #expr, \
66 precondition_buffer, false ); \
67 throw failed_precondition; \
68 } \
69 }
70# endif
71# else
72# define ERS_PRECONDITION( expr, ... )
73# endif
74
75#endif
XmlRpcServer s
Assertion(const Context &context, severity_t s)
Source context for Issue.
const std::string & message() const
Message.
virtual std::string build_message(const char *condition_text, const std::string &message, bool constant_expression=false)
virtual const char * get_class_name() const
Precondition(const Context &context, severity_t s)
static const char *const PRECONDITION_CLASS
enum ers::_severity_t severity_t