casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
MemoryLogSink.h
Go to the documentation of this file.
00001 //# MemoryLogSink.h: Save log messages in memory
00002 //# Copyright (C) 2001,2003
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: MemoryLogSink.h 20551 2009-03-25 00:11:33Z Malte.Marquarding $
00028 
00029 #ifndef CASA_MEMORYLOGSINK_H
00030 #define CASA_MEMORYLOGSINK_H
00031 
00032 //# Includes
00033 #include <casa/aips.h>
00034 #include <casa/Logging/LogSinkInterface.h>
00035 #include <casa/Containers/Block.h>
00036 #include <casa/BasicSL/String.h>
00037 
00038 namespace casa { //# NAMESPACE CASA - BEGIN
00039 
00040 //# Forward Declarations
00041 
00042 // <summary>
00043 // Save log messages in memory.
00044 // </summary>
00045 
00046 // <use visibility=export>
00047 
00048 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tLogging.cc" demos="dLogging.cc">
00049 // </reviewed>
00050 
00051 // <prerequisite>
00052 //   <li> <linkto class=LogSinkInterface>LogSinkInterface</linkto>
00053 // </prerequisite>
00054 //
00055 // <synopsis>
00056 // This class posts messages which pass the filter to 
00057 // memory.
00058 // </synopsis>
00059 //
00060 // <example>
00061 // See <linkto file="Logging.h">Logging.h</linkto>.
00062 // </example>
00063 //
00064 // <motivation>
00065 // For temporary images log messages must be held in memory temporarily.
00066 // </motivation>
00067 //
00068 //# <todo asof="2001/06/12">
00069 //# </todo>
00070 
00071 class MemoryLogSink : public LogSinkInterface
00072 {
00073 public:
00074   // Create an empty sink without a filter.
00075   MemoryLogSink();
00076 
00077   // Create an empty sink with the given filter.
00078   // <group>
00079   explicit MemoryLogSink (LogMessage::Priority filter);
00080   explicit MemoryLogSink (const LogFilterInterface& filter);
00081   // </group>
00082 
00083   // Copy constructor (copy semantics).
00084   MemoryLogSink (const MemoryLogSink& other);
00085 
00086   // Assignment (copy semantics).
00087   MemoryLogSink& operator= (const MemoryLogSink& other);
00088   
00089   virtual ~MemoryLogSink();
00090 
00091   // Get number of messages in sink.
00092   virtual uInt nelements() const;
00093 
00094   // Get given part of the i-th message from the sink.
00095   // <group>
00096   virtual Double getTime (uInt i) const;
00097   virtual String getPriority (uInt i) const;
00098   virtual String getMessage (uInt i) const;
00099   virtual String getLocation (uInt i) const;
00100   virtual String getObjectID (uInt i) const;
00101   // </group>
00102 
00103   // If the message passes the filter, write it to memory
00104   virtual Bool postLocally (const LogMessage& message);
00105 
00106   // Write a message (usually from another logsink) into the local one.
00107   virtual void writeLocally (Double time, const String& message,
00108                              const String& priority, const String& location,
00109                              const String& objectID);
00110 
00111   // Clear the local sink (i.e. remove all messages from it).
00112   virtual void clearLocally();
00113 
00114   // Returns the id for this class...
00115   static String localId( );
00116   // Returns the id of the LogSink in use...
00117   String id( ) const;
00118 
00119 private:
00120   // Avoid duplicating code in copy ctor and assignment operator
00121   void copy_other (const MemoryLogSink& other);
00122 
00123   // Rezize the blocks to the given size, but at least 64 elements
00124   // more than the current size.
00125   void resize (uInt nrnew);
00126 
00127   uInt          nmsg_p;
00128   Block<Double> time_p;
00129   Block<String> priority_p;
00130   Block<String> message_p;
00131   Block<String> location_p;
00132   Block<String> objectID_p;
00133 };
00134 
00135 
00136 
00137 } //# NAMESPACE CASA - END
00138 
00139 #endif