casa
$Rev:20696$
|
00001 //# LogOrigin.h: The source code location of the originator of a LogMessageLogOrig 00002 //# Copyright (C) 1996,1999,2000,2001 00003 //# Associated Universities, Inc. Washington DC, USA. 00004 //# 00005 //# This library is free software; you can redistribute it and/or modify it 00006 //# under the terms of the GNU Library General Public License as published by 00007 //# the Free Software Foundation; either version 2 of the License, or (at your 00008 //# option) any later version. 00009 //# 00010 //# This library is distributed in the hope that it will be useful, but WITHOUT 00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00012 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00013 //# License for more details. 00014 //# 00015 //# You should have received a copy of the GNU Library General Public License 00016 //# along with this library; if not, write to the Free Software Foundation, 00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 00018 //# 00019 //# Correspondence concerning AIPS++ should be addressed as follows: 00020 //# Internet email: aips2-request@nrao.edu. 00021 //# Postal address: AIPS++ Project Office 00022 //# National Radio Astronomy Observatory 00023 //# 520 Edgemont Road 00024 //# Charlottesville, VA 22903-2475 USA 00025 //# 00026 //# 00027 //# $Id: LogOrigin.h 20551 2009-03-25 00:11:33Z Malte.Marquarding $ 00028 00029 #ifndef CASA_LOGORIGIN_H 00030 #define CASA_LOGORIGIN_H 00031 00032 #include <casa/aips.h> 00033 #include <casa/BasicSL/String.h> 00034 #include <casa/System/ObjectID.h> 00035 #include <casa/iosfwd.h> 00036 00037 namespace casa { //# NAMESPACE CASA - BEGIN 00038 00039 class SourceLocation; 00040 00041 // <summary> 00042 // LogOrigin: The source code location of the originator of a LogMessage. 00043 // </summary> 00044 00045 // <use visibility=export> 00046 00047 // <reviewed reviewer="wbrouw" date="1996/08/21" tests="tLogging.cc" demos="dLogging.cc"> 00048 // </reviewed> 00049 00050 // <prerequisite> 00051 // <li> <linkto class="ObjectID">ObjectID</linkto> if you are interested in 00052 // logging from Distributed Objects (don't worry if you don't know what 00053 // that means - in that case ignore it!). 00054 // </prerequisite> 00055 // 00056 // <etymology> 00057 // Log[message] Origin[ation point]. 00058 // </etymology> 00059 // 00060 // <synopsis> 00061 // The <src>LogOriging</src> class is used to record the location at which a 00062 // <linkto class="LogMessage">LogMessage</linkto> originates. It consists of: 00063 // <ul> 00064 // <li> A class name, which is blank in the case of a global function. 00065 // <li> A function name - global or member. You should "cut and paste" not only 00066 // the function name, but also the arguments (but not the return type) to 00067 // ensure that the function name is unique in the face of overloading. 00068 // <li> A source file name, usually filled in with the <src>WHERE</src> 00069 // predefined macro. 00070 // <li> A line number, usually filled in with the <src>__LINE__</src> or 00071 // <src>WHERE</src> macros. 00072 // <li> An <linkto class="ObjectID">ObjectID</linkto> if the log message comes 00073 // from a distributed object (if you don't know what this means, 00074 // you don't need to worry about it). 00075 // <li> Eventually we may want to canonicalize the path in the filename. 00076 // </ul> 00077 // </synopsis> 00078 // 00079 // <example> 00080 00081 // </example> 00082 // See the examples for <linkto class="LogMessage">LogMessage</linkto> and in 00083 // <linkto file="Logging.h">Logging.h</linkto>. 00084 // 00085 // <motivation> 00086 // It can be very useful for debugging if you know where a message is coming 00087 // from. 00088 // </motivation> 00089 // 00090 // <todo asof="1996/07/23"> 00091 // <li> Nothing known 00092 // </todo> 00093 00094 class LogOrigin 00095 { 00096 public: 00097 // The default constructor sets a null class name, function name, object id, 00098 // source file name, and sets the line number to zero. 00099 LogOrigin(); 00100 00101 // Use this constructor if the log message origination is from a 00102 // global function. Normally <src>where</src> is provided using 00103 // the <src>WHERE</src> macro. 00104 LogOrigin(const String &globalFunctionName, const SourceLocation *where = 0); 00105 00106 // Use this constructor if the log message origination is from a 00107 // class member function. Normally <src>where</src> is provided using 00108 // the <src>WHERE</src> macro. 00109 LogOrigin(const String &className, const String &memberFuncName, 00110 const SourceLocation *where = 0); 00111 00112 // Use this constructor if the log message origination is from a 00113 // distributed object (don't worry if you don't know what this 00114 // means). Normally <src>where</src> is provided using the 00115 // <src>WHERE</src> macro. 00116 LogOrigin(const String &className, const String &memberFuncName, 00117 const ObjectID &id, const SourceLocation *where = 0); 00118 00119 // Make <src>this</src> LogOrigin a copy of <src>other</src>. 00120 // <group> 00121 LogOrigin(const LogOrigin &other); 00122 LogOrigin &operator=(const LogOrigin &other); 00123 // </group> 00124 00125 ~LogOrigin(); 00126 00127 // Get or set the corresponding element of the source location. Note that 00128 // the "set" functions can be strung together: 00129 // <srcBlock> 00130 // LogOrigin where; 00131 // ... 00132 // where.function("anotherFunc").line(__LINE__); 00133 // </srcBlock> 00134 // <group> 00135 const String &taskName() const; 00136 LogOrigin &taskName(const String &funcName); 00137 00138 const String &functionName() const; 00139 LogOrigin &functionName(const String &funcName); 00140 00141 const String &className() const; 00142 LogOrigin &className(const String &className); 00143 00144 const ObjectID &objectID() const; 00145 LogOrigin &objectID(const ObjectID &id); 00146 00147 uInt line() const; 00148 LogOrigin &line(uInt which); 00149 00150 const String &fileName() const; 00151 LogOrigin &fileName(const String &fileName); 00152 // </group> 00153 00154 // Set the file name and line number at the same time. Normally 00155 // <src>where</src> will be defined with the <src>WHERE</src> macro. 00156 LogOrigin &sourceLocation(const SourceLocation *where); 00157 00158 // Returns <src>class::function</src> for a member function, or 00159 // <src>::function</src> for a global function. 00160 String fullName() const; 00161 00162 // Turn the entire origin into a String. 00163 String toString() const; 00164 00165 // Turns the entire origin except for the ObjectID into a String. The 00166 // ObjectID can be turned into a string vie ObjectID::toString. 00167 String location() const; 00168 00169 // Return true if the line number and file name are not set. 00170 Bool isUnset() const; 00171 private: 00172 String task_p; 00173 String function_p; 00174 String class_p; 00175 ObjectID id_p; 00176 uInt line_p; 00177 String file_p; 00178 00179 // Provide common implementation for copy constructor and 00180 // assignment operator. 00181 void copy_other(const LogOrigin &other); 00182 }; 00183 00184 // <summary> 00185 // Write a LogOrigin to an ostream. 00186 // </summary> 00187 // Write a LogOrigin as a string to an ostream. Merely calls 00188 // <src>LogOrigin::toString()</src> 00189 // <group name=LogOrigin_ostream> 00190 ostream &operator<<(ostream &os, const LogOrigin &origin); 00191 // </group> 00192 00193 // <summary> 00194 // Helper struct to get the source line. 00195 // </summary> 00196 // The user should only use the <src>WHERE</src> macro. 00197 // <group name=SourceLocation> 00198 struct SourceLocation 00199 { 00200 const char *fileName; 00201 Int lineNumber; 00202 static const SourceLocation *canonicalize(const char *file, Int line); 00203 }; 00204 00205 #define WHERE casa::SourceLocation::canonicalize(__FILE__, __LINE__) 00206 00207 // </group> 00208 00209 00210 } //# NAMESPACE CASA - END 00211 00212 #endif