BOSS 7.0.2
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 ()
 

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 Protected Member Functions

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 42 of file Event/ers/ers-00-00-03/ers/Context.h.

Constructor & Destructor Documentation

◆ Context() [1/2]

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 71 of file Context.cxx.

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

◆ Context() [2/2]

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/2]

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

Definition at line 56 of file Context.cxx.

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

Referenced by main().

◆ add_qualifier() [2/2]

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

◆ build_host_type() [1/2]

void ers::Context::build_host_type ( )
staticprotected

stack frames

Definition at line 189 of file Context.cxx.

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

◆ build_host_type() [2/2]

static void ers::Context::build_host_type ( )
staticprotected

stack frames

◆ compilation() [1/2]

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 168 of file Context.cxx.

168 {
169 if (m_compilation.empty()) {
170 std::ostringstream compilation_s ;
171 if (! m_compilation_time.empty()) {
172 compilation_s << m_compilation_time << " " ;
173 } // compilation time
174 if (! m_compilation_date.empty()) {
175 compilation_s << m_compilation_date ;
176 } // compilation date
177 m_compilation = compilation_s.str();
178 } // if
179 return m_compilation ;
180} // compilation

◆ compilation() [2/2]

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

◆ compiler() [1/2]

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 151 of file Context.cxx.

151 {
152 if (m_compiler.empty()) {
153 if (! m_compiler_name.empty()) {
154 std::ostringstream compiler_s ;
155 compiler_s << m_compiler_name << " " << m_compiler_version ;
156 m_compiler = compiler_s.str();
157 } else {
158 m_compiler = "unknown" ;
159 }
160 } // build cache
161 return m_compiler ;
162} // compiler

◆ compiler() [2/2]

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

◆ debug_level() [1/2]

int ers::Context::debug_level ( )
static

Gives the current debug level

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

Definition at line 48 of file Context.cxx.

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

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

◆ debug_level() [2/2]

static int ers::Context::debug_level ( )
static

◆ empty() [1/2]

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 std::string empty = "" ;
31 } // if
32 return empty_instance ;
33} // empty
Source context for Issue.
static const Context * empty()
Definition: Context.cxx:27

Referenced by empty().

◆ empty() [2/2]

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

◆ file() [1/2]

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 98 of file Context.cxx.

98 {
99 return m_file_name ;
100} // file

◆ file() [2/2]

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

◆ function() [1/2]

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 ers::NotImplemented::NotImplemented().

◆ function() [2/2]

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

◆ host_type() [1/2]

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 39 of file Context.cxx.

39 {
40 if (s_host_type.empty()) build_host_type() ;
41 return s_host_type ;
42} // plateform
static void build_host_type()
Definition: Context.cxx:189

◆ host_type() [2/2]

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

type of target host

◆ line() [1/2]

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

The line number in the source code

Returns
line number

Definition at line 106 of file Context.cxx.

106 {
107 return m_line_number ;
108} // line

◆ line() [2/2]

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

◆ package_name() [1/2]

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

Definition at line 185 of file Context.cxx.

185 {
186 return m_package_name ;
187} // package_name

◆ package_name() [2/2]

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

◆ position() [1/2]

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 std::ostringstream position_s ;
127 if (! m_package_name.empty()) {
128 position_s << m_package_name << ":" ;
129 }
130 if (! m_file_name.empty()) {
131 const std::string::size_type p = m_file_name.rfind('/') ;
132 if (std::string::npos == p) {
133 position_s << m_file_name ;
134 } else {
135 position_s << (m_file_name.substr(p+1)) ;
136 } //
137 position_s << ":" << m_line_number << " ";
138 }
139 if (! m_function_name.empty()) {
140 position_s << "(" << m_function_name << ")" ;
141 } // if
142 m_position = position_s.str();
143 } // cached version not calculated
144 return m_position ;
145} // position

◆ position() [2/2]

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

◆ qualifiers() [1/2]

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 232 of file Context.cxx.

232 {
233 std::vector<std::string> qualif = default_qualifiers ;
234 if (! m_package_name.empty()) {
235 qualif.push_back(m_package_name) ;
236 } // if
237 return qualif ;
238} // qualifiers

◆ qualifiers() [2/2]

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

◆ stack_frame() [1/2]

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

Definition at line 223 of file Context.cxx.

223 {
224 return m_stack_frames[i] ;
225} // stack_frame

◆ stack_frame() [2/2]

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

◆ stack_frames() [1/2]

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

Definition at line 219 of file Context.cxx.

219 {
220 return m_stack_frames.size();
221} // stack_frames

◆ stack_frames() [2/2]

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

Member Data Documentation

◆ default_qualifiers

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

vector of default qualifiers

Definition at line 46 of file Event/ers/ers-00-00-03/ers/Context.h.

◆ empty_instance

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

Definition at line 44 of file Event/ers/ers-00-00-03/ers/Context.h.

Referenced by empty().

◆ m_compilation

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

compilation (cache)

Definition at line 57 of file Event/ers/ers-00-00-03/ers/Context.h.

◆ m_compilation_date

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

compilation date

Definition at line 52 of file Event/ers/ers-00-00-03/ers/Context.h.

◆ m_compilation_time

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

compilation time

Definition at line 53 of file Event/ers/ers-00-00-03/ers/Context.h.

◆ m_compiler

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

compilation string (cache)

Definition at line 55 of file Event/ers/ers-00-00-03/ers/Context.h.

◆ m_compiler_name

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

compiler name

Definition at line 50 of file Event/ers/ers-00-00-03/ers/Context.h.

◆ m_compiler_version

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

compiler version

Definition at line 51 of file Event/ers/ers-00-00-03/ers/Context.h.

◆ m_file_name

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

source file-name

Definition at line 47 of file Event/ers/ers-00-00-03/ers/Context.h.

◆ m_function_name

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

source function name (can be pretty printed or not)

Definition at line 49 of file Event/ers/ers-00-00-03/ers/Context.h.

◆ m_line_number

int ers::Context::m_line_number
protected

source line-number

Definition at line 48 of file Event/ers/ers-00-00-03/ers/Context.h.

◆ m_package_name

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

Definition at line 54 of file Event/ers/ers-00-00-03/ers/Context.h.

◆ m_position

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

code position (cache)

Definition at line 56 of file Event/ers/ers-00-00-03/ers/Context.h.

◆ m_stack_frames

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

Definition at line 58 of file Event/ers/ers-00-00-03/ers/Context.h.

◆ s_host_type

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

host_type

Definition at line 45 of file Event/ers/ers-00-00-03/ers/Context.h.


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