casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ByteSink.h
Go to the documentation of this file.
1 //# ByteSink.h: Class for write-only access to data in a given format
2 //# Copyright (C) 1996,1998,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_BYTESINK_H
29 #define CASA_BYTESINK_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 write-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 sink is the place where bytes are written to.
57 // </etymology>
58 
59 // <synopsis>
60 // ByteSink provides write-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 // store 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 output stream (e.g. file, memory).
71 // <p>
72 // Note that in general <src>ByteSink</src> will only be used
73 // for write-only streams like sockets or pipes.
74 // Class <linkto class=ByteSinkSource>ByteSinkSource</linkto>
75 // is the obvious choice for read/write streams.
76 // </synopsis>
77 
78 // <example>
79 // <srcblock>
80 // // Construct the correct output stream.
81 // MemoryIO memio;
82 // CanonicalIO canio (&memio);
83 // ByteSink sink (&canio);
84 // // Write data.
85 // Int vali;
86 // sink << vali << True;
87 // </srcblock>
88 // </example>
89 
90 // <motivation>
91 // This class makes it possible to deny read-access to an IO stream.
92 // </motivation>
93 
94 
95 class ByteSink: virtual public BaseSinkSource
96 {
97 public:
98  // Default constructor.
99  // This creates an invalid object, but is present for convenience.
100  ByteSink();
101 
102  // Construct from given TypeIO object. The constructor does not copy the
103  // object, but only keeps a pointer to it. If takeOver is true the this
104  // class will delete the supplied pointer. Otherwise the caller is
105  // responsible for this.
106  ByteSink (TypeIO* typeIO, Bool takeOver=False);
107 
108  // The copy constructor uses reference semantics
109  ByteSink (const ByteSink& sink);
110 
111  // The assignment operator uses reference semantics
112  ByteSink& operator= (const ByteSink& sink);
113 
114  // destructor
115  ~ByteSink();
116 
117  // These functions write one value of the given type.
118  // If this function does not succeed, an exception will be thrown.
119  // <group>
121  ByteSink& operator<< (Char value);
122  ByteSink& operator<< (uChar value);
123  ByteSink& operator<< (Short value);
124  ByteSink& operator<< (uShort value);
125  ByteSink& operator<< (Int value);
126  ByteSink& operator<< (uInt value);
127  ByteSink& operator<< (Int64 value);
128  ByteSink& operator<< (uInt64 value);
129  ByteSink& operator<< (Float value);
130  ByteSink& operator<< (Double value);
131  ByteSink& operator<< (const Complex& value);
132  ByteSink& operator<< (const DComplex& value);
133  ByteSink& operator<< (const String& value);
134  ByteSink& operator<< (const Char* value);
135  // </group>
136 
137  // These functions write multiple values of the given type.
138  // If this function does not succeed, an exception will be thrown.
139  // <group>
140  void write (size_t nvalues, const Bool* value);
141  void write (size_t nvalues, const Char* value);
142  void write (size_t nvalues, const uChar* value);
143  void write (size_t nvalues, const Short* value);
144  void write (size_t nvalues, const uShort* value);
145  void write (size_t nvalues, const Int* value);
146  void write (size_t nvalues, const uInt* value);
147  void write (size_t nvalues, const Int64* value);
148  void write (size_t nvalues, const uInt64* value);
149  void write (size_t nvalues, const Float* value);
150  void write (size_t nvalues, const Double* value);
151  void write (size_t nvalues, const Complex* value);
152  void write (size_t nvalues, const DComplex* value);
153  void write (size_t nvalues, const String* value);
154  // </group>
155 };
156 
157 
158 
159 } //# NAMESPACE CASACORE - END
160 
161 #endif
Class for write-only access to data in a given format.
Definition: ByteSink.h:95
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
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
ByteSink()
Default constructor.
Shared base class for ByteSink and ByteSource.
short Short
Definition: aipstype.h:48
~ByteSink()
destructor
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
const Bool False
Definition: aipstype.h:44
ByteSink & operator<<(Bool value)
These functions write one value of the given type.
void write(size_t nvalues, const Bool *value)
These functions write multiple values of the given type.
ByteSink & operator=(const ByteSink &sink)
The assignment operator uses reference semantics.
String: the storage and methods of handling collections of characters.
Definition: String.h:223
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