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