casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
TSMFile.h
Go to the documentation of this file.
00001 //# TSMFile.h: File object for Tiled Storage Manager
00002 //# Copyright (C) 1995,1996,1997,1999,2001
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: TSMFile.h 20859 2010-02-03 13:14:15Z gervandiepen $
00027 
00028 #ifndef TABLES_TSMFILE_H
00029 #define TABLES_TSMFILE_H
00030 
00031 //# Includes
00032 #include <casa/aips.h>
00033 #include <casa/IO/BucketFile.h>
00034 
00035 namespace casa { //# NAMESPACE CASA - BEGIN
00036 
00037 //# Forward Declarations
00038 class TSMOption;
00039 class TiledStMan;
00040 class AipsIO;
00041 
00042 // <summary>
00043 // File object for Tiled Storage Manager.
00044 // </summary>
00045 
00046 // <use visibility=local>
00047 
00048 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
00049 // </reviewed>
00050 
00051 // <prerequisite>
00052 //# Classes you should understand before using this one.
00053 //   <li> <linkto class=TiledStMan>TiledStMan</linkto>
00054 // </prerequisite>
00055 
00056 // <etymology>
00057 // TSMFile represents a data file for the Tiled Storage Manager.
00058 // </etymology>
00059 
00060 // <synopsis>
00061 // A TSMFile object represents a data file. Currently it is meant
00062 // for the TiledStMan classes, but it can easily be turned into
00063 // a more general storage manager file class.
00064 // <br>
00065 // Creation of a TSMFile object does not open the file.
00066 // An explicit open call has to be given before the file can be used.
00067 // <p>
00068 // Underneath it uses a BucketFile to access the file.
00069 // In this way the IO details are well encapsulated.
00070 // </synopsis> 
00071 
00072 // <motivation>
00073 // Encapsulate the Tiled Storage Manager file details.
00074 // </motivation>
00075 
00076 //# <todo asof="$DATE:$">
00077 //# </todo>
00078 
00079 
00080 class TSMFile
00081 {
00082 public:
00083     // Create a TSMFile object (with corresponding file).
00084     // The sequence number gets part of the file name.
00085     TSMFile (const TiledStMan* stMan, uInt fileSequenceNr,
00086              const TSMOption&);
00087 
00088     // Create a TSMFile object for the given existing file.
00089     TSMFile (const String& fileName, Bool writable, const TSMOption&);
00090 
00091     // Read the object back.
00092     // The file is not opened until the first access,
00093     // thus until the file descriptor is asked for the first time.
00094     // It checks if the sequence number matches the expected one.
00095     TSMFile (const TiledStMan* stMan, AipsIO& ios, uInt seqnr,
00096              const TSMOption&);
00097 
00098     // The destructor closes the file.
00099     ~TSMFile();
00100 
00101     // Write the object.
00102     void putObject (AipsIO& ios) const;
00103 
00104     // Get the object.
00105     void getObject (AipsIO& ios);
00106 
00107     // Open the file if not open yet.
00108     void open();
00109 
00110     // Return the BucketFile object (to be used in the BucketCache).
00111     BucketFile* bucketFile();
00112 
00113     // Return the logical file length.
00114     Int64 length() const;
00115 
00116     // Return the file sequence number.
00117     uInt sequenceNumber() const;
00118 
00119     // Increment the logical file length.
00120     void extend (Int64 increment);
00121 
00122 
00123 private:
00124     // The file sequence number.
00125     uInt fileSeqnr_p;
00126     // The file object.
00127     BucketFile* file_p;
00128     // The (logical) length of the file.
00129     Int64 length_p;
00130             
00131 
00132     // Forbid copy constructor.
00133     TSMFile (const TSMFile&);
00134 
00135     // Forbid assignment.
00136     TSMFile& operator= (const TSMFile&);
00137 };
00138 
00139 
00140 inline Int64 TSMFile::length() const
00141     { return length_p; }
00142 
00143 inline uInt TSMFile::sequenceNumber() const
00144     { return fileSeqnr_p; }
00145 
00146 inline void TSMFile::extend (Int64 increment)
00147     { length_p += increment; }
00148 
00149 inline BucketFile* TSMFile::bucketFile()
00150     { return file_p; }
00151 
00152 inline void TSMFile::open()
00153     { file_p->open(); }
00154 
00155 
00156 
00157 } //# NAMESPACE CASA - END
00158 
00159 #endif