00001 /******************************************************************** 00002 * Binx 00003 * $Id: BxArrayBuffer_8h-source.html,v 1.1.1.1 2006/04/19 14:19:02 edikt2 Exp $ 00004 * 00005 * Class for the array buffer 00006 * 00007 * 00008 * edikt::BinX 00009 * www.edikt.org 00010 * support@edikt.org 00011 * 00012 * Copyright (c) 2005 The University of Edinburgh. 00013 * 00014 ********************************************************************/ 00015 00016 #ifndef BXARRAYBUFFER_H 00017 #define BXARRAYBUFFER_H 00018 00019 #include "BxObject.h" 00020 00021 class BxBinaryFile; 00022 00023 /* 00024 * Class implementing array-knowledgable buffer management for BxArray. 00025 * An array buffer object encapsulates a physical memory-resident buffer and a set of 00026 * attributes describing that buffer. Descriptive attributes include: 00027 * <UL> 00028 * <li> the physical size of the buffer</li> 00029 * <li> the number of array data elements held in the buffer at a given time</li> 00030 * <li> the current buffer position with respect to sequent access to the buffer</li> 00031 * </UL> 00032 * The buffer serves as a window over a binary file that contains data element values. 00033 * As such, it holds a memory-resident chunk of a persistent binary array. 00034 * This class works with the class BxBinaryFile to provide services for 00035 * reading and writing data element values between the buffer and a binary file. 00036 * <BR>This class encapsulates limited understanding of the semantics of arrays. 00037 * Multi-dimensional arrays are viewed as flat one-dimensional arrays. 00038 * An array element is identified by a one-dimensional, zero-based index value, 00039 * representing the elements relative position in the total, flattened array. 00040 * The buffer manager maps the index value into a real byte-offset with the buffer 00041 * or within the file (which contains other array chunks not currently in memory. 00042 * Byte offsets are calculated based on the size of a single data element stored 00043 * by the array. 00044 * <BR><B>Since:</B> BinX version 1.0. 00045 */ 00046 class DECLSPEC BxArrayBuffer : public BxObject 00047 { 00048 public: 00049 // The constructor 00050 BxArrayBuffer(BxBinaryFile* pBFile, long arOffset, int elements, int elemSize); 00051 00052 // The copy constructor 00053 BxArrayBuffer(const BxArrayBuffer& copy); 00054 00055 // The destructor 00056 virtual ~BxArrayBuffer(); 00057 00058 byte* getElement(int elemIndex); 00059 byte* getNextElement(); 00060 byte* getBuffer() const { return buffer_; } 00061 long getArrayOffset() { return arrayOffset_; } 00062 int getElementSize() { return elementSize_; } 00063 00064 void setBuffer(byte* buf); 00065 void setBuffer(byte* buf, int bytes); 00066 00067 bool putNextElement(byte* pBuffer); 00068 00069 // Reset buffer pointer to the beginning 00070 void reset() { currentElementInBuffer_ = -1; } 00071 00072 // This function can be used to flush the buffer 00073 void writeBuffer(); 00074 00075 private: 00076 // Private operations 00077 00078 bool readBuffer(); 00079 00080 00081 // Private data 00082 00083 // The binary file pointer 00084 BxBinaryFile* bfile_; 00085 00086 // The offset of the array in the binary file 00087 long arrayOffset_; 00088 00089 // The total number of elements in the array 00090 int elementCountTotal_; 00091 00092 // The total number of elements in this buffer 00093 int elementCountInBuffer_; 00094 00095 // The size in bytes of an individual element 00096 int elementSize_; 00097 00098 // The current element in the buffer (0 based array) 00099 int currentElementInBuffer_; 00100 00101 // A flag to indicate whether the data file has been read into the buffer 00102 bool read_; 00103 00104 // The buffer containing the array chunk 00105 byte* buffer_; 00106 }; 00107 00108 #endif
1.3.3