OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
DiscBuffer.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 /***************************************************************************
3  *
4  * The IPPL Framework
5  *
6  *
7  * Visit http://people.web.psi.ch/adelmann/ for more details
8  *
9  ***************************************************************************/
10 
11 #ifndef DISC_BUFFER_H
12 #define DISC_BUFFER_H
13 
14 /***************************************************************************
15  * DiscBuffer is a simple utility class that maintains a byte buffer
16  * for use in I/O operations, one that will grow on demand and will
17  * be reused until the program quits. Users should just use the
18  * static methods to grow and access the buffer. An instance of this class
19  * is created when a program starts and is deleted when a program is
20  * deleted. Users can, but generally should not, create an instances
21  * of this class themselves.
22  ***************************************************************************/
23 
24 // include files
25 
26 #include "Utility/PAssert.h"
27 
28 
30 {
31 public:
32  // The default constructor does nothing, this class is mainly an
33  // interface to the static data.
34 
35  DiscBuffer();
36 
37  // The destructor will delete the buffer storage if it has been
38  // previously created.
39 
40  ~DiscBuffer();
41 
42  //
43  // Accessor methods.
44  //
45 
46  // Return the current size of the buffer, in bytes.
47 
48  static long size()
49  {
50  return size_s;
51  }
52 
53  // Return the current buffer pointer, as a void *.
54 
55  static void *buffer()
56  {
57  return static_cast<void *>(buffer_s);
58  }
59 
60  //
61  // Modifier methods
62  //
63 
64  // Make sure the current buffer is at least as large as the given
65  // size. If it is not, reallocate (but do not copy). Return the
66  // buffer pointer.
67 
68  static void *resize(long sz);
69 
70  // Grow the buffer to add in extra storage of the given amount.
71  // Return the buffer pointer.
72 
73  static void *grow(long amt)
74  {
75  PAssert_GE(amt, 0);
76  return DiscBuffer::resize(DiscBuffer::size() + amt);
77  }
78 
79  // Some static variables used for statistics, these are really
80  // hacks so don't count on them.
81 
82  static double readtime;
83  static double writetime;
84  static long readbytes;
85  static long writebytes;
86 
87 private:
88  // Static storage for the size of the buffer.
89 
90  static long size_s;
91 
92  // Static storage for the buffer itself.
93 
94  static char *buffer_s;
95 
96 };
97 
98 
99 #endif // DISC_BUFFER_H
100 
101 /***************************************************************************
102  * $RCSfile: DiscBuffer.h,v $ $Author: adelmann $
103  * $Revision: 1.1.1.1 $ $Date: 2003/01/23 07:40:33 $
104  * IPPL_VERSION_ID: $Id: DiscBuffer.h,v 1.1.1.1 2003/01/23 07:40:33 adelmann Exp $
105  ***************************************************************************/
static long readbytes
Definition: DiscBuffer.h:84
static void * resize(long sz)
Definition: DiscBuffer.cpp:83
static void * grow(long amt)
Definition: DiscBuffer.h:73
static double readtime
Definition: DiscBuffer.h:82
#define PAssert_GE(a, b)
Definition: PAssert.h:124
static char * buffer_s
Definition: DiscBuffer.h:94
static void * buffer()
Definition: DiscBuffer.h:55
static long size()
Definition: DiscBuffer.h:48
static long writebytes
Definition: DiscBuffer.h:85
static long size_s
Definition: DiscBuffer.h:90
static double writetime
Definition: DiscBuffer.h:83