casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
ByteSource.h
Go to the documentation of this file.
00001 //# ByteSource.h: Class for read-only access to data in a given format
00002 //# Copyright (C) 1996,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: ByteSource.h 20551 2009-03-25 00:11:33Z Malte.Marquarding $
00027 
00028 #ifndef CASA_BYTESOURCE_H
00029 #define CASA_BYTESOURCE_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 read-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 source is the place where bytes are read from.
00057 // </etymology>
00058 
00059 // <synopsis> 
00060 // ByteSource provides read-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 // read 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 input stream (e.g. file, memory).
00071 // </synopsis>
00072 
00073 // <example>
00074 // <srcblock>
00075 //    // Construct the correct input stream.
00076 //    RegularFileIO filio ("file.name");
00077 //    CanonicalIO canio (&filio);
00078 //    ByteSource source (&canio);
00079 //    // Read data.
00080 //    Int vali;
00081 //    Bool flag;
00082 //    source >> vali >> flag;
00083 // </srcblock>
00084 // </example>
00085 
00086 // <motivation> 
00087 // This class makes it possible to deny write-access to an IO stream.
00088 // </motivation>
00089 
00090 
00091 class ByteSource: virtual public BaseSinkSource
00092 {
00093 public: 
00094     // Default constructor.
00095     // This creates an invalid object, but is present for convenience.
00096     ByteSource();
00097 
00098     // Construct from given TypeIO object.  The constructor does not copy the
00099     // object, but only keeps a pointer to it. If takeOver is true the this
00100     // class will delete the supplied pointer. Otherwise the caller is
00101     // responsible for this.
00102     ByteSource (TypeIO* typeIO, Bool takeOver=False);
00103 
00104     // The copy constructor uses reference semantics
00105     ByteSource (const ByteSource& source);
00106 
00107     // The assignment operator uses reference semantics
00108     ByteSource& operator= (const ByteSource& source);
00109 
00110     // destructor
00111     ~ByteSource();
00112   
00113     // These functions read one value of the given type.
00114     // If this function does not succeed, an exception will be thrown.
00115     // <group>
00116     ByteSource& operator>> (Bool& value);
00117     ByteSource& operator>> (Char& value);
00118     ByteSource& operator>> (uChar& value);
00119     ByteSource& operator>> (Short& value);
00120     ByteSource& operator>> (uShort& value);
00121     ByteSource& operator>> (Int& value);
00122     ByteSource& operator>> (uInt& value);
00123     ByteSource& operator>> (Int64& value);
00124     ByteSource& operator>> (uInt64& value);
00125     ByteSource& operator>> (Float& value);
00126     ByteSource& operator>> (Double& value);
00127     ByteSource& operator>> (Complex& value);
00128     ByteSource& operator>> (DComplex& value);
00129     ByteSource& operator>> (String& value);
00130     // </group>
00131 
00132     // These functions read multiple values of the given type.
00133     // If this function does not succeed, an exception will be thrown.
00134     // <group>
00135     void read (uInt nvalues, Bool* value);
00136     void read (uInt nvalues, Char* value);
00137     void read (uInt nvalues, uChar* value);
00138     void read (uInt nvalues, Short* value);
00139     void read (uInt nvalues, uShort* value);
00140     void read (uInt nvalues, Int* value);
00141     void read (uInt nvalues, uInt* value);
00142     void read (uInt nvalues, Int64* value);
00143     void read (uInt nvalues, uInt64* value);
00144     void read (uInt nvalues, Float* value);
00145     void read (uInt nvalues, Double* value);
00146     void read (uInt nvalues, Complex* value);
00147     void read (uInt nvalues, DComplex* value);
00148     void read (uInt nvalues, String* value);
00149     // </group>
00150 
00151 protected:
00152 };
00153 
00154 
00155 
00156 } //# NAMESPACE CASA - END
00157 
00158 #endif