casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
LargeRegularFileIO.h
Go to the documentation of this file.
00001 //# LargeRegularFileIO.h: Class for IO on a regular large file
00002 //# Copyright (C) 1996,1997,1999,2001,2002
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: LargeRegularFileIO.h 20615 2009-06-09 02:16:01Z Malte.Marquarding $
00027 
00028 #ifndef CASA_LARGEREGULARFILEIO_H
00029 #define CASA_LARGEREGULARFILEIO_H
00030 
00031 //# Includes
00032 #include <casa/aips.h>
00033 #include <casa/IO/LargeFilebufIO.h>
00034 #include <casa/OS/RegularFile.h>
00035 
00036 
00037 namespace casa { //# NAMESPACE CASA - BEGIN
00038 
00039 // <summary> 
00040 // Class for IO on a regular large file.
00041 // </summary>
00042 
00043 // <use visibility=export>
00044 
00045 // <reviewed reviewer="Friso Olnon" date="1996/11/06" tests="tByteIO" demos="">
00046 // </reviewed>
00047 
00048 // <prerequisite> 
00049 //    <li> <linkto class=FilebufIO>FilebufIO</linkto> class
00050 // </prerequisite>
00051 
00052 // <synopsis> 
00053 // This class is a specialization of class
00054 // <linkto class=ByteIO>ByteIO</linkto>. It uses a
00055 // <linkto class=RegularFile>regular file</linkto> as the data store.
00056 // <p>
00057 // The class is derived from <linkto class=FilebufIO>FilebufIO</linkto>,
00058 // which contains all functions to access the file. The description of
00059 // this class explains the use of the <src>filebufSize</src> argument
00060 // in the constructor.
00061 // </synopsis>
00062 
00063 // <example>
00064 // <srcblock>
00065 //    // Create a file (which should not exist yet).
00066 //    LargeRegularFileIO regio (RegularFile("file.name"), ByeIO::NewNoReplace);
00067 //    // Use that as the sink of AipsIO.
00068 //    AipsIO stream (&regio);
00069 //    // Write values.
00070 //    stream << (Int)10;
00071 //    stream << True;
00072 //    // Seek to beginning of file and read data in.
00073 //    stream.setpos (0);
00074 //    Int vali;
00075 //    Bool valb;
00076 //    stream >> vali >> valb;
00077 // </srcblock>
00078 // </example>
00079 
00080 
00081 class LargeRegularFileIO: public LargeFilebufIO
00082 {
00083 public: 
00084     // Create an IO stream object for a regular file with the given name.
00085     // The ByteIO option determines if the file will be created
00086     // or opened for input and/or output.
00087     // <br>
00088     // The argument <src>filebufSize</src> defines the length of
00089     // the internal buffer in the underlying <linkto class=FilebufIO>
00090     // FilebufIO</linkto> object. A zero length uses an appropriate default.
00091     explicit LargeRegularFileIO (const RegularFile& regularFile,
00092                                  ByteIO::OpenOption = ByteIO::Old,
00093                                  uInt filebufSize=0);
00094 
00095     ~LargeRegularFileIO();
00096     
00097     // Reopen the underlying file for read/write access.
00098     // Nothing will be done if the stream is writable already.
00099     // Otherwise it will be reopened and an exception will be thrown
00100     // if it is not possible to reopen it for read/write access.
00101     virtual void reopenRW();
00102 
00103     // Get the file name of the file attached.
00104     virtual String fileName() const;
00105 
00106     // Convenience function to open or create a file.
00107     // Optionally it is checked if the file does not exist yet.
00108     // It returns the file descriptor.
00109     static int openCreate (const RegularFile& file, ByteIO::OpenOption);
00110 
00111 private:
00112     OpenOption  itsOption;
00113     RegularFile itsRegularFile;
00114 
00115     // Copy constructor, should not be used.
00116     LargeRegularFileIO (const LargeRegularFileIO& that);
00117 
00118     // Assignment, should not be used.
00119     LargeRegularFileIO& operator= (const LargeRegularFileIO& that);
00120 };
00121 
00122 
00123 
00124 } //# NAMESPACE CASA - END
00125 
00126 #endif