CGEM BOSS 6.6.5.h
BESIII Offline Software System
Loading...
Searching...
No Matches
Context.h
Go to the documentation of this file.
1/*
2 * Context.h
3 * ers
4 *
5 * Created by Matthias Wiesmann on 26.11.04.
6 * Copyright 2004 CERN. All rights reserved.
7 *
8 */
9
10#ifndef ERS_CONTEXT_
11#define ERS_CONTEXT_
12
13/** \file Context.h
14 * This file defines the ers::Context object, and the associated macros, like ERS_HERE.
15 */
16
17#include <string>
18#include <vector>
19
20namespace ers {
21
22
23/** This class encapsulates Context information for an issue.
24 * The context of an issue is the location in the code the issue was constructed.
25 * The context acts as an encapsulator for compilator generted information like:
26 * - source file
27 * - source line
28 * - function name
29 * - compilation date and time
30 * - compilator type
31 *
32 * The current context can be obtained using the macro \c ERS_HERE
33 * An empty context can be obtained using the macro \c ERS_EMPTY
34 *
35 * \author Matthias Wiesmann
36 * \version 1.1 - now returns references
37 * \brief Source context for Issue.
38 * \note it should be possible to optimize out the compilation text string, have only one default instance if
39 * all the code share the same info. This would save some memory space.
40 */
41
42class Context {
43protected:
45 static std::string s_host_type ; /**< host_type */
46 static std::vector<std::string> default_qualifiers ; /**< vector of default qualifiers */
47 std::string m_file_name ; /**< source file-name */
48 int m_line_number ; /**< source line-number */
49 std::string m_function_name ; /**< source function name (can be pretty printed or not) */
50 std::string m_compiler_name ; /**< compiler name */
51 std::string m_compiler_version ; /**< compiler version */
52 std::string m_compilation_date ; /**< compilation date */
53 std::string m_compilation_time ; /**< compilation time */
54 std::string m_package_name ;
55 mutable std::string m_compiler ; /**< compilation string (cache) */
56 mutable std::string m_position ; /**< code position (cache) */
57 mutable std::string m_compilation ; /**< compilation (cache) */
58 std::vector<std::string> m_stack_frames ; /** stack frames */
59 static void build_host_type() ;
60public:
61 static const Context* empty() ;
62 static std::string & host_type() ; /**< \brief type of target host */
63 static int debug_level();
64 static void add_qualifier(const std::string &qualif) ;
65 Context(const std::string &filename, int line_number, const std::string &function_name,
66 const std::string &compiler_name, const std::string &compiler_version,
67 const std::string &compilation_time, const std::string &compilation_date, const std::string &package) ;
68 const std::string & file() const throw(); /**< \return file-name */
69 int line() const throw() ; /**< \return line-number */
70 const std::string & function() const throw() ; /**< \return function name */
71 const std::string & position() const ; /**< \return position (i.e file+line+function) */
72 const std::string & compiler() const ; /**< \return compiler (compiler-name + compiler-version) */
73 const std::string & compilation() const ; /**< \return compilation time and date */
74 const std::string & package_name() const throw(); /**< \return package name (if defined by CMT) */
75 int stack_frames() const throw() ; /**< \return number of stack frames */
76 const std::string &stack_frame(int i) const ; /**< \return stack frame with index */
77 std::vector<std::string> qualifiers() const throw() ; /**< \return array of qualifiers */
78 } ; // Context
79
80} // ers
81
82/** \def COMPILER_NAME defines the name of the compiler used */
83/** \def __VERSION__ defines the version of the compiler used */
84
85#ifdef __GNUC__
86#define COMPILER_NAME "gcc"
87#endif
88
89#ifdef __INTEL_COMPILER
90#define COMPILER_NAME "icc"
91#endif
92
93#ifndef COMPILER_NAME
94#define COMPILER_NAME "unknown"
95#endif
96
97#ifndef __VERSION__
98#define __VERSION__ "unknown"
99#endif
100
101#ifdef TDAQ_PACKAGE_NAME
102#define ERS_PACK TDAQ_PACKAGE_NAME
103#else
104#define ERS_PACK ""
105#endif
106
107/** \def ERS_EMPTY macro to an empty context object used when no context is available */
108#define ERS_EMPTY *(ers::Context::empty())
109
110/** \def ERS_HERE This macro constructs a context object with all the current values
111 * If gnuc is present, we use the pretty function name instead of the standard __func__ name.
112 * If macro \c N_DEBUG is defined, an empty context is substituted.
113 */
114
115#ifndef N_DEBUG
116#ifdef __GNUC__
117#define ERS_HERE ers::Context(__FILE__,__LINE__,__PRETTY_FUNCTION__,COMPILER_NAME,__VERSION__,__TIME__,__DATE__,ERS_PACK)
118#else
119#define ERS_HERE ers::Context(__FILE__,__LINE__,__func__,COMPILER_NAME,__VERSION__,__TIME__,__DATE__,ERS_PACK)
120#endif
121#else
122#define ERS_HERE ERS_EMPTY
123#endif
124
125
126
127#endif
128
Source context for Issue.
Definition Context.h:42
int m_line_number
Definition Context.h:48
static std::string s_host_type
Definition Context.h:45
static const Context * empty()
Definition Context.cxx:27
const std::string & package_name() const
Definition Context.cxx:185
std::string m_compiler_name
Definition Context.h:50
const std::string & stack_frame(int i) const
Definition Context.cxx:223
int line() const
Definition Context.cxx:106
std::vector< std::string > qualifiers() const
Definition Context.cxx:232
std::string m_position
Definition Context.h:56
static int debug_level()
Definition Context.cxx:48
const std::string & compiler() const
Definition Context.cxx:151
std::string m_compilation_time
Definition Context.h:53
std::string m_compilation_date
Definition Context.h:52
static void build_host_type()
Definition Context.cxx:189
std::string m_compiler_version
Definition Context.h:51
static std::vector< std::string > default_qualifiers
Definition Context.h:46
const std::string & compilation() const
Definition Context.cxx:168
static void add_qualifier(const std::string &qualif)
Definition Context.cxx:56
const std::string & position() const
Definition Context.cxx:124
static std::string & host_type()
type of target host
Definition Context.cxx:39
std::string m_package_name
Definition Context.h:54
std::string m_compilation
Definition Context.h:57
int stack_frames() const
Definition Context.cxx:219
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)
Definition Context.cxx:71
std::string m_function_name
Definition Context.h:49
const std::string & file() const
Definition Context.cxx:98
std::string m_compiler
Definition Context.h:55
const std::string & function() const
Definition Context.cxx:114
std::vector< std::string > m_stack_frames
Definition Context.h:58
std::string m_file_name
Definition Context.h:47
static Context * empty_instance
Definition Context.h:44