Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v29r3 (fa547fc2)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
StatusCode Class Referencefinal

This class is used for returning status codes from appropriate routines. More...

#include <GaudiKernel/StatusCode.h>

Classes

class  ScopedDisableChecking
 Simple RAII class to ignore unchecked StatusCode instances in a scope. More...
 

Public Types

enum  { FAILURE = 0, SUCCESS = 1, RECOVERABLE = 2 }
 

Public Member Functions

 StatusCode ()=default
 Constructor. More...
 
 StatusCode (unsigned long code, bool checked=false)
 
 StatusCode (const StatusCode &rhs)
 
 StatusCode (StatusCode &&rhs) noexcept
 Move constructor. More...
 
 ~StatusCode ()
 Destructor. More...
 
bool isSuccess () const
 Test for a status code of SUCCESS. More...
 
bool isFailure () const
 Test for a status code of FAILURE. More...
 
bool isRecoverable () const
 
unsigned long getCode () const
 Get the status code by value. More...
 
void setCode (unsigned long value)
 Set the status code by value. More...
 
void setChecked () const
 Ignore the checking code;. More...
 
void ignore () const
 
bool checked () const
 Has the StatusCode been checked? More...
 
 operator unsigned long () const
 Cast operator. More...
 
StatusCodeoperator= (unsigned long value)
 Assignment operator. More...
 
StatusCodeoperator= (const StatusCode &rhs)
 
 operator IgnoreError () const
 

Static Public Member Functions

static GAUDI_API void enableChecking ()
 
static GAUDI_API void disableChecking ()
 
static GAUDI_API bool checkingEnabled ()
 

Protected Attributes

unsigned long d_code = SUCCESS
 The status code. More...
 
bool m_checked = false
 If the Status code has been checked. More...
 

Static Protected Attributes

static bool s_checking
 Global flag to control if StatusCode need to be checked. More...
 

Private Member Functions

void check ()
 

Friends

bool operator< (const StatusCode &a, const StatusCode &b)
 Comparison operator. More...
 
bool operator> (const StatusCode &a, const StatusCode &b)
 Comparison operator. More...
 

Detailed Description

This class is used for returning status codes from appropriate routines.

Author
Iain Last
Pere Mato
Sebastien Ponce

Definition at line 26 of file StatusCode.h.

Member Enumeration Documentation

anonymous enum
Enumerator
FAILURE 
SUCCESS 
RECOVERABLE 

Definition at line 29 of file StatusCode.h.

Constructor & Destructor Documentation

StatusCode::StatusCode ( )
default

Constructor.

StatusCode::StatusCode ( unsigned long  code,
bool  checked = false 
)
inline

Definition at line 34 of file StatusCode.h.

34 : d_code( code ), m_checked( checked ) {}
bool checked() const
Has the StatusCode been checked?
Definition: StatusCode.h:87
bool m_checked
If the Status code has been checked.
Definition: StatusCode.h:155
unsigned long d_code
The status code.
Definition: StatusCode.h:154
StatusCode::StatusCode ( const StatusCode rhs)
inline

Definition at line 36 of file StatusCode.h.

36 : d_code( rhs.d_code ), m_checked( rhs.m_checked ) { rhs.m_checked = true; }
bool m_checked
If the Status code has been checked.
Definition: StatusCode.h:155
unsigned long d_code
The status code.
Definition: StatusCode.h:154
StatusCode::StatusCode ( StatusCode &&  rhs)
inlinenoexcept

Move constructor.

Definition at line 39 of file StatusCode.h.

39 : d_code( rhs.d_code ), m_checked( rhs.m_checked ) { rhs.m_checked = true; }
bool m_checked
If the Status code has been checked.
Definition: StatusCode.h:155
unsigned long d_code
The status code.
Definition: StatusCode.h:154
StatusCode::~StatusCode ( )
inline

Destructor.

Definition at line 42 of file StatusCode.h.

43  {
44  if ( UNLIKELY( s_checking ) ) check();
45  }
#define UNLIKELY(x)
Definition: Kernel.h:128
void check()
Definition: StatusCode.cpp:24
static bool s_checking
Global flag to control if StatusCode need to be checked.
Definition: StatusCode.h:157

Member Function Documentation

void StatusCode::check ( )
private
Fix-Me:
: (MCl) use backTrace(std::string&, const int, const int) instead

Definition at line 24 of file StatusCode.cpp.

25 {
26 
28 
29  auto msg = Gaudi::svcLocator()->as<IMessageSvc>();
30  auto scs = Gaudi::svcLocator()->service<IStatusCodeSvc>( "StatusCodeSvc" );
31 
32  const size_t depth = 21;
33  void* addresses[depth];
34 
35  std::string lib, fnc;
36  void* addr = nullptr;
38  if ( System::backTrace( addresses, depth ) ) {
39 
40  for ( size_t idx : {2, 3} ) {
41  if ( System::getStackLevel( addresses[idx], addr, fnc, lib ) && fnc != "StatusCode::~StatusCode()" ) {
42 
43  if ( scs ) {
44  scs->regFnc( fnc, lib );
45  } else {
46  MsgStream log( msg, "StatusCode" );
47  log << MSG::WARNING << "Unchecked in " << fnc << " (" << lib << ")" << endmsg;
48  }
49  break;
50  }
51  }
52  }
53  }
54 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
GAUDI_API bool getStackLevel(void *addresses, void *&addr, std::string &fnc, std::string &lib)
bool m_checked
If the Status code has been checked.
Definition: StatusCode.h:155
static bool s_proc
"previous" element in the linked list
SmartIF< IFace > as()
Definition: ISvcLocator.h:109
GAUDI_API int backTrace(void **addresses, const int depth)
STL class.
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
Definition: ISvcLocator.h:79
GAUDI_API ISvcLocator * svcLocator()
The IMessage is the interface implemented by the message service.
Definition: IMessageSvc.h:38
T uncaught_exception(T...args)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
bool StatusCode::checked ( ) const
inline

Has the StatusCode been checked?

Definition at line 87 of file StatusCode.h.

87 { return m_checked; }
bool m_checked
If the Status code has been checked.
Definition: StatusCode.h:155
bool StatusCode::checkingEnabled ( )
static

Definition at line 22 of file StatusCode.cpp.

22 { return s_checking; }
static bool s_checking
Global flag to control if StatusCode need to be checked.
Definition: StatusCode.h:157
void StatusCode::disableChecking ( )
static

Definition at line 20 of file StatusCode.cpp.

20 { s_checking = false; }
static bool s_checking
Global flag to control if StatusCode need to be checked.
Definition: StatusCode.h:157
void StatusCode::enableChecking ( )
static

Definition at line 18 of file StatusCode.cpp.

18 { s_checking = true; }
static bool s_checking
Global flag to control if StatusCode need to be checked.
Definition: StatusCode.h:157
unsigned long StatusCode::getCode ( ) const
inline

Get the status code by value.

Definition at line 69 of file StatusCode.h.

70  {
71  m_checked = true;
72  return d_code;
73  }
bool m_checked
If the Status code has been checked.
Definition: StatusCode.h:155
unsigned long d_code
The status code.
Definition: StatusCode.h:154
void StatusCode::ignore ( ) const
inline

Definition at line 84 of file StatusCode.h.

84 { setChecked(); }
void setChecked() const
Ignore the checking code;.
Definition: StatusCode.h:83
bool StatusCode::isFailure ( ) const
inline

Test for a status code of FAILURE.

N.B. This is a specific type of failure where there aren't any more appropriate status codes. To test for any failure use : if ( !StatusCode.isSuccess() ) ...

Definition at line 61 of file StatusCode.h.

61 { return !isSuccess(); }
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:50
bool StatusCode::isRecoverable ( ) const
inline

Definition at line 62 of file StatusCode.h.

63  {
64  m_checked = true;
65  return ( d_code == RECOVERABLE );
66  }
bool m_checked
If the Status code has been checked.
Definition: StatusCode.h:155
unsigned long d_code
The status code.
Definition: StatusCode.h:154
bool StatusCode::isSuccess ( ) const
inline

Test for a status code of SUCCESS.

N.B. This is the only case where a function has succeeded.

Definition at line 50 of file StatusCode.h.

51  {
52  m_checked = true;
53  return ( d_code == SUCCESS );
54  }
bool m_checked
If the Status code has been checked.
Definition: StatusCode.h:155
unsigned long d_code
The status code.
Definition: StatusCode.h:154
StatusCode::operator IgnoreError ( ) const
inline

Definition at line 112 of file StatusCode.h.

113  {
114  m_checked = true;
115  return IgnoreError();
116  }
bool m_checked
If the Status code has been checked.
Definition: StatusCode.h:155
StatusCode::operator unsigned long ( ) const
inline

Cast operator.

Definition at line 90 of file StatusCode.h.

90 { return getCode(); }
unsigned long getCode() const
Get the status code by value.
Definition: StatusCode.h:69
StatusCode& StatusCode::operator= ( unsigned long  value)
inline

Assignment operator.

Definition at line 93 of file StatusCode.h.

94  {
95  setCode( value );
96  return *this;
97  }
void setCode(unsigned long value)
Set the status code by value.
Definition: StatusCode.h:76
StatusCode& StatusCode::operator= ( const StatusCode rhs)
inline

Definition at line 98 of file StatusCode.h.

99  {
100  d_code = rhs.d_code;
101  m_checked = std::exchange( rhs.m_checked, true );
102  return *this;
103  }
bool m_checked
If the Status code has been checked.
Definition: StatusCode.h:155
unsigned long d_code
The status code.
Definition: StatusCode.h:154
void StatusCode::setChecked ( ) const
inline

Ignore the checking code;.

Definition at line 83 of file StatusCode.h.

83 { m_checked = true; }
bool m_checked
If the Status code has been checked.
Definition: StatusCode.h:155
void StatusCode::setCode ( unsigned long  value)
inline

Set the status code by value.

Definition at line 76 of file StatusCode.h.

77  {
78  m_checked = false;
79  d_code = value;
80  }
bool m_checked
If the Status code has been checked.
Definition: StatusCode.h:155
unsigned long d_code
The status code.
Definition: StatusCode.h:154

Friends And Related Function Documentation

bool operator< ( const StatusCode a,
const StatusCode b 
)
friend

Comparison operator.

Definition at line 106 of file StatusCode.h.

106 { return a.d_code < b.d_code; }
unsigned long d_code
The status code.
Definition: StatusCode.h:154
bool operator> ( const StatusCode a,
const StatusCode b 
)
friend

Comparison operator.

Definition at line 109 of file StatusCode.h.

109 { return a.d_code > b.d_code; }
unsigned long d_code
The status code.
Definition: StatusCode.h:154

Member Data Documentation

unsigned long StatusCode::d_code = SUCCESS
protected

The status code.

The status code

Definition at line 154 of file StatusCode.h.

bool StatusCode::m_checked = false
mutableprotected

If the Status code has been checked.

Definition at line 155 of file StatusCode.h.

bool StatusCode::s_checking
staticprotected

Global flag to control if StatusCode need to be checked.

Definition at line 157 of file StatusCode.h.


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