00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef BUFFER_H
00022 #define BUFFER_H
00023
00024 #include <assert.h>
00025 #include <stdint.h>
00026
00027 template <class T> class Buffer_sidtt
00028 {
00029 public:
00030 Buffer_sidtt() : dummy(0)
00031 {
00032 kill();
00033 }
00034
00035 Buffer_sidtt(T* inBuf, uint_least32_t inLen) : dummy(0)
00036 {
00037 kill();
00038 if (inBuf!=0 && inLen!=0)
00039 {
00040 buf = inBuf;
00041 bufLen = inLen;
00042 }
00043 }
00044
00045 bool assign(T* newBuf, uint_least32_t newLen)
00046 {
00047 erase();
00048 buf = newBuf;
00049 bufLen = newLen;
00050 return (buf!=0);
00051 }
00052
00053 T* get() const { return buf; }
00054 uint_least32_t len() const { return bufLen; }
00055
00056 T* xferPtr()
00057 {
00058 T* tmpBuf = buf;
00059 buf = 0;
00060 return tmpBuf;
00061 }
00062
00063 uint_least32_t xferLen()
00064 {
00065 const uint_least32_t tmpBufLen = bufLen;
00066 bufLen = 0;
00067 return tmpBufLen;
00068 }
00069
00070 T& operator[](uint_least32_t index)
00071 {
00072 return (index < bufLen) ? buf[index] : dummy;
00073 }
00074
00075 bool isEmpty() const { return (buf==0); }
00076
00077 void erase()
00078 {
00079 if (buf!=0 && bufLen!=0)
00080 {
00081 #ifndef SID_HAVE_BAD_COMPILER
00082 delete[] buf;
00083 #else
00084 delete[] (void *) buf;
00085 #endif
00086 }
00087 kill();
00088 }
00089
00090 ~Buffer_sidtt()
00091 {
00092 erase();
00093 }
00094
00095 private:
00096 T* buf;
00097 uint_least32_t bufLen;
00098 T dummy;
00099
00100 void kill()
00101 {
00102 buf = 0;
00103 bufLen = 0;
00104 }
00105
00106 private:
00107
00108
00109
00110 Buffer_sidtt(const Buffer_sidtt&) : dummy (0) { assert(0); }
00111 Buffer_sidtt& operator=(Buffer_sidtt& b)
00112 {
00113 assert(0);
00114 return b;
00115 }
00116 };
00117
00118 #endif