casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MFFileIO.h
Go to the documentation of this file.
1 //# MFFileIO.h: Class for IO on a virtual file in a MultiFileBase
2 //# Copyright (C) 2014
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: RegularFileIO.h 20551 2009-03-25 00:11:33Z Malte.Marquarding $
27 
28 #ifndef CASA_MFFILEIO_H
29 #define CASA_MFFILEIO_H
30 
31 //# Includes
32 #include <casacore/casa/aips.h>
35 
36 
37 namespace casacore { //# NAMESPACE CASACORE - BEGIN
38 
39  // <summary>
40  // Class for IO on a virtual file in a MultiFileBase
41  // </summary>
42 
43  // <use visibility=export>
44 
45  // <reviewed reviewer="Friso Olnon" date="1996/11/06" tests="tByteIO" demos="">
46  // </reviewed>
47 
48  // <synopsis>
49  // This class is a specialization of class
50  // <linkto class=ByteIO>ByteIO</linkto>. It uses a
51  // <linkto class=MultiFileBase>MultiFileBase</linkto> as the data store.
52  // <p>
53  // Similar to a regular file it is possible to read and write data and to
54  // seek in the file. The object keeps track of the current file offset.
55  // </synopsis>
56 
57  // <example>
58  // <srcblock>
59  // // Create a new MultiFile using a block size of 1 MB.
60  // MultiFile mfile("file.mf', ByteIO::New, 1048576);
61  // // Create a virtual file in it.
62  // MFFileIO mf1(mfile, "mf1", ByteIO::New);
63  // // Use it (for example) as the sink of AipsIO.
64  // AipsIO stream (&mf1);
65  // // Write values.
66  // stream << (Int)10;
67  // stream << True;
68  // // Seek to beginning of file and read data in.
69  // stream.setpos (0);
70  // Int vali;
71  // Bool valb;
72  // stream >> vali >> valb;
73  // </srcblock>
74  // </example>
75 
76 
77  class MFFileIO: public ByteIO
78  {
79  public:
80  // Open or create a virtual file with the given name. Note that only the
81  // basename of the file name is actually used.
82  // It is created in the given MultiFileBase.
85 
86  // The destructor flushes and closes the file.
87  virtual ~MFFileIO();
88 
89  // Read <src>size</src> bytes from the byte stream. Returns the number of
90  // bytes actually read, or a negative number if an error occurred. Will also
91  // throw an Exception (AipsError) if the requested number of bytes could
92  // not be read unless throwException is set to False.
93  virtual Int64 read (Int64 size, void* buf, Bool throwException=True);
94 
95  // Write a block at the given offset.
96  virtual void write (Int64 size, const void* buffer);
97 
98  // Reopen the file (and possibly underlying MultiFileBase) for read/write access.
99  // Nothing will be done if the stream is writable already.
100  // An exception will be thrown if it is not possible to reopen it for
101  // read/write access.
102  virtual void reopenRW();
103 
104  // Remove the file from the MultiFileBase object.
105  // It makes the object invalid by setting the fileId to -1.
106  void remove();
107 
108  // Flush the file by writing all dirty data and all header info.
109  virtual void flush();
110 
111  // Get the length of the file.
112  virtual Int64 length();
113 
114  // The file is always readable.
115  virtual Bool isReadable() const;
116 
117  // Is the file writable?
118  virtual Bool isWritable() const;
119 
120  // The file is always seekable.
121  virtual Bool isSeekable() const;
122 
123  // Get the file name of the file attached.
124  virtual String fileName() const;
125 
126  // Fsync the file (i.e. force the data to be physically written).
127  virtual void fsync();
128 
129  // Reset the position pointer to the given value. It returns the
130  // new position.
131  virtual Int64 doSeek (Int64 offset, ByteIO::SeekOption);
132 
133  private:
134  //# Data members
139  };
140 
141 
142 } //# NAMESPACE CASACORE - END
143 
144 #endif
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size)
Definition: aipsxtype.h:38
int Int
Definition: aipstype.h:50
virtual ~MFFileIO()
The destructor flushes and closes the file.
Abstract base class to combine multiple files in a single one.
SeekOption
Define the possible seek options.
Definition: ByteIO.h:82
MultiFileBase & itsFile
Definition: MFFileIO.h:135
virtual Int64 length()
Get the length of the file.
virtual Bool isSeekable() const
The file is always seekable.
virtual Int64 doSeek(Int64 offset, ByteIO::SeekOption)
Reset the position pointer to the given value.
virtual void fsync()
Fsync the file (i.e.
ABSTRACT CLASSES Abstract class for colors Any implementation of color should be able to provide a hexadecimal form of the if a human readable name(i.e."black").In many places throughout the plotter
virtual void flush()
Flush the file by writing all dirty data and all header info.
size_t size() const
virtual void reopenRW()
Reopen the file (and possibly underlying MultiFileBase) for read/write access.
virtual Bool isWritable() const
Is the file writable?
virtual Int64 read(Int64 size, void *buf, Bool throwException=True)
Read size bytes from the byte stream.
virtual void write(Int64 size, const void *buffer)
Write a block at the given offset.
Abstract base class for IO on a byte stream.
Definition: ByteIO.h:61
MFFileIO(MultiFileBase &, const String &name, ByteIO::OpenOption=ByteIO::Old)
Open or create a virtual file with the given name.
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
OpenOption
Define the possible ByteIO open options.
Definition: ByteIO.h:65
virtual Bool isReadable() const
The file is always readable.
virtual String fileName() const
Get the file name of the file attached.
String: the storage and methods of handling collections of characters.
Definition: String.h:223
Class for IO on a virtual file in a MultiFileBase.
Definition: MFFileIO.h:77
const Bool True
Definition: aipstype.h:43
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42