40 #ifndef _resourcememorystream_cpp
41 #define _resourcememorystream_cpp
44 #include "stringtool.h"
45 #include "exception.h"
54 #ifdef USENEWDATASTREAM
56 #else //USENEWDATASTREAM
59 FreeBuffer(FreeOnClose)
62 BufferStart =
new UInt8[BufferSize];
63 BufferPos = BufferStart;
64 BufferEnd = BufferStart + BufferSize;
66 if(BufferEnd <= BufferStart)
72 FreeBuffer(FreeOnClose)
74 BufferStart = BufferPos =
static_cast<UInt8*
>(Buffer);
76 BufferEnd = BufferStart + BufferSize;
78 if(BufferEnd <= BufferStart)
107 FreeBuffer = FreeOnClose;
115 size_t RetCount = Count;
116 if(BufferPos + RetCount > BufferEnd)
117 RetCount = BufferEnd - BufferPos;
124 std::memcpy(Buffer,BufferPos,RetCount);
125 BufferPos += RetCount;
135 if(BufferPos + Written > BufferEnd)
136 Written = BufferEnd - BufferPos;
140 std::memcpy(BufferPos,Buffer,Written);
141 BufferPos += Written;
148 size_t NewPos = (size_t)( ( BufferPos - BufferStart ) + Count );
149 if( BufferStart + NewPos > BufferEnd )
152 BufferPos = BufferStart + NewPos;
157 if( BufferStart + Position > BufferEnd || Position < 0 )
160 BufferPos = BufferStart + Position;
182 if(Offset > 0 || Offset <= -
Size)
185 BufferPos = BufferStart + ((
Size - 1) + Offset);
193 return BufferPos - BufferStart;
198 return BufferPos >= BufferEnd;
203 if(FreeBuffer && BufferStart)
205 delete[] BufferStart;
218 if(Delim.find_first_of(
'\n') != String::npos)
223 size_t BytesRead = 0;
224 while(BytesRead < MaxCount && BufferPos < BufferEnd)
226 if(Delim.find(*BufferPos) != String::npos)
228 if(TrimCR && BytesRead && Buffer[BytesRead - 1] ==
'\r')
236 Buffer[BytesRead++] = *BufferPos++;
238 Buffer[BytesRead] =
'\0';
244 size_t BytesSkipped = 0;
245 while(BufferPos < BufferEnd)
248 if(Delim.find(*BufferPos++) != String::npos)
255 #endif //USENEWDATASTREAM