casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
BucketBase.h
Go to the documentation of this file.
00001 //# BucketBase.h: Abstract base class for Bucket classes
00002 //# Copyright (C) 2010
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: BucketBase.h 20859 2010-02-03 13:14:15Z gervandiepen $
00027 
00028 #ifndef CASA_BUCKETBASE_H
00029 #define CASA_BUCKETBASE_H
00030 
00031 //# Includes
00032 #include <casa/aips.h>
00033 #include <casa/IO/BucketFile.h>
00034 
00035 
00036 namespace casa { //# NAMESPACE CASA - BEGIN
00037 
00038   // <summary>
00039   // Abstract base class for Bucket classes.
00040   // </summary>
00041 
00042   // <use visibility=local>
00043 
00044   // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
00045   // </reviewed>
00046 
00047   // <prerequisite>
00048   //# Classes you should understand before using this one.
00049   //   <li> <linkto class=BucketFile>BucketFile</linkto>
00050   // </prerequisite>
00051 
00052   // <synopsis>
00053   // BucketBase is the abstract baseclass for the various Bucket classes
00054   // like BucketMapped and BucketBuffered.
00055   // It is used by TSMCube to do the IO in the required way.
00056   // </synopsis> 
00057 
00058 
00059   class BucketBase
00060   {
00061   public:
00062     // Create the bucket access for (part of) a file.
00063     // The file part starts at startOffset. Its length is
00064     // bucketSize*nrOfBuckets bytes.
00065     // If the file is smaller, the remainder is indicated as an extension
00066     // similarly to the behaviour of function extend.
00067     BucketBase (BucketFile* file, Int64 startOffset, uInt bucketSize,
00068                 uInt nrOfBuckets);
00069 
00070     // Detach the file. The BucketFile is not closed.
00071     virtual ~BucketBase();
00072 
00073     // Flush the cached buckets.
00074     // Possibly remaining uninitialized buckets will be initialized first.
00075     // A True status is returned if buckets had to be written.
00076     // The actual flushing is done using <src>doFlush</src> in the derived
00077     // class.
00078     Bool flush();
00079 
00080     // Resynchronize the object (after another process updated the file).
00081     // It remaps the file if the nr of buckets has changed.
00082     // the new sizes.
00083     virtual void resync (uInt nrBucket);
00084 
00085     // Get the current nr of buckets in the file.
00086     uInt nBucket() const
00087       { return itsCurNrOfBuckets; }
00088 
00089     // Extend the file with the given number of buckets.
00090     // The buckets get initialized when they are acquired
00091     // (using getBucket) for the first time.
00092     void extend (uInt nrBucket);
00093 
00094     // Set that data has been written.
00095     void setWritten()
00096       { itsHasWritten = True; }
00097 
00098 protected:
00099     // Copy constructor is not possible.
00100     BucketBase (const BucketBase&);
00101 
00102     // Assignment is not possible.
00103     BucketBase& operator= (const BucketBase&);
00104 
00105     // Do the actual flushing.
00106     virtual void doFlush() = 0;
00107 
00108     // Do the actual resync-ing.
00109     virtual void doResync() = 0;
00110 
00111     // Do the actual extension of the file.
00112     // Note that itsNewNrOfBuckets has been increased before doExtend is called.
00113     virtual void doExtend (uInt nrBucket) = 0;
00114 
00115     // Initialize the bucket buffer.
00116     // The uninitialized buckets before this bucket are also initialized.
00117     virtual void initializeBuckets (uInt bucketNr) = 0;
00118 
00119 
00120     // The file used.
00121     BucketFile* itsFile;
00122     // The starting offsets of the buckets in the file.
00123     Int64   itsStartOffset;
00124     // The bucket size.
00125     uInt    itsBucketSize;
00126     // The current nr of buckets in the file.
00127     uInt    itsCurNrOfBuckets;
00128     // The new nr of buckets in the file (after extension).
00129     uInt    itsNewNrOfBuckets;
00130     // Have data been written?
00131     Bool    itsHasWritten;
00132 };
00133 
00134 
00135 } //# NAMESPACE CASA - END
00136 
00137 #endif