Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef GDCMBYTEBUFFER_H
00016 #define GDCMBYTEBUFFER_H
00017
00018 #include "gdcmTypes.h"
00019 #include <vector>
00020 #include <assert.h>
00021 #include <string.h>
00022
00023 #error should not be used
00024
00025 namespace gdcm
00026 {
00035 class ByteBuffer
00036 {
00037 static const int InitBufferSize = 1024;
00038 public:
00039 ByteBuffer() : Start(0), End(0),Limit(0) {}
00040 char *Get(int len)
00041 {
00042 char *buffer = &Internal[0];
00043 if (len > Limit - End)
00044 {
00045
00046 int neededSize = len + (End - Start);
00047 if (neededSize <= Limit - buffer)
00048 {
00049 memmove(buffer, Start, End - Start);
00050 End = buffer + (End - Start);
00051 Start = buffer;
00052 }
00053 else
00054 {
00055 char *newBuf;
00056 int bufferSize = Limit - Start;
00057 if ( bufferSize == 0 )
00058 {
00059 bufferSize = InitBufferSize;
00060 }
00061 do
00062 {
00063 bufferSize *= 2;
00064 } while (bufferSize < neededSize);
00065
00066 try
00067 {
00068 Internal.reserve(bufferSize);
00069 newBuf = &Internal[0];
00070 }
00071 catch(...)
00072 {
00073
00074 return 0;
00075 }
00076 Limit = newBuf + bufferSize;
00077
00078 if (Start)
00079 {
00080 memcpy(newBuf, Start, End - Start);
00081 }
00082 End = newBuf + (End - Start);
00083 Start = newBuf;
00084 }
00085 }
00086 assert( (int)Internal.capacity() >= len );
00087 return End;
00088 }
00089
00090 void UpdatePosition() {}
00091 void ShiftEnd(int len) {
00092 End += len;
00093 }
00094 const char *GetStart() const {
00095 return Start;
00096 }
00097
00098 private:
00099 typedef std::vector<char> CharVector;
00100 const char *Start;
00101 char *End;
00102 const char *Limit;
00103 CharVector Internal;
00104 };
00105
00106 }
00107
00108 #endif //GDCMBYTEBUFFER_H