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
33namespace casacore { // # NAMESPACE CASACORE - BEGIN
34
35// <summary>
36// Templated functions to get/put a C-style array from/into AipsIO.
37// </summary>
38
39// <use visibility=export>
40
41// <reviewed reviewer="Gareth Hunt" date="95Feb24" tests="" demos="">
42
43// <prerequisite>
44// <li> <linkto class="AipsIO:description">AipsIO</linkto>
45// </prerequisite>
46
47// <etymology>
48// AipsIOCarray is simply the conventional shorthand for "aips input/output for
49// C-style arrays".
50// </etymology>
51
52// <synopsis>
53// This file declares templated functions to get or put a C-style array
54// of any data type from/into AipsIO.
55// These functions are similar to the AipsIO functions put, get and getnew,
56// but support any data type.
57//
58// Specializations (using these AipsIO functions) are made for
59// the standard data types. These are much more efficient.
60// </synopsis>
61
62// <example>
63// <srcblock>
64// // Write an C-style array of type A into AipsIO.
65// // This will first write the number of elements.
66// {
67// A ap[1000];
68// AipsIO io ("file.data", ByteIO::New);
69// io.putstart ("some",1);
70// putAipsIO (io, uInt(1000), ap);
71// io.putend();
72// }
73// // Read the data back into a preallocated array.
74// // First the number of elements have to be read.
75// {
76// A api[1000];
77// uInt n;
78// AipsIO io ("file.data");
79// io.getstart ("some");
80// io >> n;
81// getAipsIO (io, n, api);
82// }
83// // Read the data back into an automatically allocated array.
84// // This will also read the number of elements.
85// // Delete the allocated array at the end.
86// {
87// A* api;
88// uInt n;
89// AipsIO io ("file.data");
90// io.getstart ("some");
91// getnewAipsIO (io, n, &api);
92// delete [] api;
93// }
94// </srcblock>
95// </example>
96
97// <group name=AipsIOCarray>
99// Put a C-style array of n elements.
100// First the number of elements is put, thereafter all values.
101template <class T>
102void putAipsIO(AipsIO& aios, uInt n, const T* data);
103
104// Get n elements into an already available C-style array.
105// The data buffer must be large enough to hold n values.
106template <class T>
107void getAipsIO(AipsIO& aios, uInt n, T* data);
108
109// Get elements into a C-style array to be allocated on the heap.
110// First the number of elements will be read. The array will be allocated
111// by this function and must be freed by the user. Its pointer is returned
112// in data. The number of elements is returned in n.
113//
114// <note>
115// Unfortunately the CFront compiler (and maybe others as well) fail to
116// overload on <src>T*& data</src> iso. <src>T** data</src>.
117// </note>
118template <class T>
119void getnewAipsIO(AipsIO& aios, uInt& n, T** data);
120
121// </group>
122
123// # Specializations for the builtin data types.
124#define AIPSIO_FUNC_SPEC(T) \
125 inline void putAipsIO(AipsIO& aios, uInt n, const T* data) { aios.put(n, data); } \
126 inline void getAipsIO(AipsIO& aios, uInt n, T* data) { aios.get(n, data); } \
127 inline void getnewAipsIO(AipsIO& aios, uInt& n, T** data) { aios.getnew(n, *data); }
128
129// # These macros expand to generate the appropriate inline functions
130// # for the built-in data types.
131
135AIPSIO_FUNC_SPEC(short)
136AIPSIO_FUNC_SPEC(unsigned short)
138AIPSIO_FUNC_SPEC(unsigned int)
141AIPSIO_FUNC_SPEC(float)
142AIPSIO_FUNC_SPEC(double)
143AIPSIO_FUNC_SPEC(Complex)
144AIPSIO_FUNC_SPEC(DComplex)
145AIPSIO_FUNC_SPEC(String)
146
147} // namespace casacore
148
149#ifndef CASACORE_NO_AUTO_TEMPLATES
150#include <casacore/casa/IO/AipsIOCarray.tcc>
151#endif // # CASACORE_NO_AUTO_TEMPLATES
152#endif
#define AIPSIO_FUNC_SPEC(T)
For temporary backward namespace compatibility, use casa as alias for casacore.
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.