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