casa
$Rev:20696$
|
00001 //# ConversionIO.h: Class for IO in a converted 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: ConversionIO.h 20551 2009-03-25 00:11:33Z Malte.Marquarding $ 00027 00028 #ifndef CASA_CONVERSIONIO_H 00029 #define CASA_CONVERSIONIO_H 00030 00031 #include <casa/aips.h> 00032 #include <casa/IO/TypeIO.h> 00033 #include <casa/Utilities/CountedPtr.h> 00034 //# The following should be a declaration. But our Complex & DComplex classes 00035 //# 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 DataConversion; 00042 class ByteIO; 00043 class String; 00044 00045 // <summary>Class for IO in a converted format.</summary> 00046 00047 // <use visibility=export> 00048 00049 // <reviewed reviewer="Friso Olnon" date="1996/11/06" tests="tTypeIO" demos=""> 00050 // </reviewed> 00051 00052 // <prerequisite> 00053 // <li> <linkto class=ByteIO>ByteIO</linkto> class and derived classes 00054 // <li> <linkto class=TypeIO>TypeIO</linkto>class 00055 // <li> <linkto class=DataConversion>DataConversion</linkto> 00056 // </prerequisite> 00057 00058 // <synopsis> 00059 // ConversionIO is a specialization of class TypeIO to store 00060 // data in a converted format. 00061 // <p> 00062 // The class converts the data to/from external data and reads/writes 00063 // them from/into the ByteIO object given at construction time. 00064 // Conversion is only done when really needed. If not needed, the 00065 // data is directly read or written. 00066 // <p> 00067 // This class is useful when data can be stored in one of multiple formats. 00068 // Only at construction time the correct <linkto class=DataConversion> 00069 // DataConversion</linkto> class has to be given. Thereafter polymorphism 00070 // ensures that the correct conversion is done when reading or writing. 00071 // </synopsis> 00072 00073 00074 class ConversionIO: public TypeIO 00075 { 00076 public: 00077 // Constructor. 00078 // The read/write functions will use the given <src>ByteIO</src> object 00079 // as the data store and the given <src>DataConversion</src> object 00080 // as the conversion engine. 00081 // <p> 00082 // The read and write functions use an intermediate buffer to hold the data 00083 // in canonical format. For small arrays it uses a fixed buffer with 00084 // length <src>bufferLength</src>. For arrays not fitting in this buffer, 00085 // it uses a temporary buffer allocated on the heap. 00086 // <p> 00087 // If takeOver is True this this class will be responsible for deleting the 00088 // DataConversion and ByteIO pointers. Otherwise it is the callers 00089 // responsibility. 00090 ConversionIO (DataConversion* dataConversion, ByteIO* byteIO, 00091 uInt bufferLength=4096, Bool takeOver=False); 00092 00093 // The copy constructor uses reference semantics 00094 ConversionIO (const ConversionIO& conversionIO); 00095 00096 // The assignment operator uses reference semantics 00097 ConversionIO& operator= (const ConversionIO& conversionIO); 00098 00099 // Destructor, deletes allocated memory. 00100 ~ConversionIO(); 00101 00102 // Convert the values and write them to the ByteIO object. 00103 // Bool, complex and String values are handled by the base class. 00104 // <group> 00105 virtual uInt write (uInt nvalues, const Bool* value); 00106 virtual uInt write (uInt nvalues, const Char* data); 00107 virtual uInt write (uInt nvalues, const uChar* data); 00108 virtual uInt write (uInt nvalues, const Short* data); 00109 virtual uInt write (uInt nvalues, const uShort* data); 00110 virtual uInt write (uInt nvalues, const Int* data); 00111 virtual uInt write (uInt nvalues, const uInt* data); 00112 virtual uInt write (uInt nvalues, const Int64* data); 00113 virtual uInt write (uInt nvalues, const uInt64* data); 00114 virtual uInt write (uInt nvalues, const Float* data); 00115 virtual uInt write (uInt nvalues, const Double* data); 00116 virtual uInt write (uInt nvalues, const Complex* value); 00117 virtual uInt write (uInt nvalues, const DComplex* value); 00118 virtual uInt write (uInt nvalues, const String* value); 00119 // </group> 00120 00121 // Read the values from the ByteIO object and convert them. 00122 // Bool, complex and String values are handled by the base class. 00123 // <group> 00124 virtual uInt read (uInt nvalues, Bool* value); 00125 virtual uInt read (uInt nvalues, Char* data); 00126 virtual uInt read (uInt nvalues, uChar* data); 00127 virtual uInt read (uInt nvalues, Short* data); 00128 virtual uInt read (uInt nvalues, uShort* data); 00129 virtual uInt read (uInt nvalues, Int* data); 00130 virtual uInt read (uInt nvalues, uInt* data); 00131 virtual uInt read (uInt nvalues, Int64* data); 00132 virtual uInt read (uInt nvalues, uInt64* data); 00133 virtual uInt read (uInt nvalues, Float* data); 00134 virtual uInt read (uInt nvalues, Double* data); 00135 virtual uInt read (uInt nvalues, Complex* value); 00136 virtual uInt read (uInt nvalues, DComplex* value); 00137 virtual uInt read (uInt nvalues, String* value); 00138 // </group> 00139 00140 private: 00141 // Initialize the <src>itsSize</src> and <src>itsCopy</src> variables. 00142 void init(); 00143 00144 00145 //# The data. 00146 CountedPtr<DataConversion> itsConversion; 00147 uInt itsSizeChar; 00148 uInt itsSizeuChar; 00149 uInt itsSizeShort; 00150 uInt itsSizeuShort; 00151 uInt itsSizeInt; 00152 uInt itsSizeuInt; 00153 uInt itsSizeInt64; 00154 uInt itsSizeuInt64; 00155 uInt itsSizeFloat; 00156 uInt itsSizeDouble; 00157 Bool itsCopyChar; 00158 Bool itsCopyuChar; 00159 Bool itsCopyShort; 00160 Bool itsCopyuShort; 00161 Bool itsCopyInt; 00162 Bool itsCopyuInt; 00163 Bool itsCopyInt64; 00164 Bool itsCopyuInt64; 00165 Bool itsCopyFloat; 00166 Bool itsCopyDouble; 00167 //# The buffer 00168 char* itsBuffer; 00169 uInt itsBufferLength; 00170 }; 00171 00172 00173 00174 } //# NAMESPACE CASA - END 00175 00176 #endif