casacore
Loading...
Searching...
No Matches
ConversionIO.h
Go to the documentation of this file.
1// # ConversionIO.h: Class for IO in a converted format
2// # Copyright (C) 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_CONVERSIONIO_H
27#define CASA_CONVERSIONIO_H
28
29#include <casacore/casa/aips.h>
30#include <casacore/casa/IO/TypeIO.h>
31#include <memory>
32// # The following should be a declaration. But our Complex & DComplex classes
33// # are a typedef hence this does not work. Replace the following with
34// # forward declarations when Complex and DComplex are no longer typedefs.
35#include <casacore/casa/BasicSL/Complex.h>
36
37namespace casacore { // # NAMESPACE CASACORE - BEGIN
38
39class DataConversion;
40class ByteIO;
41class String;
42
43// <summary>Class for IO in a converted format.</summary>
44
45// <use visibility=export>
46
47// <reviewed reviewer="Friso Olnon" date="1996/11/06" tests="tTypeIO" demos="">
48// </reviewed>
49
50// <prerequisite>
51// <li> <linkto class=ByteIO>ByteIO</linkto> class and derived classes
52// <li> <linkto class=TypeIO>TypeIO</linkto>class
53// <li> <linkto class=DataConversion>DataConversion</linkto>
54// </prerequisite>
55
56// <synopsis>
57// ConversionIO is a specialization of class TypeIO to store
58// data in a converted format.
59// <p>
60// The class converts the data to/from external data and reads/writes
61// them from/into the ByteIO object given at construction time.
62// Conversion is only done when really needed. If not needed, the
63// data is directly read or written.
64// <p>
65// This class is useful when data can be stored in one of multiple formats.
66// Only at construction time the correct <linkto class=DataConversion>
67// DataConversion</linkto> class has to be given. Thereafter polymorphism
68// ensures that the correct conversion is done when reading or writing.
69// </synopsis>
70
71class ConversionIO : public TypeIO {
72 public:
73 // Constructor.
74 // The read/write functions will use the given <src>ByteIO</src> object
75 // as the data store and the given <src>DataConversion</src> object
76 // as the conversion engine.
77 // <p>
78 // The read and write functions use an intermediate buffer to hold the data
79 // in canonical format. For small arrays it uses a fixed buffer with
80 // length <src>bufferLength</src>. For arrays not fitting in this buffer,
81 // it uses a temporary buffer allocated on the heap.
82 ConversionIO(const std::shared_ptr<DataConversion>& dataConversion,
83 const std::shared_ptr<ByteIO>& byteIO, uInt bufferLength = 4096);
84
85 // The copy constructor uses reference semantics
86 ConversionIO(const ConversionIO& conversionIO);
87
88 // The assignment operator uses reference semantics
89 ConversionIO& operator=(const ConversionIO& conversionIO);
90
91 // Destructor, deletes allocated memory.
93
94 // Convert the values and write them to the ByteIO object.
95 // Bool, complex and String values are handled by the base class.
96 // <group>
97 virtual size_t write(size_t nvalues, const Bool* value);
98 virtual size_t write(size_t nvalues, const Char* data);
99 virtual size_t write(size_t nvalues, const uChar* data);
100 virtual size_t write(size_t nvalues, const Short* data);
101 virtual size_t write(size_t nvalues, const uShort* data);
102 virtual size_t write(size_t nvalues, const Int* data);
103 virtual size_t write(size_t nvalues, const uInt* data);
104 virtual size_t write(size_t nvalues, const Int64* data);
105 virtual size_t write(size_t nvalues, const uInt64* data);
106 virtual size_t write(size_t nvalues, const Float* data);
107 virtual size_t write(size_t nvalues, const Double* data);
108 virtual size_t write(size_t nvalues, const Complex* value);
109 virtual size_t write(size_t nvalues, const DComplex* value);
110 virtual size_t write(size_t nvalues, const String* value);
111 // </group>
112
113 // Read the values from the ByteIO object and convert them.
114 // Bool, complex and String values are handled by the base class.
115 // <group>
116 virtual size_t read(size_t nvalues, Bool* value);
117 virtual size_t read(size_t nvalues, Char* data);
118 virtual size_t read(size_t nvalues, uChar* data);
119 virtual size_t read(size_t nvalues, Short* data);
120 virtual size_t read(size_t nvalues, uShort* data);
121 virtual size_t read(size_t nvalues, Int* data);
122 virtual size_t read(size_t nvalues, uInt* data);
123 virtual size_t read(size_t nvalues, Int64* data);
124 virtual size_t read(size_t nvalues, uInt64* data);
125 virtual size_t read(size_t nvalues, Float* data);
126 virtual size_t read(size_t nvalues, Double* data);
127 virtual size_t read(size_t nvalues, Complex* value);
128 virtual size_t read(size_t nvalues, DComplex* value);
129 virtual size_t read(size_t nvalues, String* value);
130 // </group>
131
132 private:
133 // Initialize the <src>itsSize</src> and <src>itsCopy</src> variables.
134 void init();
135
136 template <typename T>
137 void initType(uInt& size, Bool& copy) const;
138
139 template <typename T>
140 size_t writeGeneric(size_t nvalues, const T* value, size_t type_size, bool copy);
141 template <typename T>
142 size_t readGeneric(size_t nvalues, T* value, size_t type_size, bool copy);
143
144 // # The data.
145 std::shared_ptr<DataConversion> itsConversion;
166 // # The buffer
169};
170
171} // namespace casacore
172
173#endif
ConversionIO(const std::shared_ptr< DataConversion > &dataConversion, const std::shared_ptr< ByteIO > &byteIO, uInt bufferLength=4096)
Constructor.
virtual size_t read(size_t nvalues, uChar *data)
virtual size_t write(size_t nvalues, const Complex *value)
virtual size_t write(size_t nvalues, const Short *data)
virtual size_t read(size_t nvalues, uInt64 *data)
virtual size_t write(size_t nvalues, const uShort *data)
std::shared_ptr< DataConversion > itsConversion
void init()
Initialize the itsSize and itsCopy variables.
virtual size_t read(size_t nvalues, Bool *value)
Read the values from the ByteIO object and convert them.
virtual size_t write(size_t nvalues, const Double *data)
void initType(uInt &size, Bool &copy) const
virtual size_t read(size_t nvalues, Int *data)
~ConversionIO()
Destructor, deletes allocated memory.
virtual size_t write(size_t nvalues, const uChar *data)
ConversionIO(const ConversionIO &conversionIO)
The copy constructor uses reference semantics.
virtual size_t write(size_t nvalues, const String *value)
virtual size_t read(size_t nvalues, Short *data)
virtual size_t write(size_t nvalues, const Char *data)
virtual size_t read(size_t nvalues, String *value)
virtual size_t write(size_t nvalues, const uInt *data)
virtual size_t read(size_t nvalues, Char *data)
virtual size_t read(size_t nvalues, Double *data)
virtual size_t write(size_t nvalues, const Float *data)
size_t readGeneric(size_t nvalues, T *value, size_t type_size, bool copy)
virtual size_t read(size_t nvalues, Complex *value)
virtual size_t write(size_t nvalues, const DComplex *value)
virtual size_t write(size_t nvalues, const Int64 *data)
virtual size_t write(size_t nvalues, const Bool *value)
Convert the values and write them to the ByteIO object.
size_t writeGeneric(size_t nvalues, const T *value, size_t type_size, bool copy)
virtual size_t read(size_t nvalues, Float *data)
ConversionIO & operator=(const ConversionIO &conversionIO)
The assignment operator uses reference semantics.
virtual size_t read(size_t nvalues, uShort *data)
virtual size_t read(size_t nvalues, Int64 *data)
virtual size_t read(size_t nvalues, uInt *data)
virtual size_t read(size_t nvalues, DComplex *value)
virtual size_t write(size_t nvalues, const Int *data)
virtual size_t write(size_t nvalues, const uInt64 *data)
String: the storage and methods of handling collections of characters.
Definition String.h:355
const ByteIO & byteIO() const
Functions to return a reference to the ByteIO class.
TypeIO(const std::shared_ptr< ByteIO > &byteIO)
Constructor.
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
unsigned char uChar
Definition aipstype.h:45
short Short
Definition aipstype.h:46
unsigned int uInt
Definition aipstype.h:49
unsigned short uShort
Definition aipstype.h:47
void copy(double *target, int npixels) const
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size).
Definition aipsxtype.h:36
float Float
Definition aipstype.h:52
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
size_t size() const
Definition Block.h:566
NewDelAllocator< T > NewDelAllocator< T >::value
Definition Allocator.h:360
double Double
Definition aipstype.h:53
char Char
Definition aipstype.h:44
unsigned long long uInt64
Definition aipsxtype.h:37