casacore
Loading...
Searching...
No Matches
RegularFileIO.h
Go to the documentation of this file.
1// # RegularFileIO.h: Class for IO on a regular file
2// # Copyright (C) 1996,1997,1999,2001,2002
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_REGULARFILEIO_H
27#define CASA_REGULARFILEIO_H
28
29// # Includes
30#include <casacore/casa/aips.h>
31#include <casacore/casa/IO/FilebufIO.h>
32#include <casacore/casa/OS/RegularFile.h>
33
34namespace casacore { // # NAMESPACE CASACORE - BEGIN
35
36// <summary>
37// Class for IO on a regular file.
38// </summary>
39
40// <use visibility=export>
41
42// <reviewed reviewer="Friso Olnon" date="1996/11/06" tests="tByteIO" demos="">
43// </reviewed>
44
45// <prerequisite>
46// <li> <linkto class=FilebufIO>FilebufIO</linkto> class
47// </prerequisite>
48
49// <synopsis>
50// This class is a specialization of class
51// <linkto class=ByteIO>ByteIO</linkto>. It uses a
52// <linkto class=RegularFile>regular file</linkto> as the data store.
53// <p>
54// The class is derived from <linkto class=FilebufIO>FilebufIO</linkto>,
55// which contains all functions to access the file. The description of
56// this class explains the use of the <src>filebufSize</src> argument
57// in the constructor.
58// </synopsis>
59
60// <example>
61// <srcblock>
62// // Create a file (which should not exist yet).
63// RegularFileIO regio (RegularFile("file.name"), ByteIO::NewNoReplace);
64// // Use that as the sink of AipsIO.
65// AipsIO stream (&regio);
66// // Write values.
67// stream << (Int)10;
68// stream << True;
69// // Seek to beginning of file and read data in.
70// stream.setpos (0);
71// Int vali;
72// Bool valb;
73// stream >> vali >> valb;
74// </srcblock>
75// </example>
76
77class RegularFileIO : public FilebufIO {
78 public:
79 // Create an IO stream object for a regular file with the given name.
80 // The ByteIO option determines if the file will be created
81 // or opened for input and/or output.
82 // <br>
83 // The argument <src>filebufSize</src> defines the length of
84 // the internal buffer in the underlying <linkto class=FilebufIO>
85 // FilebufIO</linkto> object. A zero length uses an appropriate default.
87 uInt filebufSize = 0);
88
90
91 // Reopen the underlying file for read/write access.
92 // Nothing will be done if the stream is writable already.
93 // Otherwise it will be reopened and an exception will be thrown
94 // if it is not possible to reopen it for read/write access.
95 virtual void reopenRW();
96
97 // Get the file name of the file attached.
98 virtual String fileName() const;
99
100 // Convenience function to open or create a file.
101 // Optionally it is checked if the file does not exist yet.
102 // If useODirect=True and if supported by the OS, the file will be opened
103 // with O_DIRECT which bypasses the kernel's file cache for more predictable
104 // I/O behaviour. It requires the size and the alignment of the data to be
105 // read/written to be a multiple of the the disk's logical block size.
106 // It returns the file descriptor.
107 static int openCreate(const RegularFile& file, ByteIO::OpenOption, Bool useODirect = False);
108
109 private:
112
113 // Copy constructor, should not be used.
115
116 // Assignment, should not be used.
118};
119
120} // namespace casacore
121
122#endif
OpenOption
Define the possible ByteIO open options.
Definition ByteIO.h:60
FilebufIO()
Default constructor.
virtual String fileName() const
Get the file name of the file attached.
virtual void reopenRW()
Reopen the underlying file for read/write access.
RegularFileIO & operator=(const RegularFileIO &that)
Assignment, should not be used.
RegularFileIO(const RegularFile &regularFile, ByteIO::OpenOption=ByteIO::Old, uInt filebufSize=0)
Create an IO stream object for a regular file with the given name.
static int openCreate(const RegularFile &file, ByteIO::OpenOption, Bool useODirect=False)
Convenience function to open or create a file.
RegularFileIO(const RegularFileIO &that)
Copy constructor, should not be used.
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
const Bool False
Definition aipstype.h:42
unsigned int uInt
Definition aipstype.h:49
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40