casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
DataConversion.h
Go to the documentation of this file.
00001 //# DataConversion.h: Abstract base class with functions to convert any 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: DataConversion.h 20551 2009-03-25 00:11:33Z Malte.Marquarding $
00027 
00028 #ifndef CASA_DATACONVERSION_H
00029 #define CASA_DATACONVERSION_H
00030 
00031 //# Includes
00032 #include <casa/aips.h>
00033 #include <casa/OS/Conversion.h>
00034 
00035 namespace casa { //# NAMESPACE CASA - BEGIN
00036 
00037 // <summary>
00038 // Abstract base class with functions to convert any format
00039 // </summary>
00040 
00041 // <use visibility=export>
00042 
00043 // <reviewed reviewer="Friso Olnon" date="1996/11/06" tests="tDataConversion" demos="">
00044 // </reviewed>
00045 
00046 // <synopsis>
00047 // This abstract base class contains pure virtual functions to convert
00048 // from any foreign data format to local format and vice-versa.
00049 // Classes derived from it implement the functions for a specific
00050 // foreign format (e.g.
00051 // <linkto class=CanonicalDataConversion:description>CanonicalDataConversion
00052 // </linkto>,
00053 // <linkto class=VAXDataConversion:description>VAXDataConversion</linkto>,
00054 // <linkto class=IBMDataConversion:description>IBMDataConversion</linkto>).
00055 // <linkto class=RawDataConversion:description>RawDataConversion</linkto>).
00056 // </synopsis>
00057 
00058 // <example>
00059 // <srcblock>
00060 // // Construct the correct conversion object.
00061 // DataConversion* conv = new IBMDataConversion();
00062 // // Say that you read a block of 256 floats (in IBM-format).
00063 // char buffer[1024];
00064 // read (fd, buffer, 1024);
00065 // // Convert the float to local format.
00066 // float values[256];
00067 // conv->toLocal (values, buffer, 256);
00068 // </srcblock>
00069 // </example>
00070 
00071 // <motivation>
00072 // The abstract base class allows one to construct the correct conversion
00073 // object at the beginning. Thereafter this base class can be used and
00074 // polymorphism takes care of picking the correct functions.
00075 // </motivation>
00076 
00077 // <todo asof="$DATE$">
00078 //  <li> Support data type long double.
00079 // </todo>
00080 
00081 
00082 class DataConversion
00083 {
00084 public:
00085     // Construct the object.
00086     DataConversion();
00087 
00088     virtual ~DataConversion();
00089 
00090     // Convert one value from foreign format to local format.
00091     // The from and to buffer should not overlap.
00092     // <note>
00093     // The char version handles characters (thus may involve conversion
00094     // EBCDIC to ASCII), while the unsigned chars are simply bytes.
00095     // </note>
00096     // <group>
00097     virtual unsigned int toLocal (char&           to,
00098                                   const void* from) const = 0;
00099     virtual unsigned int toLocal (unsigned char&  to,
00100                                   const void* from) const = 0;
00101     virtual unsigned int toLocal (short&          to,
00102                                   const void* from) const = 0;
00103     virtual unsigned int toLocal (unsigned short& to,
00104                                   const void* from) const = 0;
00105     virtual unsigned int toLocal (int&            to,
00106                                   const void* from) const = 0;
00107     virtual unsigned int toLocal (unsigned int&   to,
00108                                   const void* from) const = 0;
00109     virtual unsigned int toLocal (Int64&          to,
00110                                   const void* from) const = 0;
00111     virtual unsigned int toLocal (uInt64&         to,
00112                                   const void* from) const = 0;
00113     virtual unsigned int toLocal (float&          to,
00114                                   const void* from) const = 0;
00115     virtual unsigned int toLocal (double&         to,
00116                                   const void* from) const = 0;
00117     // </group>
00118     
00119     // Convert nr values from foreign format to local format.
00120     // The from and to buffer should not overlap.
00121     // <note>
00122     // The char version handles characters (thus may involve conversion
00123     // EBCDIC to ASCII), while the unsigned chars are simply bytes.
00124     // </note>
00125     // <group>
00126     virtual unsigned int toLocal (char*           to, const void* from,
00127                                   unsigned int nr) const = 0;
00128     virtual unsigned int toLocal (unsigned char*  to, const void* from,
00129                                   unsigned int nr) const = 0;
00130     virtual unsigned int toLocal (short*          to, const void* from,
00131                                   unsigned int nr) const = 0;
00132     virtual unsigned int toLocal (unsigned short* to, const void* from,
00133                                   unsigned int nr) const = 0;
00134     virtual unsigned int toLocal (int*            to, const void* from,
00135                                   unsigned int nr) const = 0;
00136     virtual unsigned int toLocal (unsigned int*   to, const void* from,
00137                                   unsigned int nr) const = 0;
00138     virtual unsigned int toLocal (Int64*          to, const void* from,
00139                                   unsigned int nr) const = 0;
00140     virtual unsigned int toLocal (uInt64*         to, const void* from,
00141                                   unsigned int nr) const = 0;
00142     virtual unsigned int toLocal (float*          to, const void* from,
00143                                   unsigned int nr) const = 0;
00144     virtual unsigned int toLocal (double*         to, const void* from,
00145                                   unsigned int nr) const = 0;
00146     // </group>
00147 
00148     // Convert one value from local format to foreign format.
00149     // The from and to buffer should not overlap.
00150     // <note>
00151     // The char version handles characters (thus may involve conversion
00152     // ASCII to EBCDIC), while the unsigned chars are simply bytes.
00153     // </note>
00154     // <group>
00155     virtual unsigned int fromLocal (void* to, char           from) const = 0;
00156     virtual unsigned int fromLocal (void* to, unsigned char  from) const = 0;
00157     virtual unsigned int fromLocal (void* to, short          from) const = 0;
00158     virtual unsigned int fromLocal (void* to, unsigned short from) const = 0;
00159     virtual unsigned int fromLocal (void* to, int            from) const = 0;
00160     virtual unsigned int fromLocal (void* to, unsigned int   from) const = 0;
00161     virtual unsigned int fromLocal (void* to, Int64          from) const = 0;
00162     virtual unsigned int fromLocal (void* to, uInt64         from) const = 0;
00163     virtual unsigned int fromLocal (void* to, float          from) const = 0;
00164     virtual unsigned int fromLocal (void* to, double         from) const = 0;
00165     // </group>
00166     
00167     // Convert nr values from local format to foreign format.
00168     // The from and to buffer should not overlap.
00169     // <note>
00170     // The char version handles characters (thus may involve conversion
00171     // ASCII to EBCDIC), while the unsigned chars are simply bytes.
00172     // </note>
00173     // <group>
00174     virtual unsigned int fromLocal (void* to, const char*           from,
00175                                     unsigned int nr) const = 0;
00176     virtual unsigned int fromLocal (void* to, const unsigned char*  from,
00177                                     unsigned int nr) const = 0;
00178     virtual unsigned int fromLocal (void* to, const short*          from,
00179                                     unsigned int nr) const = 0;
00180     virtual unsigned int fromLocal (void* to, const unsigned short* from,
00181                                     unsigned int nr) const = 0;
00182     virtual unsigned int fromLocal (void* to, const int*            from,
00183                                     unsigned int nr) const = 0;
00184     virtual unsigned int fromLocal (void* to, const unsigned int*   from,
00185                                     unsigned int nr) const = 0;
00186     virtual unsigned int fromLocal (void* to, const Int64*          from,
00187                                     unsigned int nr) const = 0;
00188     virtual unsigned int fromLocal (void* to, const uInt64*         from,
00189                                     unsigned int nr) const = 0;
00190     virtual unsigned int fromLocal (void* to, const float*          from,
00191                                     unsigned int nr) const = 0;
00192     virtual unsigned int fromLocal (void* to, const double*         from,
00193                                     unsigned int nr) const = 0;
00194     // </group>
00195 
00196     // Determine if the data for a data type can be simply copied, thus
00197     // if no conversion is needed.
00198     // <group>
00199     virtual Bool canCopy (const char*) const = 0;
00200     virtual Bool canCopy (const unsigned char*) const = 0;
00201     virtual Bool canCopy (const short*) const = 0;
00202     virtual Bool canCopy (const unsigned short*) const = 0;
00203     virtual Bool canCopy (const int*) const = 0;
00204     virtual Bool canCopy (const unsigned int*) const = 0;
00205     virtual Bool canCopy (const Int64*) const = 0;
00206     virtual Bool canCopy (const uInt64*) const = 0;
00207     virtual Bool canCopy (const float*) const = 0;
00208     virtual Bool canCopy (const double*) const = 0;
00209     // </group>
00210 
00211     // Get the external size of the data type.
00212     // <group>
00213     virtual unsigned int externalSize (const char*) const = 0;
00214     virtual unsigned int externalSize (const unsigned char*) const = 0;
00215     virtual unsigned int externalSize (const short*) const = 0;
00216     virtual unsigned int externalSize (const unsigned short*) const = 0;
00217     virtual unsigned int externalSize (const int*) const = 0;
00218     virtual unsigned int externalSize (const unsigned int*) const = 0;
00219     virtual unsigned int externalSize (const Int64*) const = 0;
00220     virtual unsigned int externalSize (const uInt64*) const = 0;
00221     virtual unsigned int externalSize (const float*) const = 0;
00222     virtual unsigned int externalSize (const double*) const = 0;
00223     // </group>
00224 };
00225 
00226 
00227 inline DataConversion::DataConversion()
00228 {}
00229 
00230 
00231 
00232 } //# NAMESPACE CASA - END
00233 
00234 #endif