BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
ers::Context Class Reference

Source context for Issue. More...

#include <Context.h>

Public Member Functions

 Context (const std::string &filename, int line_number, const std::string &function_name, const std::string &compiler_name, const std::string &compiler_version, const std::string &compilation_time, const std::string &compilation_date, const std::string &package)
const std::string & file () const throw ()
int line () const throw ()
const std::string & function () const throw ()
const std::string & position () const
const std::string & compiler () const
const std::string & compilation () const
const std::string & package_name () const throw ()
int stack_frames () const throw ()
const std::string & stack_frame (int i) const
std::vector< std::string > qualifiers () const throw ()
 Context (const std::string &filename, int line_number, const std::string &function_name, const std::string &compiler_name, const std::string &compiler_version, const std::string &compilation_time, const std::string &compilation_date, const std::string &package)
const std::string & file () const throw ()
int line () const throw ()
const std::string & function () const throw ()
const std::string & position () const
const std::string & compiler () const
const std::string & compilation () const
const std::string & package_name () const throw ()
int stack_frames () const throw ()
const std::string & stack_frame (int i) const
std::vector< std::string > qualifiers () const throw ()
 Context (const std::string &filename, int line_number, const std::string &function_name, const std::string &compiler_name, const std::string &compiler_version, const std::string &compilation_time, const std::string &compilation_date, const std::string &package)
const std::string & file () const throw ()
int line () const throw ()
const std::string & function () const throw ()
const std::string & position () const
const std::string & compiler () const
const std::string & compilation () const
const std::string & package_name () const throw ()
int stack_frames () const throw ()
const std::string & stack_frame (int i) const
std::vector< std::string > qualifiers () const throw ()

Static Public Member Functions

static const Contextempty ()
static std::string & host_type ()
 type of target host
static int debug_level ()
static void add_qualifier (const std::string &qualif)
static const Contextempty ()
static std::string & host_type ()
 type of target host
static int debug_level ()
static void add_qualifier (const std::string &qualif)
static const Contextempty ()
static std::string & host_type ()
 type of target host
static int debug_level ()
static void add_qualifier (const std::string &qualif)

Static Protected Member Functions

static void build_host_type ()
static void build_host_type ()
static void build_host_type ()

Protected Attributes

std::string m_file_name
int m_line_number
std::string m_function_name
std::string m_compiler_name
std::string m_compiler_version
std::string m_compilation_date
std::string m_compilation_time
std::string m_package_name
std::string m_compiler
std::string m_position
std::string m_compilation
std::vector< std::string > m_stack_frames

Static Protected Attributes

static Contextempty_instance = 0
static std::string s_host_type
static std::vector< std::string > default_qualifiers

Detailed Description

Source context for Issue.

This class encapsulates Context information for an issue. The context of an issue is the location in the code the issue was constructed. The context acts as an encapsulator for compilator generted information like:

  • source file
  • source line
  • function name
  • compilation date and time
  • compilator type

The current context can be obtained using the macro ERS_HERE An empty context can be obtained using the macro ERS_EMPTY

Author
Matthias Wiesmann
Version
1.1 - now returns references
Note
it should be possible to optimize out the compilation text string, have only one default instance if all the code share the same info. This would save some memory space.

Definition at line 41 of file Event/ers/include/ers/Context.h.

Constructor & Destructor Documentation

◆ Context() [1/3]

ers::Context::Context ( const std::string & filename,
int line_number,
const std::string & function_name,
const std::string & compiler_name,
const std::string & compiler_version,
const std::string & compilation_time,
const std::string & compilation_date,
const std::string & package_name )

Constructor - defines an Issue context. This constructor should generally not be called directly, instead use the macro ERS_HERE.

Parameters
filenamename of the source code file
line_numberline_number in the source code
function_namename of the function - either pretty printed or not
compiler_namename of the compiler
compiler_versionversion of the compiler
compilation_timetime of the compilation
compilation_datedate of the compilation

Definition at line 73 of file Context.cxx.

77 {
78 this->m_file_name = filename;
79 this->m_line_number = line_number;
80 this->m_function_name = function_name;
81 this->m_compiler_name = compiler_name;
82 this->m_compiler_version = compiler_version;
83 this->m_compilation_date = compilation_date;
84 this->m_compilation_time = compilation_time;
86#if defined( __GNU_LIBRARY__ )
87 void* array[128];
88 const int n_size = backtrace( array, 128 );
89 char** symbols = backtrace_symbols( array, n_size );
90 for ( int i = 1; i < n_size; i++ )
91 { // we start at 1, current position is noise
92 this->m_stack_frames.push_back( symbols[i] );
93 } // for
94 free( symbols );
95#endif
96} // Context
const std::string & package_name() const
Definition Context.cxx:180
std::vector< std::string > m_stack_frames

Referenced by empty().

◆ Context() [2/3]

ers::Context::Context ( const std::string & filename,
int line_number,
const std::string & function_name,
const std::string & compiler_name,
const std::string & compiler_version,
const std::string & compilation_time,
const std::string & compilation_date,
const std::string & package )

◆ Context() [3/3]

ers::Context::Context ( const std::string & filename,
int line_number,
const std::string & function_name,
const std::string & compiler_name,
const std::string & compiler_version,
const std::string & compilation_time,
const std::string & compilation_date,
const std::string & package )

Member Function Documentation

◆ add_qualifier() [1/3]

void ers::Context::add_qualifier ( const std::string & qualif)
static

Definition at line 58 of file Context.cxx.

58 {
59 default_qualifiers.push_back( qualif );
60} // add_qualifier
static std::vector< std::string > default_qualifiers

Referenced by main().

◆ add_qualifier() [2/3]

void ers::Context::add_qualifier ( const std::string & qualif)
static

◆ add_qualifier() [3/3]

void ers::Context::add_qualifier ( const std::string & qualif)
static

◆ build_host_type() [1/3]

void ers::Context::build_host_type ( )
staticprotected

stack frames

Definition at line 184 of file Context.cxx.

184 {
185 std::ostringstream plateform_s;
186#if defined( __linux__ )
187 plateform_s << "linux";
188#endif
189#if defined( __OpenBSD__ )
190 plateform_s << "OpenBSD";
191#endif
192#if defined( __FreeBSD__ )
193 plateform_s << "FreeBSD";
194#endif
195#if defined( __APPLE__ ) && defined( __MACH__ )
196 plateform_s << "Darwin";
197#endif
198#if defined( __SOLARIS__ )
199 plateform_s << "Solaris";
200#endif
201 plateform_s << "/";
202#if defined( __POWERPC__ ) || defined( __ppc__ ) || defined( __PPC__ ) || \
203 defined( powerpc ) || defined( ppc )
204 plateform_s << "PowerPC";
205#endif
206#if defined( __i386__ ) || defined( __INTEL__ ) || defined( intel ) || defined( _M_IX86 )
207 plateform_s << "i386";
208#endif
209#if defined( sparc ) || defined( __sparc )
210 plateform_s << "Sparc";
211#endif
212 s_host_type = plateform_s.str();
213} // build_host_type
static std::string s_host_type

Referenced by host_type().

◆ build_host_type() [2/3]

void ers::Context::build_host_type ( )
staticprotected

stack frames

◆ build_host_type() [3/3]

void ers::Context::build_host_type ( )
staticprotected

stack frames

◆ compilation() [1/3]

const std::string & ers::Context::compilation ( ) const
Returns
compilation time and date

Pretty printed compilation time description

Returns
reference to string containing description

Definition at line 164 of file Context.cxx.

164 {
165 if ( m_compilation.empty() )
166 {
167 std::ostringstream compilation_s;
168 if ( !m_compilation_time.empty() )
169 { compilation_s << m_compilation_time << " "; } // compilation time
170 if ( !m_compilation_date.empty() )
171 { compilation_s << m_compilation_date; } // compilation date
172 m_compilation = compilation_s.str();
173 } // if
174 return m_compilation;
175} // compilation

Referenced by compilation().

◆ compilation() [2/3]

const std::string & ers::Context::compilation ( ) const
Returns
compilation time and date

◆ compilation() [3/3]

const std::string & ers::Context::compilation ( ) const
Returns
compilation time and date

◆ compiler() [1/3]

const std::string & ers::Context::compiler ( ) const
Returns
compiler (compiler-name + compiler-version)

Pretty printed compiler name

Returns
reference to string containing format

Definition at line 146 of file Context.cxx.

146 {
147 if ( m_compiler.empty() )
148 {
149 if ( !m_compiler_name.empty() )
150 {
151 std::ostringstream compiler_s;
152 compiler_s << m_compiler_name << " " << m_compiler_version;
153 m_compiler = compiler_s.str();
154 }
155 else { m_compiler = "unknown"; }
156 } // build cache
157 return m_compiler;
158} // compiler

Referenced by compiler().

◆ compiler() [2/3]

const std::string & ers::Context::compiler ( ) const
Returns
compiler (compiler-name + compiler-version)

◆ compiler() [3/3]

const std::string & ers::Context::compiler ( ) const
Returns
compiler (compiler-name + compiler-version)

◆ debug_level() [1/3]

int ers::Context::debug_level ( )
static

Gives the current debug level

Returns
debug level, or -1 if it cannot be determined

Definition at line 50 of file Context.cxx.

50 {
51#if defined( DEBUG_LEVEL )
52 return DEBUG_LEVEL;
53#else
54 return -1;
55#endif
56} // debug_level

Referenced by ers::Issue::insert().

◆ debug_level() [2/3]

int ers::Context::debug_level ( )
static

◆ debug_level() [3/3]

int ers::Context::debug_level ( )
static

◆ empty() [1/3]

const ers::Context * ers::Context::empty ( )
static

Returns the empty instance

Returns
a pointer to the empty instance.

Definition at line 27 of file Context.cxx.

27 {
28 if ( !empty_instance )
29 {
30 std::string empty = "";
31 empty_instance = new ers::Context( empty, 0, empty, empty, empty, empty, empty, empty );
32 } // if
33 return empty_instance;
34} // empty
static Context * empty_instance
static const Context * empty()
Definition Context.cxx:27

Referenced by empty().

◆ empty() [2/3]

const Context * ers::Context::empty ( )
static

◆ empty() [3/3]

const Context * ers::Context::empty ( )
static

◆ file() [1/3]

const std::string & ers::Context::file ( ) const
throw ( )
Returns
file-name

The source code file name

Returns
path of the source file

Definition at line 102 of file Context.cxx.

102{ return m_file_name; } // file

◆ file() [2/3]

const std::string & ers::Context::file ( ) const
throw ( )
Returns
file-name

◆ file() [3/3]

const std::string & ers::Context::file ( ) const
throw ( )
Returns
file-name

◆ function() [1/3]

const std::string & ers::Context::function ( ) const
throw ( )
Returns
function name

Name of the function containing the context

Returns
name of the function

Definition at line 114 of file Context.cxx.

114 {
115 return m_function_name;
116} // function

Referenced by function(), and ers::NotImplemented::NotImplemented().

◆ function() [2/3]

const std::string & ers::Context::function ( ) const
throw ( )
Returns
function name

◆ function() [3/3]

const std::string & ers::Context::function ( ) const
throw ( )
Returns
function name

◆ host_type() [1/3]

std::string & ers::Context::host_type ( )
static

type of target host

Tries to gues the host name

Returns
a string describing the host, in the form architecture-operating-system

Definition at line 41 of file Context.cxx.

41 {
42 if ( s_host_type.empty() ) build_host_type();
43 return s_host_type;
44} // plateform
static void build_host_type()
Definition Context.cxx:184

◆ host_type() [2/3]

std::string & ers::Context::host_type ( )
static

type of target host

◆ host_type() [3/3]

std::string & ers::Context::host_type ( )
static

type of target host

◆ line() [1/3]

int ers::Context::line ( ) const
throw ( )
Returns
line-number

The line number in the source code

Returns
line number

Definition at line 108 of file Context.cxx.

108{ return m_line_number; } // line

Referenced by line().

◆ line() [2/3]

int ers::Context::line ( ) const
throw ( )
Returns
line-number

◆ line() [3/3]

int ers::Context::line ( ) const
throw ( )
Returns
line-number

◆ package_name() [1/3]

const std::string & ers::Context::package_name ( ) const
throw ( )
Returns
package name (if defined by CMT)
package name

Definition at line 180 of file Context.cxx.

180 {
181 return m_package_name;
182} // package_name

Referenced by Context(), and package_name().

◆ package_name() [2/3]

const std::string & ers::Context::package_name ( ) const
throw ( )
Returns
package name (if defined by CMT)

◆ package_name() [3/3]

const std::string & ers::Context::package_name ( ) const
throw ( )
Returns
package name (if defined by CMT)

◆ position() [1/3]

const std::string & ers::Context::position ( ) const
Returns
position (i.e file+line+function)

Pretty printed code position format: file_name:line_number (function_name)

Returns
reference to string containing format
Note
the file name is truncated from the last slash

Definition at line 124 of file Context.cxx.

124 {
125 if ( m_position.empty() )
126 {
127 std::ostringstream position_s;
128 if ( !m_package_name.empty() ) { position_s << m_package_name << ":"; }
129 if ( !m_file_name.empty() )
130 {
131 const std::string::size_type p = m_file_name.rfind( '/' );
132 if ( std::string::npos == p ) { position_s << m_file_name; }
133 else { position_s << ( m_file_name.substr( p + 1 ) ); } //
134 position_s << ":" << m_line_number << " ";
135 }
136 if ( !m_function_name.empty() ) { position_s << "(" << m_function_name << ")"; } // if
137 m_position = position_s.str();
138 } // cached version not calculated
139 return m_position;
140} // position

Referenced by position().

◆ position() [2/3]

const std::string & ers::Context::position ( ) const
Returns
position (i.e file+line+function)

◆ position() [3/3]

const std::string & ers::Context::position ( ) const
Returns
position (i.e file+line+function)

◆ qualifiers() [1/3]

std::vector< std::string > ers::Context::qualifiers ( ) const
throw ( )
Returns
array of qualifiers

Returns the set of qualifiers associated with context At the moment, this includes the default qualifiers plus the package

Returns
array of strings represnting the qualifiers

Definition at line 228 of file Context.cxx.

228 {
229 std::vector<std::string> qualif = default_qualifiers;
230 if ( !m_package_name.empty() ) { qualif.push_back( m_package_name ); } // if
231 return qualif;
232} // qualifiers

Referenced by qualifiers().

◆ qualifiers() [2/3]

std::vector< std::string > ers::Context::qualifiers ( ) const
throw ( )
Returns
array of qualifiers

◆ qualifiers() [3/3]

std::vector< std::string > ers::Context::qualifiers ( ) const
throw ( )
Returns
array of qualifiers

◆ stack_frame() [1/3]

const std::string & ers::Context::stack_frame ( int i) const
Returns
stack frame with index

Definition at line 219 of file Context.cxx.

219 {
220 return m_stack_frames[i];
221} // stack_frame

Referenced by stack_frame().

◆ stack_frame() [2/3]

const std::string & ers::Context::stack_frame ( int i) const
Returns
stack frame with index

◆ stack_frame() [3/3]

const std::string & ers::Context::stack_frame ( int i) const
Returns
stack frame with index

◆ stack_frames() [1/3]

int ers::Context::stack_frames ( ) const
throw ( )
Returns
number of stack frames

Definition at line 215 of file Context.cxx.

215 {
216 return m_stack_frames.size();
217} // stack_frames

Referenced by stack_frames().

◆ stack_frames() [2/3]

int ers::Context::stack_frames ( ) const
throw ( )
Returns
number of stack frames

◆ stack_frames() [3/3]

int ers::Context::stack_frames ( ) const
throw ( )
Returns
number of stack frames

Member Data Documentation

◆ default_qualifiers

std::vector< std::string > ers::Context::default_qualifiers
staticprotected

vector of default qualifiers

Definition at line 45 of file Event/ers/include/ers/Context.h.

Referenced by add_qualifier(), and qualifiers().

◆ empty_instance

Context * ers::Context::empty_instance = 0
staticprotected

Definition at line 43 of file Event/ers/include/ers/Context.h.

Referenced by empty().

◆ m_compilation

std::string ers::Context::m_compilation
mutableprotected

compilation (cache)

Definition at line 56 of file Event/ers/include/ers/Context.h.

Referenced by compilation().

◆ m_compilation_date

std::string ers::Context::m_compilation_date
protected

compilation date

Definition at line 51 of file Event/ers/include/ers/Context.h.

Referenced by compilation(), and Context().

◆ m_compilation_time

std::string ers::Context::m_compilation_time
protected

compilation time

Definition at line 52 of file Event/ers/include/ers/Context.h.

Referenced by compilation(), and Context().

◆ m_compiler

std::string ers::Context::m_compiler
mutableprotected

compilation string (cache)

Definition at line 54 of file Event/ers/include/ers/Context.h.

Referenced by compiler().

◆ m_compiler_name

std::string ers::Context::m_compiler_name
protected

compiler name

Definition at line 49 of file Event/ers/include/ers/Context.h.

Referenced by compiler(), and Context().

◆ m_compiler_version

std::string ers::Context::m_compiler_version
protected

compiler version

Definition at line 50 of file Event/ers/include/ers/Context.h.

Referenced by compiler(), and Context().

◆ m_file_name

std::string ers::Context::m_file_name
protected

source file-name

Definition at line 46 of file Event/ers/include/ers/Context.h.

Referenced by Context(), file(), and position().

◆ m_function_name

std::string ers::Context::m_function_name
protected

source function name (can be pretty printed or not)

Definition at line 48 of file Event/ers/include/ers/Context.h.

Referenced by Context(), function(), and position().

◆ m_line_number

int ers::Context::m_line_number
protected

source line-number

Definition at line 47 of file Event/ers/include/ers/Context.h.

Referenced by Context(), line(), and position().

◆ m_package_name

std::string ers::Context::m_package_name
protected

Definition at line 53 of file Event/ers/include/ers/Context.h.

Referenced by Context(), package_name(), position(), and qualifiers().

◆ m_position

std::string ers::Context::m_position
mutableprotected

code position (cache)

Definition at line 55 of file Event/ers/include/ers/Context.h.

Referenced by position().

◆ m_stack_frames

std::vector< std::string > ers::Context::m_stack_frames
protected

Definition at line 57 of file Event/ers/include/ers/Context.h.

Referenced by Context(), stack_frame(), and stack_frames().

◆ s_host_type

std::string ers::Context::s_host_type
staticprotected

host_type

Definition at line 44 of file Event/ers/include/ers/Context.h.

Referenced by build_host_type(), and host_type().


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