#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 () |
Static Public Member Functions | |
static const Context * | empty () |
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 () |
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 Context * | empty_instance = 0 |
static std::string | s_host_type |
static std::vector< std::string > | default_qualifiers |
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:
The current context can be obtained using the macro ERS_HERE
An empty context can be obtained using the macro ERS_EMPTY
Definition at line 42 of file Context.h.
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
.
filename | name of the source code file | |
line_number | line_number in the source code | |
function_name | name of the function - either pretty printed or not | |
compiler_name | name of the compiler | |
compiler_version | version of the compiler | |
compilation_time | time of the compilation | |
compilation_date | date of the compilation |
Definition at line 71 of file Context.cxx.
References genRecEmupikp::i, m_compilation_date, m_compilation_time, m_compiler_name, m_compiler_version, m_file_name, m_function_name, m_line_number, and m_package_name.
00074 { 00075 this->m_file_name = filename ; 00076 this->m_line_number = line_number ; 00077 this->m_function_name = function_name ; 00078 this->m_compiler_name = compiler_name ; 00079 this->m_compiler_version = compiler_version ; 00080 this->m_compilation_date = compilation_date ; 00081 this->m_compilation_time = compilation_time ; 00082 this->m_package_name = package_name ; 00083 #if defined(__GNU_LIBRARY__) 00084 void * array[128] ; 00085 const int n_size = backtrace (array,128) ; 00086 char ** symbols = backtrace_symbols(array, n_size); 00087 for (int i = 1; i < n_size; i++) { // we start at 1, current position is noise 00088 this->m_stack_frames.push_back(symbols[i]); 00089 } // for 00090 free(symbols); 00091 #endif 00092 } // Context
void ers::Context::add_qualifier | ( | const std::string & | qualif | ) | [static] |
Definition at line 56 of file Context.cxx.
References default_qualifiers.
Referenced by main().
00056 { 00057 default_qualifiers.push_back(qualif) ; 00058 } // add_qualifier
void ers::Context::build_host_type | ( | ) | [static, protected] |
stack frames
Definition at line 189 of file Context.cxx.
References s_host_type.
Referenced by host_type().
00189 { 00190 std::ostringstream plateform_s ; 00191 #if defined(__linux__) 00192 plateform_s << "linux" ; 00193 #endif 00194 #if defined(__OpenBSD__) 00195 plateform_s << "OpenBSD" ; 00196 #endif 00197 #if defined(__FreeBSD__) 00198 plateform_s << "FreeBSD" ; 00199 #endif 00200 #if defined(__APPLE__) && defined(__MACH__) 00201 plateform_s << "Darwin" ; 00202 #endif 00203 #if defined(__SOLARIS__) 00204 plateform_s << "Solaris" ; 00205 #endif 00206 plateform_s << "/" ; 00207 #if defined(__POWERPC__) || defined(__ppc__ ) || defined( __PPC__ ) || defined( powerpc ) || defined( ppc ) 00208 plateform_s << "PowerPC" ; 00209 #endif 00210 #if defined(__i386__) || defined(__INTEL__) || defined( intel ) || defined( _M_IX86 ) 00211 plateform_s << "i386" ; 00212 #endif 00213 #if defined(sparc) || defined(__sparc) 00214 plateform_s << "Sparc" ; 00215 #endif 00216 s_host_type= plateform_s.str(); 00217 } // build_host_type
const std::string & ers::Context::compilation | ( | ) | const |
Definition at line 168 of file Context.cxx.
References m_compilation, m_compilation_date, and m_compilation_time.
00168 { 00169 if (m_compilation.empty()) { 00170 std::ostringstream compilation_s ; 00171 if (! m_compilation_time.empty()) { 00172 compilation_s << m_compilation_time << " " ; 00173 } // compilation time 00174 if (! m_compilation_date.empty()) { 00175 compilation_s << m_compilation_date ; 00176 } // compilation date 00177 m_compilation = compilation_s.str(); 00178 } // if 00179 return m_compilation ; 00180 } // compilation
const std::string & ers::Context::compiler | ( | ) | const |
Definition at line 151 of file Context.cxx.
References m_compiler, m_compiler_name, and m_compiler_version.
00151 { 00152 if (m_compiler.empty()) { 00153 if (! m_compiler_name.empty()) { 00154 std::ostringstream compiler_s ; 00155 compiler_s << m_compiler_name << " " << m_compiler_version ; 00156 m_compiler = compiler_s.str(); 00157 } else { 00158 m_compiler = "unknown" ; 00159 } 00160 } // build cache 00161 return m_compiler ; 00162 } // compiler
int ers::Context::debug_level | ( | ) | [static] |
Gives the current debug level
Definition at line 48 of file Context.cxx.
References DEBUG_LEVEL.
Referenced by ers::Issue::insert().
00048 { 00049 #if defined(DEBUG_LEVEL) 00050 return DEBUG_LEVEL ; 00051 #else 00052 return -1 ; 00053 #endif 00054 } // debug_level
const ers::Context * ers::Context::empty | ( | ) | [static] |
Returns the empty instance
Definition at line 27 of file Context.cxx.
References empty_instance, and deljobs::string.
00027 { 00028 if (! empty_instance) { 00029 std::string empty = "" ; 00030 empty_instance = new ers::Context(empty,0,empty,empty,empty,empty,empty,empty) ; 00031 } // if 00032 return empty_instance ; 00033 } // empty
const std::string & ers::Context::file | ( | ) | const throw () |
Definition at line 98 of file Context.cxx.
References m_file_name.
00098 { 00099 return m_file_name ; 00100 } // file
const std::string & ers::Context::function | ( | ) | const throw () |
Definition at line 114 of file Context.cxx.
References m_function_name.
Referenced by ers::NotImplemented::NotImplemented().
00114 { 00115 return m_function_name ; 00116 } // function
std::string & ers::Context::host_type | ( | ) | [static] |
type of target host
Tries to gues the host name
Definition at line 39 of file Context.cxx.
References build_host_type(), and s_host_type.
00039 { 00040 if (s_host_type.empty()) build_host_type() ; 00041 return s_host_type ; 00042 } // plateform
int ers::Context::line | ( | ) | const throw () |
Definition at line 106 of file Context.cxx.
References m_line_number.
00106 { 00107 return m_line_number ; 00108 } // line
const std::string & ers::Context::package_name | ( | ) | const throw () |
Definition at line 185 of file Context.cxx.
References m_package_name.
00185 { 00186 return m_package_name ; 00187 } // package_name
const std::string & ers::Context::position | ( | ) | const |
Definition at line 124 of file Context.cxx.
References m_file_name, m_function_name, m_line_number, m_package_name, m_position, and RealDBUtil::npos.
00124 { 00125 if (m_position.empty()) { 00126 std::ostringstream position_s ; 00127 if (! m_package_name.empty()) { 00128 position_s << m_package_name << ":" ; 00129 } 00130 if (! m_file_name.empty()) { 00131 const std::string::size_type p = m_file_name.rfind('/') ; 00132 if (std::string::npos == p) { 00133 position_s << m_file_name ; 00134 } else { 00135 position_s << (m_file_name.substr(p+1)) ; 00136 } // 00137 position_s << ":" << m_line_number << " "; 00138 } 00139 if (! m_function_name.empty()) { 00140 position_s << "(" << m_function_name << ")" ; 00141 } // if 00142 m_position = position_s.str(); 00143 } // cached version not calculated 00144 return m_position ; 00145 } // position
std::vector< std::string > ers::Context::qualifiers | ( | ) | const throw () |
Definition at line 232 of file Context.cxx.
References default_qualifiers, and m_package_name.
00232 { 00233 std::vector<std::string> qualif = default_qualifiers ; 00234 if (! m_package_name.empty()) { 00235 qualif.push_back(m_package_name) ; 00236 } // if 00237 return qualif ; 00238 } // qualifiers
const std::string & ers::Context::stack_frame | ( | int | i | ) | const |
Definition at line 223 of file Context.cxx.
References m_stack_frames.
00223 { 00224 return m_stack_frames[i] ; 00225 } // stack_frame
int ers::Context::stack_frames | ( | ) | const throw () |
Definition at line 219 of file Context.cxx.
References m_stack_frames.
00219 { 00220 return m_stack_frames.size(); 00221 } // stack_frames
std::vector< std::string > ers::Context::default_qualifiers [static, protected] |
vector of default qualifiers
Definition at line 46 of file Context.h.
Referenced by add_qualifier(), and qualifiers().
ers::Context * ers::Context::empty_instance = 0 [static, protected] |
std::string ers::Context::m_compilation [mutable, protected] |
std::string ers::Context::m_compilation_date [protected] |
compilation date
Definition at line 52 of file Context.h.
Referenced by compilation(), and Context().
std::string ers::Context::m_compilation_time [protected] |
compilation time
Definition at line 53 of file Context.h.
Referenced by compilation(), and Context().
std::string ers::Context::m_compiler [mutable, protected] |
std::string ers::Context::m_compiler_name [protected] |
std::string ers::Context::m_compiler_version [protected] |
std::string ers::Context::m_file_name [protected] |
source file-name
Definition at line 47 of file Context.h.
Referenced by Context(), file(), and position().
std::string ers::Context::m_function_name [protected] |
source function name (can be pretty printed or not)
Definition at line 49 of file Context.h.
Referenced by Context(), function(), and position().
int ers::Context::m_line_number [protected] |
source line-number
Definition at line 48 of file Context.h.
Referenced by Context(), line(), and position().
std::string ers::Context::m_package_name [protected] |
Definition at line 54 of file Context.h.
Referenced by Context(), package_name(), position(), and qualifiers().
std::string ers::Context::m_position [mutable, protected] |
std::vector<std::string> ers::Context::m_stack_frames [protected] |
std::string ers::Context::s_host_type [static, protected] |
host_type
Definition at line 45 of file Context.h.
Referenced by build_host_type(), and host_type().