casacore
TypeIO.h
Go to the documentation of this file.
1//# TypeIO.h: Abstract base class for IO of data in a type-dependent 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_TYPEIO_H
29#define CASA_TYPEIO_H
30
31#include <casacore/casa/aips.h>
32#include <casacore/casa/IO/ByteIO.h>
33#include <casacore/casa/Utilities/CountedPtr.h>
34//# The following should be a forward declaration. But our Complex & DComplex
35//# classes 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
39namespace casacore { //# NAMESPACE CASACORE - BEGIN
40
41class String;
42
43// <summary>Abstract base class for IO of data in a type-dependent 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// </prerequisite>
53
54// <synopsis>
55// This class is the abstract base class for doing IO in a type-dependent
56// way. Derived from it are classes like <linkto class=CanonicalIO>
57// CanonicalIO</linkto> doing the actual formatting of the data.
58// <p>
59// The TypeIO classes convert the data to/from the given format
60// using the static conversion functions in the classes like
61// <linkto class=CanonicalConversion>CanonicalConversion</linkto>.
62// The data is written to or read from the <linkto class=ByteIO>ByteIO</linkto>
63// object given when constructing the TypeIO object.
64// <p>
65// TypeIO declares the virtual functions read and write to read/write
66// one or more values of a given data type. Usually the derived classes
67// have to implement these functions. An exception are the functions
68// handling Bool, complex and String values. These functions have a
69// default implementation in this base class. However, if needed
70// they can be overwritten in derived classes.
71// </synopsis>
72
73// <motivation>
74// The base class is needed for polymorphic type-dependent IO.
75// Furthermore the common functionality can be implemented here.
76// </motivation>
77
78
79class TypeIO
80{
81public:
82 // Constructor.
83 // The read/write functions will use the given ByteIO object
84 // as the data store.
85 explicit TypeIO (ByteIO* byteIO, Bool takeOver=False);
86
87 virtual ~TypeIO();
88
89 // Functions to return a reference to the ByteIO class.
90 // <group>
91 const ByteIO& byteIO() const;
93 // </group>
94
95 // Convert the values and write them to the ByteIO object.
96 // By default Bools are stored as bits, Complex as 2 floats,
97 // DComplex as 2 doubles and String as a length (uInt) and chars.
98 // If it does not succeed an exception will be thrown.
99 // <group>
100 virtual size_t write (size_t nvalues, const Bool* value);
101 virtual size_t write (size_t nvalues, const Char* value) = 0;
102 virtual size_t write (size_t nvalues, const uChar* value) = 0;
103 virtual size_t write (size_t nvalues, const Short* value) = 0;
104 virtual size_t write (size_t nvalues, const uShort* value) = 0;
105 virtual size_t write (size_t nvalues, const Int* value) = 0;
106 virtual size_t write (size_t nvalues, const uInt* value) = 0;
107 virtual size_t write (size_t nvalues, const Int64* value) = 0;
108 virtual size_t write (size_t nvalues, const uInt64* value) = 0;
109 virtual size_t write (size_t nvalues, const Float* value) = 0;
110 virtual size_t write (size_t nvalues, const Double* value) = 0;
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 // By default Bools are stored as bits, Complex as 2 floats,
118 // DComplex as 2 doubles and String as a length (uInt) and chars.
119 // If it does not succeed an exception will be thrown.
120 // <group>
121 virtual size_t read (size_t nvalues, Bool* value);
122 virtual size_t read (size_t nvalues, Char* value) = 0;
123 virtual size_t read (size_t nvalues, uChar* value) = 0;
124 virtual size_t read (size_t nvalues, Short* value) = 0;
125 virtual size_t read (size_t nvalues, uShort* value) = 0;
126 virtual size_t read (size_t nvalues, Int* value) = 0;
127 virtual size_t read (size_t nvalues, uInt* value) = 0;
128 virtual size_t read (size_t nvalues, Int64* value) = 0;
129 virtual size_t read (size_t nvalues, uInt64* value) = 0;
130 virtual size_t read (size_t nvalues, Float* value) = 0;
131 virtual size_t read (size_t nvalues, Double* value) = 0;
132 virtual size_t read (size_t nvalues, Complex* value);
133 virtual size_t read (size_t nvalues, DComplex* value);
134 virtual size_t read (size_t nvalues, String* value);
135 // </group>
136
137 // This function sets the position on the given offset.
138 // The seek option defines from which file position the seek is done.
139 // -1 is returned if not seekable.
140 // <group>
143 // </group>
144
145 // Is the TypeIO stream readable?
147
148 // Is the TypeIO stream writable?
150
151 // Is the TypeIO stream seekable?
153
154protected:
155 // This variable keeps a pointer to a ByteIO.
157
158 // The copy constructor uses reference semantics.
160
161 // The assignment operator uses reference semantics.
162 TypeIO& operator= (const TypeIO& typeIO);
163};
164
165
166
167
168} //# NAMESPACE CASACORE - END
169
170#endif
SeekOption
Define the possible seek options.
Definition: ByteIO.h:82
@ Begin
Seek from beginning of file.
Definition: ByteIO.h:84
Referenced counted pointer for constant data.
Definition: CountedPtr.h:81
String: the storage and methods of handling collections of characters.
Definition: String.h:225
virtual size_t write(size_t nvalues, const Bool *value)
Convert the values and write them to the ByteIO object.
Bool isReadable() const
Is the TypeIO stream readable?
virtual size_t write(size_t nvalues, const DComplex *value)
Int64 seek(Int offset, ByteIO::SeekOption=ByteIO::Begin)
virtual size_t write(size_t nvalues, const Char *value)=0
virtual size_t read(size_t nvalues, Short *value)=0
Bool isSeekable() const
Is the TypeIO stream seekable?
virtual size_t write(size_t nvalues, const uShort *value)=0
virtual size_t write(size_t nvalues, const uInt64 *value)=0
virtual size_t write(size_t nvalues, const Short *value)=0
virtual size_t write(size_t nvalues, const Complex *value)
virtual size_t read(size_t nvalues, Char *value)=0
virtual size_t read(size_t nvalues, DComplex *value)
virtual size_t write(size_t nvalues, const Int64 *value)=0
virtual size_t write(size_t nvalues, const Float *value)=0
virtual size_t read(size_t nvalues, uShort *value)=0
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 Int *value)=0
const ByteIO & byteIO() const
Functions to return a reference to the ByteIO class.
virtual size_t read(size_t nvalues, Int *value)=0
virtual size_t write(size_t nvalues, const String *value)
virtual size_t read(size_t nvalues, Complex *value)
virtual size_t read(size_t nvalues, Float *value)=0
Bool isWritable() const
Is the TypeIO stream writable?
virtual size_t write(size_t nvalues, const Double *value)=0
CountedPtr< ByteIO > itsByteIO
This variable keeps a pointer to a ByteIO.
Definition: TypeIO.h:156
virtual size_t read(size_t nvalues, Double *value)=0
TypeIO(const TypeIO &TypeIO)
The copy constructor uses reference semantics.
virtual size_t read(size_t nvalues, String *value)
TypeIO & operator=(const TypeIO &typeIO)
The assignment operator uses reference semantics.
virtual ~TypeIO()
virtual size_t read(size_t nvalues, uChar *value)=0
virtual size_t read(size_t nvalues, Int64 *value)=0
ByteIO & byteIO()
virtual size_t write(size_t nvalues, const uInt *value)=0
virtual size_t write(size_t nvalues, const uChar *value)=0
virtual size_t read(size_t nvalues, uInt *value)=0
Int64 seek(Int64 offset, ByteIO::SeekOption=ByteIO::Begin)
This function sets the position on the given offset.
virtual size_t read(size_t nvalues, uInt64 *value)=0
TypeIO(ByteIO *byteIO, Bool takeOver=False)
Constructor.
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