casacore
Loading...
Searching...
No Matches
AipsIOCarray.h
Go to the documentation of this file.
1//# AipsIOCarray.h: Templated functions to get/put a C-array from/into AipsIO.
2//# Copyright (C) 1993,1994,1995,1996,1999,2001
3//# Associated Universities, Inc. Washington DC, USA.
4//#
5//# This library is free software; you can redistribute it and/or modify it
6//# under the terms of the GNU Library General Public License as published by
7//# the Free Software Foundation; either version 2 of the License, or (at your
8//# option) any later version.
9//#
10//# This library is distributed in the hope that it will be useful, but WITHOUT
11//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12//# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13//# License for more details.
14//#
15//# You should have received a copy of the GNU Library General Public License
16//# along with this library; if not, write to the Free Software Foundation,
17//# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18//#
19//# Correspondence concerning AIPS++ should be addressed as follows:
20//# Internet email: casa-feedback@nrao.edu.
21//# Postal address: AIPS++ Project Office
22//# National Radio Astronomy Observatory
23//# 520 Edgemont Road
24//# Charlottesville, VA 22903-2475 USA
25
26#ifndef CASA_AIPSIOCARRAY_H
27#define CASA_AIPSIOCARRAY_H
28
29//# Includes
30#include <casacore/casa/aips.h>
31#include <casacore/casa/IO/AipsIO.h>
32
33
34namespace casacore { //# NAMESPACE CASACORE - BEGIN
35
36// <summary>
37// Templated functions to get/put a C-style array from/into AipsIO.
38// </summary>
39
40// <use visibility=export>
41
42// <reviewed reviewer="Gareth Hunt" date="95Feb24" tests="" demos="">
43
44// <prerequisite>
45// <li> <linkto class="AipsIO:description">AipsIO</linkto>
46// </prerequisite>
47
48// <etymology>
49// AipsIOCarray is simply the conventional shorthand for "aips input/output for
50// C-style arrays".
51// </etymology>
52
53// <synopsis>
54// This file declares templated functions to get or put a C-style array
55// of any data type from/into AipsIO.
56// These functions are similar to the AipsIO functions put, get and getnew,
57// but support any data type.
58//
59// Specializations (using these AipsIO functions) are made for
60// the standard data types. These are much more efficient.
61// </synopsis>
62
63// <example>
64// <srcblock>
65// // Write an C-style array of type A into AipsIO.
66// // This will first write the number of elements.
67// {
68// A ap[1000];
69// AipsIO io ("file.data", ByteIO::New);
70// io.putstart ("some",1);
71// putAipsIO (io, uInt(1000), ap);
72// io.putend();
73// }
74// // Read the data back into a preallocated array.
75// // First the number of elements have to be read.
76// {
77// A api[1000];
78// uInt n;
79// AipsIO io ("file.data");
80// io.getstart ("some");
81// io >> n;
82// getAipsIO (io, n, api);
83// }
84// // Read the data back into an automatically allocated array.
85// // This will also read the number of elements.
86// // Delete the allocated array at the end.
87// {
88// A* api;
89// uInt n;
90// AipsIO io ("file.data");
91// io.getstart ("some");
92// getnewAipsIO (io, n, &api);
93// delete [] api;
94// }
95// </srcblock>
96// </example>
97
98
99// <group name=AipsIOCarray>
101// Put a C-style array of n elements.
102// First the number of elements is put, thereafter all values.
103template<class T>
104void putAipsIO (AipsIO& aios, uInt n, const T* data);
105
106// Get n elements into an already available C-style array.
107// The data buffer must be large enough to hold n values.
108template<class T>
109void getAipsIO (AipsIO& aios, uInt n, T* data);
110
111// Get elements into a C-style array to be allocated on the heap.
112// First the number of elements will be read. The array will be allocated
113// by this function and must be freed by the user. Its pointer is returned
114// in data. The number of elements is returned in n.
115//
116// <note>
117// Unfortunately the CFront compiler (and maybe others as well) fail to
118// overload on <src>T*& data</src> iso. <src>T** data</src>.
119// </note>
120template<class T>
121void getnewAipsIO (AipsIO& aios, uInt& n, T** data);
122
123// </group>
124
125
126//# Specializations for the builtin data types.
127#define AIPSIO_FUNC_SPEC(T) \
128inline void putAipsIO (AipsIO& aios, uInt n, const T* data) \
129 { aios.put (n, data); } \
130inline void getAipsIO (AipsIO& aios, uInt n, T* data) \
131 { aios.get (n, data); } \
132inline void getnewAipsIO (AipsIO& aios, uInt& n, T** data) \
133 { aios.getnew (n, *data); }
134
135//# These macros expand to generate the appropriate inline functions
136//# for the built-in data types.
137
141AIPSIO_FUNC_SPEC(short)
142AIPSIO_FUNC_SPEC(unsigned short)
144AIPSIO_FUNC_SPEC(unsigned int)
147AIPSIO_FUNC_SPEC(float)
148AIPSIO_FUNC_SPEC(double)
149AIPSIO_FUNC_SPEC(Complex)
150AIPSIO_FUNC_SPEC(DComplex)
151AIPSIO_FUNC_SPEC(String)
152
153
154
155} //# NAMESPACE CASACORE - END
156
157#ifndef CASACORE_NO_AUTO_TEMPLATES
158#include <casacore/casa/IO/AipsIOCarray.tcc>
159#endif //# CASACORE_NO_AUTO_TEMPLATES
160#endif
#define AIPSIO_FUNC_SPEC(T)
this file contains all the compiler specific defines
Definition mainpage.dox:28
unsigned char uChar
Definition aipstype.h:45
unsigned int uInt
Definition aipstype.h:49
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size)
Definition aipsxtype.h:36
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
char Char
Definition aipstype.h:44
unsigned long long uInt64
Definition aipsxtype.h:37
void getnewAipsIO(AipsIO &aios, uInt &n, T **data)
Get elements into a C-style array to be allocated on the heap.
void getAipsIO(AipsIO &aios, uInt n, T *data)
Get n elements into an already available C-style array.
void putAipsIO(AipsIO &aios, uInt n, const T *data)
Put a C-style array of n elements.