MemCacheClient

ReadWriteBuffer.h

Go to the documentation of this file.
00001 
00009 #ifndef INCLUDED_ReadWriteBuffer
00010 #define INCLUDED_ReadWriteBuffer
00011 
00012 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
00013 # pragma once
00014 #endif
00015 
00016 // ----------------------------------------------------------------------------
00017 // ReadWriteBuffer
00018 
00042 class ReadWriteBuffer 
00043 {
00044 public:
00046     ReadWriteBuffer();
00047 
00053     ReadWriteBuffer(const ReadWriteBuffer &);
00054 
00060     ReadWriteBuffer & operator=(const ReadWriteBuffer &);
00061 
00063     ~ReadWriteBuffer();
00064 
00066     void Deallocate();
00067 
00069     void SetEmpty();
00070 
00082     void SetExternalBuffer(void * a_pBuf, size_t a_nBufSiz, size_t a_nBufLen = 0, size_t a_nGrowBy = 0); // throw std::invalid_argument 
00083 
00093     void SetInternalBuffer(size_t a_nInitialSize, size_t a_nGrowBy = 1024); // throw std::bad_alloc
00094 
00116     char * GetWriteBuffer(size_t a_nMinBytes = 0); // throw std::overflow_error, std::bad_alloc
00117 
00128     void CommitWriteBytes(size_t a_nBytes); // throw std::invalid_argument
00129 
00135     size_t GetWriteSize() const;
00136 
00150     void WriteBytes(const void * a_pBuf, size_t a_nBufLen); // throw std::overflow_error, std::bad_alloc
00151 
00159     const char * GetReadBuffer() const;
00160 
00171     void CommitReadBytes(size_t a_nBytes); // throw std::invalid_argument
00172 
00177     size_t GetReadSize() const;
00178 
00189     void ReadBytes(void * a_pBuf, size_t a_nBufLen); // throw std::invalid_argument
00190 
00196     void Compact();
00197 
00199     bool operator==(const ReadWriteBuffer &) const;
00200 
00201 private:
00202     size_t mBufSiz; 
00203     size_t mBufLen; 
00204     size_t mBufIdx; 
00205     size_t mGrowBy; 
00206     bool   mIsExt;  
00207     char * mBuf;    
00208 };
00209 
00210 #endif // INCLUDED_ReadWriteBuffer