casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
ByteSink.h
Go to the documentation of this file.
00001 //# ByteSink.h: Class for write-only access to data in a given format
00002 //# Copyright (C) 1996,1998,1999,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 //# $Id: ByteSink.h 20551 2009-03-25 00:11:33Z Malte.Marquarding $
00027 
00028 #ifndef CASA_BYTESINK_H
00029 #define CASA_BYTESINK_H
00030 
00031 #include <casa/aips.h>
00032 #include <casa/IO/BaseSinkSource.h>
00033 //# The following should be a forward declaration. But our Complex & DComplex
00034 //# classes are a typedef hence this does not work. Replace the following with
00035 //# forward declarations when Complex and DComplex are no longer typedefs.
00036 #include <casa/BasicSL/Complex.h>
00037 
00038 namespace casa { //# NAMESPACE CASA - BEGIN
00039 
00040 class TypeIO;
00041 class String;
00042 
00043 // <summary>Class for write-only access to data in a given format.</summary>
00044 
00045 // <use visibility=export>
00046 
00047 // <reviewed reviewer="Friso Olnon" date="1996/11/06" tests="tByteSink" demos="">
00048 // </reviewed>
00049 
00050 // <prerequisite> 
00051 //    <li> <linkto class=BaseSinkSource>BaseSinkSource</linkto> class
00052 //    <li> <linkto class=TypeIO>TypeIO</linkto> class and derived classes
00053 // </prerequisite> 
00054 
00055 // <etymology> 
00056 // A sink is the place where bytes are written to.
00057 // </etymology>
00058 
00059 // <synopsis> 
00060 // ByteSink provides write-only access to a typed byte stream in the
00061 // AIPS++ IO framework. The base class <src>BaseSinkSource</src>
00062 // contains common functions like <src>seek</src>.
00063 // <p>
00064 // The object is constructed using a typed byte stream. This stream
00065 // is an instance of a class derived from class
00066 // <linkto class=TypeIO>TypeIO</linkto>. This makes it possible to
00067 // store the data in any format (e.g. CanonicalIO or RawIO).
00068 // <br> In its turn TypeIO uses an instance of a class derived from class
00069 // <linkto class=ByteIO>ByteIO</linkto>. This makes it possible to
00070 // use any output stream (e.g. file, memory).
00071 // <p>
00072 // Note that in general <src>ByteSink</src> will only be used
00073 // for write-only streams like sockets or pipes.
00074 // Class <linkto class=ByteSinkSource>ByteSinkSource</linkto>
00075 // is the obvious choice for read/write streams.
00076 // </synopsis>
00077 
00078 // <example>
00079 // <srcblock>
00080 //    // Construct the correct output stream.
00081 //    MemoryIO memio;
00082 //    CanonicalIO canio (&memio);
00083 //    ByteSink sink (&canio);
00084 //    // Write data.
00085 //    Int vali;
00086 //    sink << vali << True;
00087 // </srcblock>
00088 // </example>
00089 
00090 // <motivation> 
00091 // This class makes it possible to deny read-access to an IO stream.
00092 // </motivation>
00093 
00094 
00095 class ByteSink: virtual public BaseSinkSource
00096 {
00097 public: 
00098     // Default constructor.
00099     // This creates an invalid object, but is present for convenience.
00100     ByteSink();
00101 
00102     // Construct from given TypeIO object.  The constructor does not copy the
00103     // object, but only keeps a pointer to it. If takeOver is true the this
00104     // class will delete the supplied pointer. Otherwise the caller is
00105     // responsible for this.
00106     ByteSink (TypeIO* typeIO, Bool takeOver=False);
00107  
00108     // The copy constructor uses reference semantics
00109     ByteSink (const ByteSink& sink);
00110 
00111     // The assignment operator uses reference semantics
00112     ByteSink& operator= (const ByteSink& sink);
00113 
00114     // destructor
00115     ~ByteSink();
00116 
00117     // These functions write one value of the given type.
00118     // If this function does not succeed, an exception will be thrown.
00119     // <group>
00120     ByteSink& operator<< (Bool value);
00121     ByteSink& operator<< (Char value);
00122     ByteSink& operator<< (uChar value);
00123     ByteSink& operator<< (Short value);
00124     ByteSink& operator<< (uShort value);
00125     ByteSink& operator<< (Int value);
00126     ByteSink& operator<< (uInt value);
00127     ByteSink& operator<< (Int64 value);
00128     ByteSink& operator<< (uInt64 value);
00129     ByteSink& operator<< (Float value);
00130     ByteSink& operator<< (Double value);
00131     ByteSink& operator<< (const Complex& value);
00132     ByteSink& operator<< (const DComplex& value);
00133     ByteSink& operator<< (const String& value);
00134     ByteSink& operator<< (const Char* value);
00135     // </group>
00136 
00137     // These functions write multiple values of the given type.
00138     // If this function does not succeed, an exception will be thrown.
00139     // <group>
00140     void write (uInt nvalues, const Bool* value);
00141     void write (uInt nvalues, const Char* value);
00142     void write (uInt nvalues, const uChar* value);
00143     void write (uInt nvalues, const Short* value);
00144     void write (uInt nvalues, const uShort* value);
00145     void write (uInt nvalues, const Int* value);
00146     void write (uInt nvalues, const uInt* value);
00147     void write (uInt nvalues, const Int64* value);
00148     void write (uInt nvalues, const uInt64* value);
00149     void write (uInt nvalues, const Float* value);
00150     void write (uInt nvalues, const Double* value);
00151     void write (uInt nvalues, const Complex* value);
00152     void write (uInt nvalues, const DComplex* value);
00153     void write (uInt nvalues, const String* value);
00154      // </group>
00155 };
00156 
00157 
00158 
00159 } //# NAMESPACE CASA - END
00160 
00161 #endif