MFFileIO.h

Go to the documentation of this file.
00001 //# MFFileIO.h: Class for IO on a virtual file in a MultiFileBase
00002 //# Copyright (C) 2014
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //# $Id: RegularFileIO.h 20551 2009-03-25 00:11:33Z Malte.Marquarding $
00027 
00028 #ifndef CASA_MFFILEIO_H
00029 #define CASA_MFFILEIO_H
00030 
00031 //# Includes
00032 #include <casacore/casa/aips.h>
00033 #include <casacore/casa/IO/ByteIO.h>
00034 #include <casacore/casa/IO/MultiFileBase.h>
00035 
00036 
00037 namespace casacore { //# NAMESPACE CASACORE - BEGIN
00038 
00039   // <summary> 
00040   // Class for IO on a virtual file in a MultiFileBase
00041   // </summary>
00042 
00043   // <use visibility=export>
00044 
00045   // <reviewed reviewer="Friso Olnon" date="1996/11/06" tests="tByteIO" demos="">
00046   // </reviewed>
00047 
00048   // <synopsis> 
00049   // This class is a specialization of class
00050   // <linkto class=ByteIO>ByteIO</linkto>. It uses a
00051   // <linkto class=MultiFileBase>MultiFileBase</linkto> as the data store.
00052   // <p>
00053   // Similar to a regular file it is possible to read and write data and to
00054   // seek in the file. The object keeps track of the current file offset.
00055   // </synopsis>
00056 
00057   // <example>
00058   // <srcblock>
00059   //    // Create a new MultiFile using a block size of 1 MB.
00060   //    MultiFile mfile("file.mf', ByteIO::New, 1048576);
00061   //    // Create a virtual file in it.
00062   //    MFFileIO mf1(mfile, "mf1", ByteIO::New);
00063   //    // Use it (for example) as the sink of AipsIO.
00064   //    AipsIO stream (&mf1);
00065   //    // Write values.
00066   //    stream << (Int)10;
00067   //    stream << True;
00068   //    // Seek to beginning of file and read data in.
00069   //    stream.setpos (0);
00070   //    Int vali;
00071   //    Bool valb;
00072   //    stream >> vali >> valb;
00073   // </srcblock>
00074   // </example>
00075 
00076 
00077   class MFFileIO: public ByteIO
00078   {
00079   public:
00080     // Open or create a virtual file with the given name. Note that only the
00081     // basename of the file name is actually used.
00082     // It is created in the given MultiFileBase.
00083     MFFileIO (MultiFileBase&, const String& name,
00084               ByteIO::OpenOption = ByteIO::Old);
00085 
00086     // The destructor flushes and closes the file.
00087     virtual ~MFFileIO();
00088 
00089     // Read <src>size</src> bytes from the byte stream. Returns the number of
00090     // bytes actually read, or a negative number if an error occurred. Will also
00091     // throw an Exception (AipsError) if the requested number of bytes could
00092     // not be read unless throwException is set to False.
00093     virtual Int64 read (Int64 size, void* buf, Bool throwException=True);
00094 
00095     // Write a block at the given offset.
00096     virtual void write (Int64 size, const void* buffer);
00097 
00098     // Reopen the file (and possibly underlying MultiFileBase) for read/write access.
00099     // Nothing will be done if the stream is writable already.
00100     // An exception will be thrown if it is not possible to reopen it for
00101     // read/write access.
00102     virtual void reopenRW();
00103 
00104     // Remove the file from the MultiFileBase object.
00105     // It makes the object invalid by setting the fileId to -1.
00106     void remove();
00107 
00108     // Flush the file by writing all dirty data and all header info.
00109     virtual void flush();
00110 
00111     // Get the length of the file.
00112     virtual Int64 length();
00113        
00114     // The file is always readable.
00115     virtual Bool isReadable() const;
00116 
00117     // Is the file writable?
00118     virtual Bool isWritable() const;
00119 
00120     // The file is always seekable.
00121     virtual Bool isSeekable() const;
00122 
00123     // Get the file name of the file attached.
00124     virtual String fileName() const;
00125 
00126     // Fsync the file (i.e. force the data to be physically written).
00127     virtual void fsync();
00128 
00129     // Reset the position pointer to the given value. It returns the
00130     // new position.
00131     virtual Int64 doSeek (Int64 offset, ByteIO::SeekOption);
00132 
00133   private:
00134     //# Data members
00135     MultiFileBase& itsFile;
00136     Int64          itsPosition;
00137     String         itsName;
00138     Int            itsId;
00139   };
00140 
00141 
00142 } //# NAMESPACE CASACORE - END
00143 
00144 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1