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
92class ByteSink : virtual public BaseSinkSource {
93 public:
94 // Default constructor.
95 // This creates an invalid object, but is present for convenience.
97
98 // Construct from given TypeIO object.
99 // The constructor does not copy the object, but only keeps a pointer to it.
100 ByteSink(const std::shared_ptr<TypeIO>& typeIO);
101
102 // The copy constructor uses reference semantics
103 ByteSink(const ByteSink& sink);
104
105 // The assignment operator uses reference semantics
107
108 // destructor
110
111 // These functions write one value of the given type.
112 // If this function does not succeed, an exception will be thrown.
113 // <group>
125 ByteSink& operator<<(const Complex& value);
126 ByteSink& operator<<(const DComplex& value);
129 // </group>
130
131 // These functions write multiple values of the given type.
132 // If this function does not succeed, an exception will be thrown.
133 // <group>
134 void write(size_t nvalues, const Bool* value);
135 void write(size_t nvalues, const Char* value);
136 void write(size_t nvalues, const uChar* value);
137 void write(size_t nvalues, const Short* value);
138 void write(size_t nvalues, const uShort* value);
139 void write(size_t nvalues, const Int* value);
140 void write(size_t nvalues, const uInt* value);
141 void write(size_t nvalues, const Int64* value);
142 void write(size_t nvalues, const uInt64* value);
143 void write(size_t nvalues, const Float* value);
144 void write(size_t nvalues, const Double* value);
145 void write(size_t nvalues, const Complex* value);
146 void write(size_t nvalues, const DComplex* value);
147 void write(size_t nvalues, const String* value);
148 // </group>
149};
150
151} // namespace casacore
152
153#endif
const std::shared_ptr< TypeIO > & typeIO() const
This functions returns the shared pointer to itsTypeIO.
ByteSink & operator<<(const Char *value)
ByteSink & operator<<(uInt value)
ByteSink(const std::shared_ptr< TypeIO > &typeIO)
Construct from given TypeIO object.
ByteSink(const ByteSink &sink)
The copy constructor uses reference semantics.
ByteSink & operator<<(const String &value)
ByteSink()
Default constructor.
void write(size_t nvalues, const Short *value)
void write(size_t nvalues, const Double *value)
ByteSink & operator<<(uShort value)
void write(size_t nvalues, const Float *value)
ByteSink & operator<<(Double 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)
ByteSink & operator<<(Int64 value)
ByteSink & operator<<(Int value)
void write(size_t nvalues, const uInt *value)
ByteSink & operator<<(const DComplex &value)
ByteSink & operator<<(Float value)
void write(size_t nvalues, const Int *value)
ByteSink & operator<<(uChar 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)
ByteSink & operator<<(Short 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)
ByteSink & operator<<(uInt64 value)
ByteSink & operator<<(Char value)
void write(size_t nvalues, const uInt64 *value)
ByteSink & operator<<(const Complex &value)
~ByteSink()
destructor
String: the storage and methods of handling collections of characters.
Definition String.h:355
For temporary backward namespace compatibility, use casa as alias for casacore.
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
NewDelAllocator< T > NewDelAllocator< T >::value
Definition Allocator.h:360
double Double
Definition aipstype.h:53
char Char
Definition aipstype.h:44
unsigned long long uInt64
Definition aipsxtype.h:37