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