casacore
Loading...
Searching...
No Matches
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: 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_TYPEIO_H
27#define CASA_TYPEIO_H
28
29#include <casacore/casa/aips.h>
30#include <casacore/casa/IO/ByteIO.h>
31#include <memory>
32//# The following should be a forward declaration. But our Complex & DComplex
33//# classes 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 String;
40
41// <summary>Abstract base class for IO of data in a type-dependent format</summary>
42
43// <use visibility=export>
44
45// <reviewed reviewer="Friso Olnon" date="1996/11/06" tests="tTypeIO" demos="">
46// </reviewed>
47
48// <prerequisite>
49// <li> <linkto class=ByteIO>ByteIO</linkto> class and derived classes
50// </prerequisite>
51
52// <synopsis>
53// This class is the abstract base class for doing IO in a type-dependent
54// way. Derived from it are classes like <linkto class=CanonicalIO>
55// CanonicalIO</linkto> doing the actual formatting of the data.
56// <p>
57// The TypeIO classes convert the data to/from the given format
58// using the static conversion functions in the classes like
59// <linkto class=CanonicalConversion>CanonicalConversion</linkto>.
60// The data is written to or read from the <linkto class=ByteIO>ByteIO</linkto>
61// object given when constructing the TypeIO object.
62// <p>
63// TypeIO declares the virtual functions read and write to read/write
64// one or more values of a given data type. Usually the derived classes
65// have to implement these functions. An exception are the functions
66// handling Bool, complex and String values. These functions have a
67// default implementation in this base class. However, if needed
68// they can be overwritten in derived classes.
69// </synopsis>
70
71// <motivation>
72// The base class is needed for polymorphic type-dependent IO.
73// Furthermore the common functionality can be implemented here.
74// </motivation>
75
76
77class TypeIO
78{
79public:
80 // Constructor.
81 // The read/write functions will use the given ByteIO object
82 // as the data store.
83 explicit TypeIO (const std::shared_ptr<ByteIO>& byteIO);
84
85 virtual ~TypeIO();
86
87 // Functions to return a reference to the ByteIO class.
88 // <group>
89 const ByteIO& byteIO() const;
91 // </group>
92
93 // Convert the values and write them to the ByteIO object.
94 // By default Bools are stored as bits, Complex as 2 floats,
95 // DComplex as 2 doubles and String as a length (uInt) and chars.
96 // If it does not succeed an exception will be thrown.
97 // <group>
98 virtual size_t write (size_t nvalues, const Bool* value);
99 virtual size_t write (size_t nvalues, const Char* value) = 0;
100 virtual size_t write (size_t nvalues, const uChar* value) = 0;
101 virtual size_t write (size_t nvalues, const Short* value) = 0;
102 virtual size_t write (size_t nvalues, const uShort* value) = 0;
103 virtual size_t write (size_t nvalues, const Int* value) = 0;
104 virtual size_t write (size_t nvalues, const uInt* value) = 0;
105 virtual size_t write (size_t nvalues, const Int64* value) = 0;
106 virtual size_t write (size_t nvalues, const uInt64* value) = 0;
107 virtual size_t write (size_t nvalues, const Float* value) = 0;
108 virtual size_t write (size_t nvalues, const Double* value) = 0;
109 virtual size_t write (size_t nvalues, const Complex* value);
110 virtual size_t write (size_t nvalues, const DComplex* value);
111 virtual size_t write (size_t nvalues, const String* value);
112 // </group>
113
114 // Read the values from the ByteIO object and convert them.
115 // By default Bools are stored as bits, Complex as 2 floats,
116 // DComplex as 2 doubles and String as a length (uInt) and chars.
117 // If it does not succeed an exception will be thrown.
118 // <group>
119 virtual size_t read (size_t nvalues, Bool* value);
120 virtual size_t read (size_t nvalues, Char* value) = 0;
121 virtual size_t read (size_t nvalues, uChar* value) = 0;
122 virtual size_t read (size_t nvalues, Short* value) = 0;
123 virtual size_t read (size_t nvalues, uShort* value) = 0;
124 virtual size_t read (size_t nvalues, Int* value) = 0;
125 virtual size_t read (size_t nvalues, uInt* value) = 0;
126 virtual size_t read (size_t nvalues, Int64* value) = 0;
127 virtual size_t read (size_t nvalues, uInt64* value) = 0;
128 virtual size_t read (size_t nvalues, Float* value) = 0;
129 virtual size_t read (size_t nvalues, Double* value) = 0;
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
135 // This function sets the position on the given offset.
136 // The seek option defines from which file position the seek is done.
137 // -1 is returned if not seekable.
138 // <group>
141 // </group>
142
143 // Is the TypeIO stream readable?
145
146 // Is the TypeIO stream writable?
148
149 // Is the TypeIO stream seekable?
151
152protected:
153 // This variable keeps a pointer to a ByteIO.
154 std::shared_ptr<ByteIO> itsByteIO;
155
156 // The copy constructor uses reference semantics.
158
159 // The assignment operator uses reference semantics.
160 TypeIO& operator= (const TypeIO& typeIO);
161};
162
163
164
165
166} //# NAMESPACE CASACORE - END
167
168#endif
SeekOption
Define the possible seek options.
Definition ByteIO.h:80
@ Begin
Seek from beginning of file.
Definition ByteIO.h:82
String: the storage and methods of handling collections of characters.
Definition String.h:223
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
std::shared_ptr< ByteIO > itsByteIO
This variable keeps a pointer to a ByteIO.
Definition TypeIO.h:154
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.
TypeIO(const std::shared_ptr< ByteIO > &byteIO)
Constructor.
virtual size_t read(size_t nvalues, uInt64 *value)=0
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