00001 //# AipsIOCarray.h: Templated functions to get/put a C-array from/into AipsIO. 00002 //# Copyright (C) 1993,1994,1995,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$ 00027 00028 #ifndef CASA_AIPSIOCARRAY_H 00029 #define CASA_AIPSIOCARRAY_H 00030 00031 //# Includes 00032 #include <casacore/casa/aips.h> 00033 #include <casacore/casa/IO/AipsIO.h> 00034 00035 00036 namespace casacore { //# NAMESPACE CASACORE - BEGIN 00037 00038 // <summary> 00039 // Templated functions to get/put a C-style array from/into AipsIO. 00040 // </summary> 00041 00042 // <use visibility=export> 00043 00044 // <reviewed reviewer="Gareth Hunt" date="95Feb24" tests="" demos=""> 00045 00046 // <prerequisite> 00047 // <li> <linkto class="AipsIO:description">AipsIO</linkto> 00048 // </prerequisite> 00049 00050 // <etymology> 00051 // AipsIOCarray is simply the conventional shorthand for "aips input/output for 00052 // C-style arrays". 00053 // </etymology> 00054 00055 // <synopsis> 00056 // This file declares templated functions to get or put a C-style array 00057 // of any data type from/into AipsIO. 00058 // These functions are similar to the AipsIO functions put, get and getnew, 00059 // but support any data type. 00060 // 00061 // Specializations (using these AipsIO functions) are made for 00062 // the standard data types. These are much more efficient. 00063 // </synopsis> 00064 00065 // <example> 00066 // <srcblock> 00067 // // Write an C-style array of type A into AipsIO. 00068 // // This will first write the number of elements. 00069 // { 00070 // A ap[1000]; 00071 // AipsIO io ("file.data", ByteIO::New); 00072 // io.putstart ("some",1); 00073 // putAipsIO (io, uInt(1000), ap); 00074 // io.putend(); 00075 // } 00076 // // Read the data back into a preallocated array. 00077 // // First the number of elements have to be read. 00078 // { 00079 // A api[1000]; 00080 // uInt n; 00081 // AipsIO io ("file.data"); 00082 // io.getstart ("some"); 00083 // io >> n; 00084 // getAipsIO (io, n, api); 00085 // } 00086 // // Read the data back into an automatically allocated array. 00087 // // This will also read the number of elements. 00088 // // Delete the allocated array at the end. 00089 // { 00090 // A* api; 00091 // uInt n; 00092 // AipsIO io ("file.data"); 00093 // io.getstart ("some"); 00094 // getnewAipsIO (io, n, &api); 00095 // delete [] api; 00096 // } 00097 // </srcblock> 00098 // </example> 00099 00100 00101 // <group name=AipsIOCarray> 00102 00103 // Put a C-style array of n elements. 00104 // First the number of elements is put, thereafter all values. 00105 template<class T> 00106 void putAipsIO (AipsIO& aios, uInt n, const T* data); 00107 00108 // Get n elements into an already available C-style array. 00109 // The data buffer must be large enough to hold n values. 00110 template<class T> 00111 void getAipsIO (AipsIO& aios, uInt n, T* data); 00112 00113 // Get elements into a C-style array to be allocated on the heap. 00114 // First the number of elements will be read. The array will be allocated 00115 // by this function and must be freed by the user. Its pointer is returned 00116 // in data. The number of elements is returned in n. 00117 // 00118 // <note> 00119 // Unfortunately the CFront compiler (and maybe others as well) fail to 00120 // overload on <src>T*& data</src> iso. <src>T** data</src>. 00121 // </note> 00122 template<class T> 00123 void getnewAipsIO (AipsIO& aios, uInt& n, T** data); 00124 00125 // </group> 00126 00127 00128 //# Specializations for the builtin data types. 00129 #define AIPSIO_FUNC_SPEC(T) \ 00130 inline void putAipsIO (AipsIO& aios, uInt n, const T* data) \ 00131 { aios.put (n, data); } \ 00132 inline void getAipsIO (AipsIO& aios, uInt n, T* data) \ 00133 { aios.get (n, data); } \ 00134 inline void getnewAipsIO (AipsIO& aios, uInt& n, T** data) \ 00135 { aios.getnew (n, *data); } 00136 00137 //# These macros expand to generate the appropriate inline functions 00138 //# for the built-in data types. 00139 00140 AIPSIO_FUNC_SPEC(Bool) 00141 AIPSIO_FUNC_SPEC(Char) 00142 AIPSIO_FUNC_SPEC(uChar) 00143 AIPSIO_FUNC_SPEC(short) 00144 AIPSIO_FUNC_SPEC(unsigned short) 00145 AIPSIO_FUNC_SPEC(int) 00146 AIPSIO_FUNC_SPEC(unsigned int) 00147 AIPSIO_FUNC_SPEC(Int64) 00148 AIPSIO_FUNC_SPEC(uInt64) 00149 AIPSIO_FUNC_SPEC(float) 00150 AIPSIO_FUNC_SPEC(double) 00151 AIPSIO_FUNC_SPEC(Complex) 00152 AIPSIO_FUNC_SPEC(DComplex) 00153 AIPSIO_FUNC_SPEC(String) 00154 00155 00156 00157 } //# NAMESPACE CASACORE - END 00158 00159 #ifndef CASACORE_NO_AUTO_TEMPLATES 00160 #include <casacore/casa/IO/AipsIOCarray.tcc> 00161 #endif //# CASACORE_NO_AUTO_TEMPLATES 00162 #endif