Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

ers::Context Class Reference

Source context for Issue. More...

#include <Context.h>

List of all members.

Public Member Functions

const std::string & compilation () const
const std::string & compilation () const
const std::string & compiler () const
const std::string & compiler () const
 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 (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 ()
const std::string & file () const throw ()
const std::string & function () const throw ()
const std::string & function () const throw ()
int line () const throw ()
int line () const throw ()
const std::string & package_name () const throw ()
const std::string & package_name () const throw ()
const std::string & position () const
const std::string & position () const
std::vector< std::string > qualifiers () const throw ()
std::vector< std::string > qualifiers () const throw ()
const std::string & stack_frame (int i) const
const std::string & stack_frame (int i) const
int stack_frames () const throw ()
int stack_frames () const throw ()

Static Public Member Functions

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

Static Protected Member Functions

void build_host_type ()
void build_host_type ()

Protected Attributes

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

Static Protected Attributes

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


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:

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.


Constructor & Destructor Documentation

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:
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
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

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

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

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

00056                                                       {
00057     default_qualifiers.push_back(qualif) ;
00058 } // add_qualifier

void ers::Context::build_host_type  )  [static, protected]
 

stack frames

void ers::Context::build_host_type  )  [static, protected]
 

stack frames

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
 

Returns:
compilation time and date

const std::string & ers::Context::compilation  )  const
 

Returns:
compilation time and date
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
 

Returns:
compiler (compiler-name + compiler-version)

const std::string & ers::Context::compiler  )  const
 

Returns:
compiler (compiler-name + 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]
 

int ers::Context::debug_level  )  [static]
 

Gives the current debug level

Returns:
debug level, or -1 if it cannot be determined
00048                             {
00049 #if defined(DEBUG_LEVEL) 
00050     return DEBUG_LEVEL ; 
00051 #else 
00052     return -1 ; 
00053 #endif
00054 } // debug_level

const Context* ers::Context::empty  )  [static]
 

const ers::Context * ers::Context::empty  )  [static]
 

Returns the empty instance

Returns:
a pointer to the empty instance.
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 ()
 

Returns:
file-name

const std::string & ers::Context::file  )  const throw ()
 

Returns:
file-name
00098                                                  {
00099     return m_file_name ; 
00100 } // file

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

Returns:
function name

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

Returns:
function name
00114                                                      {
00115     return m_function_name ; 
00116 } // function

std::string& ers::Context::host_type  )  [static]
 

type of target host

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
00039                                   {
00040     if (s_host_type.empty()) build_host_type() ; 
00041     return s_host_type ; 
00042 } // plateform

int ers::Context::line  )  const throw ()
 

Returns:
line-number

int ers::Context::line  )  const throw ()
 

Returns:
line-number
00106                                    {
00107     return m_line_number ; 
00108 } // line 

const std::string& ers::Context::package_name  )  const throw ()
 

Returns:
package name (if defined by CMT)

const std::string & ers::Context::package_name  )  const throw ()
 

Returns:
package name (if defined by CMT)
00185                                                          {
00186     return m_package_name ; 
00187 } // package_name

const std::string& ers::Context::position  )  const
 

Returns:
position (i.e file+line+function)

const std::string & ers::Context::position  )  const
 

Returns:
position (i.e file+line+function)
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 ()
 

Returns:
array of qualifiers

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

Returns:
array of qualifiers
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
 

Returns:
stack frame with index

const std::string & ers::Context::stack_frame int  i  )  const
 

Returns:
stack frame with index
00223                                                      {
00224    return m_stack_frames[i] ; 
00225 } // stack_frame

int ers::Context::stack_frames  )  const throw ()
 

Returns:
number of stack frames

int ers::Context::stack_frames  )  const throw ()
 

Returns:
number of stack frames
00219                                            {
00220    return m_stack_frames.size();
00221 } // stack_frames


Member Data Documentation

std::vector<std::string> ers::Context::default_qualifiers [static, protected]
 

vector of default qualifiers

std::vector< std::string > ers::Context::default_qualifiers [static, protected]
 

vector of default qualifiers

Context* ers::Context::empty_instance [static, protected]
 

ers::Context * ers::Context::empty_instance = 0 [static, protected]
 

std::string ers::Context::m_compilation [mutable, protected]
 

compilation (cache)

std::string ers::Context::m_compilation_date [protected]
 

compilation date

std::string ers::Context::m_compilation_time [protected]
 

compilation time

std::string ers::Context::m_compiler [mutable, protected]
 

compilation string (cache)

std::string ers::Context::m_compiler_name [protected]
 

compiler name

std::string ers::Context::m_compiler_version [protected]
 

compiler version

std::string ers::Context::m_file_name [protected]
 

source file-name

std::string ers::Context::m_function_name [protected]
 

source function name (can be pretty printed or not)

int ers::Context::m_line_number [protected]
 

source line-number

std::string ers::Context::m_package_name [protected]
 

std::string ers::Context::m_position [mutable, protected]
 

code position (cache)

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

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

std::string ers::Context::s_host_type [static, protected]
 

host_type


The documentation for this class was generated from the following files:
Generated on Wed Feb 2 19:19:22 2011 for BOSS6.5.5 by  doxygen 1.3.9.1