casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ByteSource.h
Go to the documentation of this file.
1 //# ByteSource.h: Class for read-only access to data in a given 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_BYTESOURCE_H
29 #define CASA_BYTESOURCE_H
30 
31 #include <casacore/casa/aips.h>
33 //# The following should be a forward declaration. But our Complex & DComplex
34 //# classes are a typedef hence this does not work. Replace the following with
35 //# forward declarations when Complex and DComplex are no longer typedefs.
37 
38 namespace casacore { //# NAMESPACE CASACORE - BEGIN
39 
40 class TypeIO;
41 class String;
42 
43 // <summary>Class for read-only access to data in a given format.</summary>
44 
45 // <use visibility=export>
46 
47 // <reviewed reviewer="Friso Olnon" date="1996/11/06" tests="tByteSink" demos="">
48 // </reviewed>
49 
50 // <prerequisite>
51 // <li> <linkto class=BaseSinkSource>BaseSinkSource</linkto> class
52 // <li> <linkto class=TypeIO>TypeIO</linkto> class and derived classes
53 // </prerequisite>
54 
55 // <etymology>
56 // A source is the place where bytes are read from.
57 // </etymology>
58 
59 // <synopsis>
60 // ByteSource provides read-only access to a typed byte stream in the
61 // Casacore IO framework. The base class <src>BaseSinkSource</src>
62 // contains common functions like <src>seek</src>.
63 // <p>
64 // The object is constructed using a typed byte stream. This stream
65 // is an instance of a class derived from class
66 // <linkto class=TypeIO>TypeIO</linkto>. This makes it possible to
67 // read the data in any format (e.g. CanonicalIO or RawIO).
68 // <br> In its turn TypeIO uses an instance of a class derived from class
69 // <linkto class=ByteIO>ByteIO</linkto>. This makes it possible to
70 // use any input stream (e.g. file, memory).
71 // </synopsis>
72 
73 // <example>
74 // <srcblock>
75 // // Construct the correct input stream.
76 // RegularFileIO filio ("file.name");
77 // CanonicalIO canio (&filio);
78 // ByteSource source (&canio);
79 // // Read data.
80 // Int vali;
81 // Bool flag;
82 // source >> vali >> flag;
83 // </srcblock>
84 // </example>
85 
86 // <motivation>
87 // This class makes it possible to deny write-access to an IO stream.
88 // </motivation>
89 
90 
91 class ByteSource: virtual public BaseSinkSource
92 {
93 public:
94  // Default constructor.
95  // This creates an invalid object, but is present for convenience.
96  ByteSource();
97 
98  // Construct from given TypeIO object. The constructor does not copy the
99  // object, but only keeps a pointer to it. If takeOver is true the this
100  // class will delete the supplied pointer. Otherwise the caller is
101  // responsible for this.
102  ByteSource (TypeIO* typeIO, Bool takeOver=False);
103 
104  // The copy constructor uses reference semantics
105  ByteSource (const ByteSource& source);
106 
107  // The assignment operator uses reference semantics
108  ByteSource& operator= (const ByteSource& source);
109 
110  // destructor
111  ~ByteSource();
112 
113  // These functions read one value of the given type.
114  // If this function does not succeed, an exception will be thrown.
115  // <group>
117  ByteSource& operator>> (Char& value);
118  ByteSource& operator>> (uChar& value);
119  ByteSource& operator>> (Short& value);
120  ByteSource& operator>> (uShort& value);
121  ByteSource& operator>> (Int& value);
122  ByteSource& operator>> (uInt& value);
123  ByteSource& operator>> (Int64& value);
124  ByteSource& operator>> (uInt64& value);
125  ByteSource& operator>> (Float& value);
126  ByteSource& operator>> (Double& value);
127  ByteSource& operator>> (Complex& value);
129  ByteSource& operator>> (String& value);
130  // </group>
131 
132  // These functions read multiple values of the given type.
133  // If this function does not succeed, an exception will be thrown.
134  // <group>
135  void read (size_t nvalues, Bool* value);
136  void read (size_t nvalues, Char* value);
137  void read (size_t nvalues, uChar* value);
138  void read (size_t nvalues, Short* value);
139  void read (size_t nvalues, uShort* value);
140  void read (size_t nvalues, Int* value);
141  void read (size_t nvalues, uInt* value);
142  void read (size_t nvalues, Int64* value);
143  void read (size_t nvalues, uInt64* value);
144  void read (size_t nvalues, Float* value);
145  void read (size_t nvalues, Double* value);
146  void read (size_t nvalues, Complex* value);
147  void read (size_t nvalues, DComplex* value);
148  void read (size_t nvalues, String* value);
149  // </group>
150 
151 protected:
152 };
153 
154 
155 
156 } //# NAMESPACE CASACORE - END
157 
158 #endif
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size)
Definition: aipsxtype.h:38
int Int
Definition: aipstype.h:50
Class for read-only access to data in a given format.
Definition: ByteSource.h:91
unsigned long long uInt64
Definition: aipsxtype.h:39
unsigned char uChar
Definition: aipstype.h:47
TypeIO & typeIO()
This functions returns a reference to itsTypeIO.
char Char
Definition: aipstype.h:46
Shared base class for ByteSink and ByteSource.
short Short
Definition: aipstype.h:48
ByteSource()
Default constructor.
void read(size_t nvalues, Bool *value)
These functions read multiple values of the given type.
double Double
Definition: aipstype.h:55
Abstract base class for IO of data in a type-dependent format.
Definition: TypeIO.h:79
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
float Float
Definition: aipstype.h:54
~ByteSource()
destructor
const Bool False
Definition: aipstype.h:44
ByteSource & operator=(const ByteSource &source)
The assignment operator uses reference semantics.
String: the storage and methods of handling collections of characters.
Definition: String.h:223
ByteSource & operator>>(Bool &value)
These functions read one value of the given type.
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.
unsigned int uInt
Definition: aipstype.h:51
unsigned short uShort
Definition: aipstype.h:49
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42