casacore
Loading...
Searching...
No Matches
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: 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_MFFILEIO_H
27#define CASA_MFFILEIO_H
28
29//# Includes
30#include <casacore/casa/aips.h>
31#include <casacore/casa/IO/ByteIO.h>
32#include <casacore/casa/IO/MultiFileBase.h>
33
34
35namespace casacore { //# NAMESPACE CASACORE - BEGIN
36
37 // <summary>
38 // Class for IO on a virtual file in a MultiFileBase
39 // </summary>
40
41 // <use visibility=export>
42
43 // <reviewed reviewer="Friso Olnon" date="1996/11/06" tests="tByteIO" demos="">
44 // </reviewed>
45
46 // <synopsis>
47 // This class is a specialization of class
48 // <linkto class=ByteIO>ByteIO</linkto>. It uses a
49 // <linkto class=MultiFileBase>MultiFileBase</linkto> as the data store.
50 // <p>
51 // Similar to a regular file it is possible to read and write data and to
52 // seek in the file. The object keeps track of the current file offset.
53 // </synopsis>
54
55 // <example>
56 // <srcblock>
57 // // Create a new MultiFile using a block size of 1 MB.
58 // shared_ptr<MultiFileBase> mfile
59 // (new MultiFile("file.mf', ByteIO::New, 1048576));
60 // // Create a virtual file in it.
61 // MFFileIO mf1(mfile, "mf1", ByteIO::New);
62 // // Use it (for example) as the sink of AipsIO.
63 // AipsIO stream (&mf1);
64 // // Write values.
65 // stream << (Int)10;
66 // stream << True;
67 // // Seek to beginning of file and read data in.
68 // stream.setpos (0);
69 // Int vali;
70 // Bool valb;
71 // stream >> vali >> valb;
72 // </srcblock>
73 // </example>
74
75
76 class MFFileIO: public ByteIO
77 {
78 public:
79 // Open or create a virtual file with the given name. Note that only the
80 // basename of the file name is actually used.
81 // It is created in the given MultiFileBase.
82 MFFileIO (const std::shared_ptr<MultiFileBase>&, const String& name,
84
85 // The destructor flushes and closes the file.
86 ~MFFileIO() override;
87
88 // Read <src>size</src> bytes from the byte stream. Returns the number of
89 // bytes actually read, or a negative number if an error occurred. Will also
90 // throw an Exception (AipsError) if the requested number of bytes could
91 // not be read unless throwException is set to False.
92 Int64 read (Int64 size, void* buf, Bool throwException=True) override;
93
94 // Write a block at the current offset.
95 void write (Int64 size, const void* buffer) override;
96
97 // Reopen the file (and possibly underlying MultiFileBase) for read/write access.
98 // Nothing will be done if the stream is writable already.
99 // An exception will be thrown if it is not possible to reopen it for
100 // read/write access.
101 void reopenRW() override;
102
103 // Remove the file from the MultiFileBase object.
104 // It makes the object invalid by setting the fileId to -1.
105 void remove();
106
107 // Flush the file by writing all dirty data and all header info.
108 void flush() override;
109
110 // Get the length of the file.
111 Int64 length() override;
112
113 // The file is always readable.
114 Bool isReadable() const override;
115
116 // Is the file writable?
117 Bool isWritable() const override;
118
119 // The file is always seekable.
120 Bool isSeekable() const override;
121
122 // Get the file name of the file attached.
123 String fileName() const override;
124
125 // Fsync the file (i.e. force the data to be physically written).
126 void fsync() override;
127
128 // Truncate the file to the given size.
129 void truncate (Int64 size) override;
130
131 // Reset the position pointer to the given value. It returns the
132 // new position.
134
135 // Get the MultiFileInfo object for this file.
136 const MultiFileInfo& getInfo() const;
137
138 private:
139 //# Data members
140 std::shared_ptr<MultiFileBase> itsFile;
145 };
146
147
148} //# NAMESPACE CASACORE - END
149
150#endif
SeekOption
Define the possible seek options.
Definition ByteIO.h:80
OpenOption
Define the possible ByteIO open options.
Definition ByteIO.h:63
void write(Int64 size, const void *buffer) override
Write a block at the current offset.
Int64 doSeek(Int64 offset, ByteIO::SeekOption) override
Reset the position pointer to the given value.
~MFFileIO() override
The destructor flushes and closes the file.
Int64 read(Int64 size, void *buf, Bool throwException=True) override
Read size bytes from the byte stream.
void flush() override
Flush the file by writing all dirty data and all header info.
Bool isSeekable() const override
The file is always seekable.
void truncate(Int64 size) override
Truncate the file to the given size.
void remove()
Remove the file from the MultiFileBase object.
String fileName() const override
Get the file name of the file attached.
void fsync() override
Fsync the file (i.e.
Bool isWritable() const override
Is the file writable?
std::shared_ptr< MultiFileBase > itsFile
Definition MFFileIO.h:140
Int64 length() override
Get the length of the file.
Bool isReadable() const override
The file is always readable.
MFFileIO(const std::shared_ptr< MultiFileBase > &, const String &name, ByteIO::OpenOption=ByteIO::Old)
Open or create a virtual file with the given name.
void reopenRW() override
Reopen the file (and possibly underlying MultiFileBase) for read/write access.
const MultiFileInfo & getInfo() const
Get the MultiFileInfo object for this file.
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
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size)
Definition aipsxtype.h:36
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
const Bool True
Definition aipstype.h:41
Helper class for MultiFileBase containing info per logical file.