//# LogOrigin.h: The source code location of the originator of a LogMessageLogOrig //# Copyright (C) 1996,1999,2000,2001 //# Associated Universities, Inc. Washington DC, USA. //# //# This library is free software; you can redistribute it and/or modify it //# under the terms of the GNU Library General Public License as published by //# the Free Software Foundation; either version 2 of the License, or (at your //# option) any later version. //# //# This library is distributed in the hope that it will be useful, but WITHOUT //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public //# License for more details. //# //# You should have received a copy of the GNU Library General Public License //# along with this library; if not, write to the Free Software Foundation, //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. //# //# Correspondence concerning AIPS++ should be addressed as follows: //# Internet email: aips2-request@nrao.edu. //# Postal address: AIPS++ Project Office //# National Radio Astronomy Observatory //# 520 Edgemont Road //# Charlottesville, VA 22903-2475 USA //# //# //# $Id$ #ifndef CASA_LOGORIGIN_H #define CASA_LOGORIGIN_H #include #include #include #include namespace casacore { //# NAMESPACE CASACORE - BEGIN struct SourceLocation; // // LogOrigin: The source code location of the originator of a LogMessage. // // // // // //
  • ObjectID if you are interested in // logging from Distributed Objects (don't worry if you don't know what // that means - in that case ignore it!). // // // // Log[message] Origin[ation point]. // // // // The LogOriging class is used to record the location at which a // LogMessage originates. It consists of: //
      //
    • A class name, which is blank in the case of a global function. //
    • A function name - global or member. You should "cut and paste" not only // the function name, but also the arguments (but not the return type) to // ensure that the function name is unique in the face of overloading. //
    • A source file name, usually filled in with the WHERE // predefined macro. //
    • A line number, usually filled in with the __LINE__ or // WHERE macros. //
    • An ObjectID if the log message comes // from a distributed object (if you don't know what this means, // you don't need to worry about it). //
    • Eventually we may want to canonicalize the path in the filename. //
    //
    // // // // See the examples for LogMessage and in // Logging.h. // // // It can be very useful for debugging if you know where a message is coming // from. // // // //
  • Nothing known // class LogOrigin { public: // The default constructor sets a null class name, function name, object id, // source file name, and sets the line number to zero. LogOrigin(); // Use this constructor if the log message origination is from a // global function. Normally where is provided using // the WHERE macro. LogOrigin(const String &globalFunctionName, const SourceLocation *where = 0); // Use this constructor if the log message origination is from a // class member function. Normally where is provided using // the WHERE macro. LogOrigin(const String &className, const String &memberFuncName, const SourceLocation *where = 0); // Use this constructor if the log message origination is from a // distributed object (don't worry if you don't know what this // means). Normally where is provided using the // WHERE macro. LogOrigin(const String &className, const String &memberFuncName, const ObjectID &id, const SourceLocation *where = 0); // Make this LogOrigin a copy of other. // LogOrigin(const LogOrigin &other); LogOrigin &operator=(const LogOrigin &other); // ~LogOrigin(); // Get or set the corresponding element of the source location. Note that // the "set" functions can be strung together: // // LogOrigin where; // ... // where.function("anotherFunc").line(__LINE__); // // const String &taskName() const; LogOrigin &taskName(const String &funcName); const String &functionName() const; LogOrigin &functionName(const String &funcName); const String &className() const; LogOrigin &className(const String &className); const ObjectID &objectID() const; LogOrigin &objectID(const ObjectID &id); uInt line() const; LogOrigin &line(uInt which); const String &fileName() const; LogOrigin &fileName(const String &fileName); // // Set the file name and line number at the same time. Normally // where will be defined with the WHERE macro. LogOrigin &sourceLocation(const SourceLocation *where); // Returns class\::function for a member function, or // \::function for a global function. String fullName() const; // Turn the entire origin into a String. String toString() const; // Turns the entire origin except for the ObjectID into a String. The // ObjectID can be turned into a string vie ObjectID::toString. String location() const; // Return true if the line number and file name are not set. Bool isUnset() const; private: String task_p; String function_p; String class_p; ObjectID id_p; uInt line_p; String file_p; String node_p; // Return a String with the MPI rank String getNode(); // Provide common implementation for copy constructor and // assignment operator. void copy_other(const LogOrigin &other); }; // // Write a LogOrigin to an ostream. // // Write a LogOrigin as a string to an ostream. Merely calls // LogOrigin::toString() // ostream &operator<<(ostream &os, const LogOrigin &origin); // // // Helper struct to get the source line. // // The user should only use the WHERE macro. // struct SourceLocation { const char *fileName; Int lineNumber; static const SourceLocation *canonicalize(const char *file, Int line); }; #define WHERE casacore::SourceLocation::canonicalize(__FILE__, __LINE__) // } //# NAMESPACE CASACORE - END #endif