casacore
Loading...
Searching...
No Matches
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: 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_BYTESINK_H
27#define CASA_BYTESINK_H
28
29#include <casacore/casa/aips.h>
30#include <casacore/casa/IO/BaseSinkSource.h>
31//# The following should be a forward declaration. But our Complex & DComplex
32//# classes are a typedef hence this does not work. Replace the following with
33//# forward declarations when Complex and DComplex are no longer typedefs.
34#include <casacore/casa/BasicSL/Complex.h>
35
36namespace casacore { //# NAMESPACE CASACORE - BEGIN
37
38class TypeIO;
39class String;
40
41// <summary>Class for write-only access to data in a given format.</summary>
42
43// <use visibility=export>
44
45// <reviewed reviewer="Friso Olnon" date="1996/11/06" tests="tByteSink" demos="">
46// </reviewed>
47
48// <prerequisite>
49// <li> <linkto class=BaseSinkSource>BaseSinkSource</linkto> class
50// <li> <linkto class=TypeIO>TypeIO</linkto> class and derived classes
51// </prerequisite>
52
53// <etymology>
54// A sink is the place where bytes are written to.
55// </etymology>
56
57// <synopsis>
58// ByteSink provides write-only access to a typed byte stream in the
59// Casacore IO framework. The base class <src>BaseSinkSource</src>
60// contains common functions like <src>seek</src>.
61// <p>
62// The object is constructed using a typed byte stream. This stream
63// is an instance of a class derived from class
64// <linkto class=TypeIO>TypeIO</linkto>. This makes it possible to
65// store the data in any format (e.g. CanonicalIO or RawIO).
66// <br> In its turn TypeIO uses an instance of a class derived from class
67// <linkto class=ByteIO>ByteIO</linkto>. This makes it possible to
68// use any output stream (e.g. file, memory).
69// <p>
70// Note that in general <src>ByteSink</src> will only be used
71// for write-only streams like sockets or pipes.
72// Class <linkto class=ByteSinkSource>ByteSinkSource</linkto>
73// is the obvious choice for read/write streams.
74// </synopsis>
75
76// <example>
77// <srcblock>
78// // Construct the correct output stream.
79// MemoryIO memio;
80// CanonicalIO canio (&memio);
81// ByteSink sink (&canio);
82// // Write data.
83// Int vali;
84// sink << vali << True;
85// </srcblock>
86// </example>
87
88// <motivation>
89// This class makes it possible to deny read-access to an IO stream.
90// </motivation>
91
92
93class ByteSink: virtual public BaseSinkSource
94{
95public:
96 // Default constructor.
97 // This creates an invalid object, but is present for convenience.
99
100 // Construct from given TypeIO object.
101 // The constructor does not copy the object, but only keeps a pointer to it.
102 ByteSink (const std::shared_ptr<TypeIO>& typeIO);
103
104 // The copy constructor uses reference semantics
105 ByteSink (const ByteSink& sink);
106
107 // The assignment operator uses reference semantics
109
110 // destructor
112
113 // These functions write one value of the given type.
114 // If this function does not succeed, an exception will be thrown.
115 // <group>
127 ByteSink& operator<< (const Complex& value);
128 ByteSink& operator<< (const DComplex& value);
131 // </group>
132
133 // These functions write multiple values of the given type.
134 // If this function does not succeed, an exception will be thrown.
135 // <group>
136 void write (size_t nvalues, const Bool* value);
137 void write (size_t nvalues, const Char* value);
138 void write (size_t nvalues, const uChar* value);
139 void write (size_t nvalues, const Short* value);
140 void write (size_t nvalues, const uShort* value);
141 void write (size_t nvalues, const Int* value);
142 void write (size_t nvalues, const uInt* value);
143 void write (size_t nvalues, const Int64* value);
144 void write (size_t nvalues, const uInt64* value);
145 void write (size_t nvalues, const Float* value);
146 void write (size_t nvalues, const Double* value);
147 void write (size_t nvalues, const Complex* value);
148 void write (size_t nvalues, const DComplex* value);
149 void write (size_t nvalues, const String* value);
150 // </group>
151};
152
153
154
155} //# NAMESPACE CASACORE - END
156
157#endif
const std::shared_ptr< TypeIO > & typeIO() const
This functions returns the shared pointer to itsTypeIO.
ByteSink(const std::shared_ptr< TypeIO > &typeIO)
Construct from given TypeIO object.
ByteSink(const ByteSink &sink)
The copy constructor uses reference semantics.
ByteSink()
Default constructor.
void write(size_t nvalues, const Short *value)
void write(size_t nvalues, const Double *value)
void write(size_t nvalues, const Float *value)
void write(size_t nvalues, const Int64 *value)
void write(size_t nvalues, const DComplex *value)
void write(size_t nvalues, const String *value)
ByteSink & operator<<(Bool value)
These functions write one value of the given type.
void write(size_t nvalues, const Complex *value)
void write(size_t nvalues, const uInt *value)
void write(size_t nvalues, const Int *value)
void write(size_t nvalues, const Char *value)
ByteSink & operator=(const ByteSink &sink)
The assignment operator uses reference semantics.
void write(size_t nvalues, const uShort *value)
void write(size_t nvalues, const Bool *value)
These functions write multiple values of the given type.
void write(size_t nvalues, const uChar *value)
void write(size_t nvalues, const uInt64 *value)
~ByteSink()
destructor
String: the storage and methods of handling collections of characters.
Definition String.h:223
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