casacore
Loading...
Searching...
No Matches
LogOrigin.h
Go to the documentation of this file.
1//# LogOrigin.h: The source code location of the originator of a LogMessageLogOrig
2//# Copyright (C) 1996,1999,2000,2001
3//# Associated Universities, Inc. Washington DC, USA.
4//#
5//# This library is free software; you can redistribute it and/or modify it
6//# under the terms of the GNU Library General Public License as published by
7//# the Free Software Foundation; either version 2 of the License, or (at your
8//# option) any later version.
9//#
10//# This library is distributed in the hope that it will be useful, but WITHOUT
11//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12//# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13//# License for more details.
14//#
15//# You should have received a copy of the GNU Library General Public License
16//# along with this library; if not, write to the Free Software Foundation,
17//# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18//#
19//# Correspondence concerning AIPS++ should be addressed as follows:
20//# Internet email: casa-feedback@nrao.edu.
21//# Postal address: AIPS++ Project Office
22//# National Radio Astronomy Observatory
23//# 520 Edgemont Road
24//# Charlottesville, VA 22903-2475 USA
25
26#ifndef CASA_LOGORIGIN_H
27#define CASA_LOGORIGIN_H
28
29#include <casacore/casa/aips.h>
30#include <casacore/casa/BasicSL/String.h>
31#include <casacore/casa/System/ObjectID.h>
32#include <casacore/casa/iosfwd.h>
33
34namespace casacore { //# NAMESPACE CASACORE - BEGIN
35
36struct SourceLocation;
37
38// <summary>
39// LogOrigin: The source code location of the originator of a LogMessage.
40// </summary>
41
42// <use visibility=export>
43
44// <reviewed reviewer="wbrouw" date="1996/08/21" tests="tLogging.cc" demos="dLogging.cc">
45// </reviewed>
46
47// <prerequisite>
48// <li> <linkto class="ObjectID">ObjectID</linkto> if you are interested in
49// logging from Distributed Objects (don't worry if you don't know what
50// that means - in that case ignore it!).
51// </prerequisite>
52//
53// <etymology>
54// Log[message] Origin[ation point].
55// </etymology>
56//
57// <synopsis>
58// The <src>LogOriging</src> class is used to record the location at which a
59// <linkto class="LogMessage">LogMessage</linkto> originates. It consists of:
60// <ul>
61// <li> A class name, which is blank in the case of a global function.
62// <li> A function name - global or member. You should "cut and paste" not only
63// the function name, but also the arguments (but not the return type) to
64// ensure that the function name is unique in the face of overloading.
65// <li> A source file name, usually filled in with the <src>WHERE</src>
66// predefined macro.
67// <li> A line number, usually filled in with the <src>__LINE__</src> or
68// <src>WHERE</src> macros.
69// <li> An <linkto class="ObjectID">ObjectID</linkto> if the log message comes
70// from a distributed object (if you don't know what this means,
71// you don't need to worry about it).
72// <li> Eventually we may want to canonicalize the path in the filename.
73// </ul>
74// </synopsis>
75//
76// <example>
77
78// </example>
79// See the examples for <linkto class="LogMessage">LogMessage</linkto> and in
80// <linkto file="Logging.h">Logging.h</linkto>.
81//
82// <motivation>
83// It can be very useful for debugging if you know where a message is coming
84// from.
85// </motivation>
86//
87// <todo asof="1996/07/23">
88// <li> Nothing known
89// </todo>
90
92{
93public:
94
95 // The default constructor sets a null class name, function name, object id,
96 // source file name, and sets the line number to zero.
98
99 // Use this constructor if the log message origination is from a
100 // global function. Normally <src>where</src> is provided using
101 // the <src>WHERE</src> macro.
102 LogOrigin(const String &globalFunctionName, const SourceLocation *where = 0);
103
104 // Use this constructor if the log message origination is from a
105 // class member function. Normally <src>where</src> is provided using
106 // the <src>WHERE</src> macro.
107 LogOrigin(const String &className, const String &memberFuncName,
108 const SourceLocation *where = 0);
109
110 // Use this constructor if the log message origination is from a
111 // distributed object (don't worry if you don't know what this
112 // means). Normally <src>where</src> is provided using the
113 // <src>WHERE</src> macro.
114 LogOrigin(const String &className, const String &memberFuncName,
115 const ObjectID &id, const SourceLocation *where = 0);
116
117 // Make <src>this</src> LogOrigin a copy of <src>other</src>.
118 // <group>
119 LogOrigin(const LogOrigin &other);
121 // </group>
122
124
125 // Get or set the corresponding element of the source location. Note that
126 // the "set" functions can be strung together:
127 // <srcBlock>
128 // LogOrigin where;
129 // ...
130 // where.function("anotherFunc").line(__LINE__);
131 // </srcBlock>
132 // <group>
133 const String &taskName() const;
134 LogOrigin &taskName(const String &funcName);
135
136 const String &functionName() const;
137 LogOrigin &functionName(const String &funcName);
138
139 const String &className() const;
141
142 const ObjectID &objectID() const;
144
145 uInt line() const;
147
148 const String &fileName() const;
150 // </group>
151
152 // Set the file name and line number at the same time. Normally
153 // <src>where</src> will be defined with the <src>WHERE</src> macro.
154 LogOrigin &sourceLocation(const SourceLocation *where);
155
156 // Returns <src>class\::function</src> for a member function, or
157 // <src>\::function</src> for a global function.
159
160 // Turn the entire origin into a String.
162
163 // Turns the entire origin except for the ObjectID into a String. The
164 // ObjectID can be turned into a string vie ObjectID::toString.
166
167 // Return true if the line number and file name are not set.
168 Bool isUnset() const;
169
170private:
178
179 // Return a String with the MPI rank
181
182 // Provide common implementation for copy constructor and
183 // assignment operator.
184 void copy_other(const LogOrigin &other);
185};
186
187// <summary>
188// Write a LogOrigin to an ostream.
189// </summary>
190// Write a LogOrigin as a string to an ostream. Merely calls
191// <src>LogOrigin::toString()</src>
192// <group name=LogOrigin_ostream>
193ostream &operator<<(ostream &os, const LogOrigin &origin);
194// </group>
195
196// <summary>
197// Helper struct to get the source line.
198// </summary>
199// The user should only use the <src>WHERE</src> macro.
200// <group name=SourceLocation>
203 const char *fileName;
204 Int lineNumber;
205 static const SourceLocation *canonicalize(const char *file, Int line);
207
208#define WHERE casacore::SourceLocation::canonicalize(__FILE__, __LINE__)
209
210// </group>
211
212
213} //# NAMESPACE CASACORE - END
214
215#endif
String location() const
Turns the entire origin except for the ObjectID into a String.
LogOrigin(const String &globalFunctionName, const SourceLocation *where=0)
Use this constructor if the log message origination is from a global function.
LogOrigin & operator=(const LogOrigin &other)
const String & functionName() const
LogOrigin()
The default constructor sets a null class name, function name, object id, source file name,...
Bool isUnset() const
Return true if the line number and file name are not set.
LogOrigin & fileName(const String &fileName)
const String & className() const
LogOrigin & sourceLocation(const SourceLocation *where)
Set the file name and line number at the same time.
const String & fileName() const
const String & taskName() const
Get or set the corresponding element of the source location.
LogOrigin & functionName(const String &funcName)
String toString() const
Turn the entire origin into a String.
void copy_other(const LogOrigin &other)
Provide common implementation for copy constructor and assignment operator.
LogOrigin & className(const String &className)
const ObjectID & objectID() const
LogOrigin & line(uInt which)
LogOrigin & objectID(const ObjectID &id)
LogOrigin(const String &className, const String &memberFuncName, const SourceLocation *where=0)
Use this constructor if the log message origination is from a class member function.
uInt line() const
String fullName() const
Returns class::function for a member function, or ::function for a global function.
LogOrigin(const LogOrigin &other)
Make this LogOrigin a copy of other.
String getNode()
Return a String with the MPI rank.
LogOrigin & taskName(const String &funcName)
LogOrigin(const String &className, const String &memberFuncName, const ObjectID &id, const SourceLocation *where=0)
Use this constructor if the log message origination is from a distributed object (don't worry if you ...
String: the storage and methods of handling collections of characters.
Definition String.h:223
this file contains all the compiler specific defines
Definition mainpage.dox:28
ostream & operator<<(ostream &os, const IComplex &)
Show on ostream.
unsigned int uInt
Definition aipstype.h:49
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
ostream & operator<<(ostream &os, const LogOrigin &origin)
static const SourceLocation * canonicalize(const char *file, Int line)
Helper struct to get the source line.
Definition LogOrigin.h:201