src/Utility/DiscBuffer.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 /***************************************************************************
00003  *
00004  * The IPPL Framework
00005  * 
00006  *
00007  * Visit http://people.web.psi.ch/adelmann/ for more details
00008  *
00009  ***************************************************************************/
00010 
00011 #ifndef DISC_BUFFER_H
00012 #define DISC_BUFFER_H
00013 
00014 /***************************************************************************
00015  * DiscBuffer is a simple utility class that maintains a byte buffer
00016  * for use in I/O operations, one that will grow on demand and will
00017  * be reused until the program quits.  Users should just use the
00018  * static methods to grow and access the buffer.  An instance of this class
00019  * is created when a program starts and is deleted when a program is
00020  * deleted. Users can, but generally should not, create an instances
00021  * of this class themselves.
00022  ***************************************************************************/
00023 
00024 // include files
00025 
00026 #include "Utility/PAssert.h"
00027 
00028 
00029 class DiscBuffer
00030 {
00031 public:
00032   // The default constructor does nothing, this class is mainly an
00033   // interface to the static data.
00034 
00035   DiscBuffer();
00036 
00037   // The destructor will delete the buffer storage if it has been
00038   // previously created.
00039 
00040   ~DiscBuffer();
00041 
00042   //
00043   // Accessor methods.
00044   //
00045 
00046   // Return the current size of the buffer, in bytes.
00047 
00048   static long size()
00049   {
00050     return size_s;
00051   }
00052 
00053   // Return the current buffer pointer, as a void *.
00054 
00055   static void *buffer()
00056   {
00057     return static_cast<void *>(buffer_s);
00058   }
00059 
00060   //
00061   // Modifier methods
00062   //
00063 
00064   // Make sure the current buffer is at least as large as the given
00065   // size.  If it is not, reallocate (but do not copy).  Return the
00066   // buffer pointer.
00067 
00068   static void *resize(long sz);
00069 
00070   // Grow the buffer to add in extra storage of the given amount.
00071   // Return the buffer pointer.
00072 
00073   static void *grow(long amt)
00074   {
00075     PAssert(amt >= 0);
00076     return DiscBuffer::resize(DiscBuffer::size() + amt);
00077   }
00078 
00079   // Some static variables used for statistics, these are really
00080   // hacks so don't count on them.
00081 
00082   static double readtime;
00083   static double writetime;
00084   static long readbytes;
00085   static long writebytes;
00086 
00087 private:
00088   // Static storage for the size of the buffer.
00089 
00090   static long size_s;
00091 
00092   // Static storage for the buffer itself.
00093 
00094   static char *buffer_s;
00095 
00096 };
00097 
00098 
00099 #endif // DISC_BUFFER_H
00100 
00101 /***************************************************************************
00102  * $RCSfile: DiscBuffer.h,v $   $Author: adelmann $
00103  * $Revision: 1.1.1.1 $   $Date: 2003/01/23 07:40:33 $
00104  * IPPL_VERSION_ID: $Id: DiscBuffer.h,v 1.1.1.1 2003/01/23 07:40:33 adelmann Exp $ 
00105  ***************************************************************************/

Generated on Mon Jan 16 13:23:57 2006 for IPPL by  doxygen 1.4.6