casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
TypeIO.h
Go to the documentation of this file.
00001 //# TypeIO.h: Abstract base class for IO of data in a type-dependent 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: TypeIO.h 20551 2009-03-25 00:11:33Z Malte.Marquarding $
00027 
00028 #ifndef CASA_TYPEIO_H
00029 #define CASA_TYPEIO_H
00030 
00031 #include <casa/aips.h>
00032 #include <casa/IO/ByteIO.h>
00033 #include <casa/Utilities/CountedPtr.h>
00034 //# The following should be a forward declaration. But our Complex & DComplex
00035 //# classes are a typedef hence this does not work. Replace the following with
00036 //# forward declarations when Complex and DComplex are no longer typedefs.
00037 #include <casa/BasicSL/Complex.h>
00038 
00039 namespace casa { //# NAMESPACE CASA - BEGIN
00040 
00041 class String;
00042 
00043 // <summary>Abstract base class for IO of data in a type-dependent format</summary>
00044 
00045 // <use visibility=export>
00046 
00047 // <reviewed reviewer="Friso Olnon" date="1996/11/06" tests="tTypeIO" demos="">
00048 // </reviewed>
00049 
00050 // <prerequisite> 
00051 //    <li> <linkto class=ByteIO>ByteIO</linkto> class and derived classes
00052 // </prerequisite>
00053 
00054 // <synopsis> 
00055 // This class is the abstract base class for doing IO in a type-dependent
00056 // way. Derived from it are classes like <linkto class=CanonicalIO>
00057 // CanonicalIO</linkto> doing the actual formatting of the data.
00058 // <p>
00059 // The TypeIO classes convert the data to/from the given format
00060 // using the static conversion functions in the classes like
00061 // <linkto class=CanonicalConversion>CanonicalConversion</linkto>.
00062 // The data is written to or read from the <linkto class=ByteIO>ByteIO</linkto>
00063 // object given when constructing the TypeIO object.
00064 // <p>
00065 // TypeIO declares the virtual functions read and write to read/write
00066 // one or more values of a given data type. Usually the derived classes
00067 // have to implement these functions. An exception are the functions
00068 // handling Bool, complex and String values. These functions have a
00069 // default implementation in this base class. However, if needed
00070 // they can be overwritten in derived classes.
00071 // </synopsis>
00072 
00073 // <motivation> 
00074 // The base class is needed for polymorphic type-dependent IO.
00075 // Furthermore the common functionality can be implemented here.
00076 // </motivation>
00077 
00078 
00079 class TypeIO
00080 {
00081 public: 
00082     // Constructor.
00083     // The read/write functions will use the given ByteIO object
00084     // as the data store.
00085     explicit TypeIO (ByteIO* byteIO, Bool takeOver=False);
00086 
00087     virtual ~TypeIO();
00088     
00089     // Functions to return a reference to the ByteIO class.
00090     // <group>
00091     const ByteIO& byteIO() const;
00092     ByteIO& byteIO();
00093     // </group>
00094 
00095     // Convert the values and write them to the ByteIO object.
00096     // By default Bools are stored as bits, Complex as 2 floats,
00097     // DComplex as 2 doubles and String as a length (uInt) and chars.
00098     // If it does not succeed an exception will be thrown.
00099     // <group>
00100     virtual uInt write (uInt nvalues, const Bool* value);
00101     virtual uInt write (uInt nvalues, const Char* value) = 0;
00102     virtual uInt write (uInt nvalues, const uChar* value) = 0;
00103     virtual uInt write (uInt nvalues, const Short* value) = 0;
00104     virtual uInt write (uInt nvalues, const uShort* value) = 0;
00105     virtual uInt write (uInt nvalues, const Int* value) = 0;
00106     virtual uInt write (uInt nvalues, const uInt* value) = 0;
00107     virtual uInt write (uInt nvalues, const Int64* value) = 0;
00108     virtual uInt write (uInt nvalues, const uInt64* value) = 0;
00109     virtual uInt write (uInt nvalues, const Float* value) = 0;
00110     virtual uInt write (uInt nvalues, const Double* value) = 0;
00111     virtual uInt write (uInt nvalues, const Complex* value);
00112     virtual uInt write (uInt nvalues, const DComplex* value);
00113     virtual uInt write (uInt nvalues, const String* value);
00114     // </group>
00115    
00116     // Read the values from the ByteIO object and convert them.
00117     // By default Bools are stored as bits, Complex as 2 floats,
00118     // DComplex as 2 doubles and String as a length (uInt) and chars.
00119     // If it does not succeed an exception will be thrown.
00120     // <group>
00121     virtual uInt read (uInt nvalues, Bool* value);
00122     virtual uInt read (uInt nvalues, Char* value) = 0;
00123     virtual uInt read (uInt nvalues, uChar* value) = 0;
00124     virtual uInt read (uInt nvalues, Short* value) = 0;
00125     virtual uInt read (uInt nvalues, uShort* value) = 0;
00126     virtual uInt read (uInt nvalues, Int* value) = 0;
00127     virtual uInt read (uInt nvalues, uInt* value) = 0;
00128     virtual uInt read (uInt nvalues, Int64* value) = 0;
00129     virtual uInt read (uInt nvalues, uInt64* value) = 0;
00130     virtual uInt read (uInt nvalues, Float* value) = 0;
00131     virtual uInt read (uInt nvalues, Double* value) = 0;
00132     virtual uInt read (uInt nvalues, Complex* value);
00133     virtual uInt read (uInt nvalues, DComplex* value);
00134     virtual uInt read (uInt nvalues, String* value);
00135     // </group>
00136 
00137     // This function sets the position on the given offset.
00138     // The seek option defines from which file position the seek is done.
00139     // -1 is returned if not seekable.
00140     // <group>
00141     Int64 seek (Int64 offset, ByteIO::SeekOption = ByteIO::Begin);
00142     Int64 seek (Int offset, ByteIO::SeekOption = ByteIO::Begin);
00143     // </group>
00144     
00145     // Is the TypeIO stream readable?
00146     Bool isReadable() const;
00147 
00148     // Is the TypeIO stream writable?
00149     Bool isWritable() const;
00150 
00151     // Is the TypeIO stream seekable?
00152     Bool isSeekable() const;
00153 
00154 protected:    
00155     // This varable keeps a pointer to a ByteIO.
00156     CountedPtr<ByteIO> itsByteIO;
00157 
00158     // The copy constructor uses reference semantics
00159     TypeIO (const TypeIO& TypeIO);
00160 
00161     // The assignment operator uses reference semantics
00162     TypeIO& operator= (const TypeIO& typeIO);
00163 };
00164 
00165 
00166 
00167 
00168 } //# NAMESPACE CASA - END
00169 
00170 #endif