casacore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
StreamIO.h
Go to the documentation of this file.
1 //# StreamIO.h: Class for connection oriented IO to/from a socket
2 //# Copyright (C) 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_STREAMIO_H
29 #define CASA_STREAMIO_H
30 
31 #include <casacore/casa/aips.h>
33 
34 namespace casacore { //# NAMESPACE CASACORE - BEGIN
35 
36 class String;
37 
38 // <summary>Class for IO on connection oriented socket</summary>
39 
40 // <use visibility=export>
41 
42 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
43 // </reviewed>
44 
45 // <prerequisite>
46 // <li> <linkto class=ByteIO>ByteIO</linkto> class
47 // <li> Tape descriptors
48 // </prerequisite>
49 
50 // <synopsis>
51 // This class is a specialization of class
52 // <linkto class=ByteIO>ByteIO</linkto>. It uses a file descriptor
53 // to read/write data to a Internet (AF_INET) stream.
54 // <p>
55 // </synopsis>
56 
57 // <example>
58 // </example>
59 
60 // <motivation>
61 // This class was needed for the online version of the VLA filler.
62 // </motivation>
63 
64 
65 class StreamIO: public ByteIO
66 {
67 public:
68  // Construct a stream that is attached to the specified host on the specified
69  // portnumber. Name lookup is not currently done so that the dotted quad
70  // notation must be used.
71  StreamIO(const String& hostname, uShort portNumber);
72 
73  // The destructor closes the file.
74  virtual ~StreamIO();
75 
76  // Write the specified number of bytes.
77  virtual void write(Int64 size, const void* buf);
78 
79  // Read <src>size</src> bytes from the tape. Returns the number of bytes
80  // actually read or a negative number if an error occured. Will throw an
81  // exception (AipsError) if the requested number of bytes could not be read,
82  // or an error occured, unless throwException is set to False.
83  virtual Int64 read(Int64 size, void* buf, Bool throwException=True);
84 
85  // Get the length of the stream. Not a meaningful function for this
86  // class and this function always returns -1.
87  virtual Int64 length();
88 
89  // Is the stream readable? This function always returns True.
90  virtual Bool isReadable() const;
91 
92  // Is the stream writable? This function always returns True.
93  virtual Bool isWritable() const;
94 
95  // Is the stream seekable? This function always returns False.
96  virtual Bool isSeekable() const;
97 
98 protected:
99  // Reset the position pointer to the given value. It returns the new
100  // position. As stream devices are not seekable calling this function will
101  // always throw an AipsError exception.
102  virtual Int64 doSeek(Int64 offset, ByteIO::SeekOption);
103 
104 private:
105  // The following functions are made private so that the compiler does not
106  // generate default ones. They cannot be used and are not defined.
107  StreamIO (const StreamIO& other);
108  StreamIO& operator= (const StreamIO& other);
109 
111 };
112 
113 } //# NAMESPACE CASACORE - END
114 
115 #endif
virtual Int64 read(Int64 size, void *buf, Bool throwException=True)
Read size bytes from the tape.
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size)
Definition: aipsxtype.h:38
virtual Int64 doSeek(Int64 offset, ByteIO::SeekOption)
Reset the position pointer to the given value.
virtual Bool isSeekable() const
Is the stream seekable? This function always returns False.
SeekOption
Define the possible seek options.
Definition: ByteIO.h:82
Class for IO on connection oriented socket.
Definition: StreamIO.h:65
virtual Bool isWritable() const
Is the stream writable? This function always returns True.
StreamIO & operator=(const StreamIO &other)
virtual Bool isReadable() const
Is the stream readable? This function always returns True.
Abstract base class for IO on a byte stream.
Definition: ByteIO.h:61
virtual Int64 length()
Get the length of the stream.
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
StreamIO(const String &hostname, uShort portNumber)
Construct a stream that is attached to the specified host on the specified portnumber.
virtual ~StreamIO()
The destructor closes the file.
virtual void write(Int64 size, const void *buf)
Write the specified number of bytes.
String: the storage and methods of handling collections of characters.
Definition: String.h:225
const Bool True
Definition: aipstype.h:43
unsigned short uShort
Definition: aipstype.h:49