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.
90  ConversionIO (DataConversion* dataConversion, ByteIO* byteIO,
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.
100  ~ConversionIO();
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
casacore::ConversionIO::itsSizeChar
uInt itsSizeChar
Definition: ConversionIO.h:147
casacore::ConversionIO::init
void init()
Initialize the itsSize and itsCopy variables.
Complexfwd_global_functions_Complexfwd::casacore::DComplex
std::complex< Double > DComplex
Definition: Complexfwd.h:50
casacore::ConversionIO::itsSizeuChar
uInt itsSizeuChar
Definition: ConversionIO.h:148
casacore::ConversionIO::itsCopyuChar
Bool itsCopyuChar
Definition: ConversionIO.h:158
casacore::ConversionIO::itsSizeuInt
uInt itsSizeuInt
Definition: ConversionIO.h:152
casacore::CountedPtr
Referenced counted pointer for constant data.
Definition: CountedPtr.h:80
casacore::uChar
unsigned char uChar
Definition: aipstype.h:47
casacore::ConversionIO::itsBufferLength
uInt itsBufferLength
Definition: ConversionIO.h:169
casacore::ConversionIO::itsCopyFloat
Bool itsCopyFloat
Definition: ConversionIO.h:165
casacore::ConversionIO::itsCopyInt64
Bool itsCopyInt64
Definition: ConversionIO.h:163
casacore::ConversionIO::itsSizeShort
uInt itsSizeShort
Definition: ConversionIO.h:149
casacore::ConversionIO::itsSizeInt
uInt itsSizeInt
Definition: ConversionIO.h:151
casacore::ConversionIO::itsCopyShort
Bool itsCopyShort
Definition: ConversionIO.h:159
casacore::ConversionIO::itsCopyInt
Bool itsCopyInt
Definition: ConversionIO.h:161
casacore::Float
float Float
Definition: aipstype.h:54
casacore::ConversionIO::itsCopyuShort
Bool itsCopyuShort
Definition: ConversionIO.h:160
casacore::value
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.
casacore::uShort
unsigned short uShort
Definition: aipstype.h:49
casacore::ConversionIO::itsSizeInt64
uInt itsSizeInt64
Definition: ConversionIO.h:153
casacore::Double
double Double
Definition: aipstype.h:55
casacore::ConversionIO::itsCopyDouble
Bool itsCopyDouble
Definition: ConversionIO.h:166
casacore::False
const Bool False
Definition: aipstype.h:44
casacore::uInt
unsigned int uInt
Definition: aipstype.h:51
casacore::ConversionIO::itsCopyuInt
Bool itsCopyuInt
Definition: ConversionIO.h:162
casacore::DataConversion
Abstract base class with functions to convert any format.
Definition: DataConversion.h:82
casacore::Int
int Int
Definition: aipstype.h:50
casacore
this file contains all the compiler specific defines
Definition: mainpage.dox:28
casacore::ConversionIO::itsBuffer
char * itsBuffer
Definition: ConversionIO.h:168
casacore::TypeIO
Abstract base class for IO of data in a type-dependent format.
Definition: TypeIO.h:79
casacore::ConversionIO::itsConversion
CountedPtr< DataConversion > itsConversion
Definition: ConversionIO.h:146
casacore::ConversionIO::~ConversionIO
~ConversionIO()
Destructor, deletes allocated memory.
casacore::ConversionIO
Class for IO in a converted format.
Definition: ConversionIO.h:74
casacore::ConversionIO::read
virtual size_t read(size_t nvalues, Bool *value)
Read the values from the ByteIO object and convert them.
casacore::ConversionIO::itsSizeFloat
uInt itsSizeFloat
Definition: ConversionIO.h:155
casacore::Int64
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size)
Definition: aipsxtype.h:38
casacore::ConversionIO::itsSizeDouble
uInt itsSizeDouble
Definition: ConversionIO.h:156
casacore::ConversionIO::itsSizeuInt64
uInt itsSizeuInt64
Definition: ConversionIO.h:154
casacore::String
String: the storage and methods of handling collections of characters.
Definition: String.h:223
casacore::Bool
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
Complexfwd_global_functions_Complexfwd::casacore::Complex
std::complex< Float > Complex
Definition: Complexfwd.h:49
casacore::Short
short Short
Definition: aipstype.h:48
casacore::TypeIO::byteIO
const ByteIO & byteIO() const
Functions to return a reference to the ByteIO class.
casacore::ConversionIO::ConversionIO
ConversionIO(DataConversion *dataConversion, ByteIO *byteIO, uInt bufferLength=4096, Bool takeOver=False)
Constructor.
casacore::ByteIO
Abstract base class for IO on a byte stream.
Definition: ByteIO.h:61
casacore::ConversionIO::write
virtual size_t write(size_t nvalues, const Bool *value)
Convert the values and write them to the ByteIO object.
casacore::ConversionIO::itsCopyChar
Bool itsCopyChar
Definition: ConversionIO.h:157
casacore::ConversionIO::itsSizeuShort
uInt itsSizeuShort
Definition: ConversionIO.h:150
casacore::ConversionIO::itsCopyuInt64
Bool itsCopyuInt64
Definition: ConversionIO.h:164
casacore::Char
char Char
Definition: aipstype.h:46
casacore::ConversionIO::operator=
ConversionIO & operator=(const ConversionIO &conversionIO)
The assignment operator uses reference semantics.
casacore::uInt64
unsigned long long uInt64
Definition: aipsxtype.h:39