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
71
72class ConversionIO: public TypeIO
73{
74public:
75 // Constructor.
76 // The read/write functions will use the given <src>ByteIO</src> object
77 // as the data store and the given <src>DataConversion</src> object
78 // as the conversion engine.
79 // <p>
80 // The read and write functions use an intermediate buffer to hold the data
81 // in canonical format. For small arrays it uses a fixed buffer with
82 // length <src>bufferLength</src>. For arrays not fitting in this buffer,
83 // it uses a temporary buffer allocated on the heap.
84 ConversionIO (const std::shared_ptr<DataConversion>& dataConversion,
85 const std::shared_ptr<ByteIO>& byteIO,
86 uInt bufferLength=4096);
87
88 // The copy constructor uses reference semantics
89 ConversionIO (const ConversionIO& conversionIO);
90
91 // The assignment operator uses reference semantics
92 ConversionIO& operator= (const ConversionIO& conversionIO);
93
94 // Destructor, deletes allocated memory.
96
97 // Convert the values and write them to the ByteIO object.
98 // Bool, complex and String values are handled by the base class.
99 // <group>
100 virtual size_t write (size_t nvalues, const Bool* value);
101 virtual size_t write (size_t nvalues, const Char* data);
102 virtual size_t write (size_t nvalues, const uChar* data);
103 virtual size_t write (size_t nvalues, const Short* data);
104 virtual size_t write (size_t nvalues, const uShort* data);
105 virtual size_t write (size_t nvalues, const Int* data);
106 virtual size_t write (size_t nvalues, const uInt* data);
107 virtual size_t write (size_t nvalues, const Int64* data);
108 virtual size_t write (size_t nvalues, const uInt64* data);
109 virtual size_t write (size_t nvalues, const Float* data);
110 virtual size_t write (size_t nvalues, const Double* data);
111 virtual size_t write (size_t nvalues, const Complex* value);
112 virtual size_t write (size_t nvalues, const DComplex* value);
113 virtual size_t write (size_t nvalues, const String* value);
114 // </group>
115
116 // Read the values from the ByteIO object and convert them.
117 // Bool, complex and String values are handled by the base class.
118 // <group>
119 virtual size_t read (size_t nvalues, Bool* value);
120 virtual size_t read (size_t nvalues, Char* data);
121 virtual size_t read (size_t nvalues, uChar* data);
122 virtual size_t read (size_t nvalues, Short* data);
123 virtual size_t read (size_t nvalues, uShort* data);
124 virtual size_t read (size_t nvalues, Int* data);
125 virtual size_t read (size_t nvalues, uInt* data);
126 virtual size_t read (size_t nvalues, Int64* data);
127 virtual size_t read (size_t nvalues, uInt64* data);
128 virtual size_t read (size_t nvalues, Float* data);
129 virtual size_t read (size_t nvalues, Double* data);
130 virtual size_t read (size_t nvalues, Complex* value);
131 virtual size_t read (size_t nvalues, DComplex* value);
132 virtual size_t read (size_t nvalues, String* value);
133 // </group>
134
135private:
136 // Initialize the <src>itsSize</src> and <src>itsCopy</src> variables.
137 void init();
138
139
140 //# The data.
141 std::shared_ptr<DataConversion> itsConversion;
162 //# The buffer
165};
166
167
168
169} //# NAMESPACE CASACORE - END
170
171#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)
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)
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.
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:223
const ByteIO & byteIO() const
Functions to return a reference to the ByteIO class.
this file contains all the compiler specific defines
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
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
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.
double Double
Definition aipstype.h:53
char Char
Definition aipstype.h:44
unsigned long long uInt64
Definition aipsxtype.h:37