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