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