5 static ossimTrace traceDebug(
"BlockStreamBuffer:debug");
11 m_adaptStream(adaptStream)
27 m_blockBuffer.clear();
28 m_blockInfo.setBuffer(s,
n);
36 if(m_blockInfo.isLoaded())
38 setg(m_blockInfo.getBuffer(),
39 m_blockInfo.getBuffer() + (m_currentPosValue - m_blockInfo.m_startByte),
40 m_blockInfo.getBuffer() + m_blockInfo.m_validSize);
51 m_blockInfo.m_blockLoaded =
false;
52 m_blockInfo.m_validSize = 0;
55 if(m_currentPosValue < 0) m_currentPosValue = 0;
56 ossim_int64 blockIndex = m_blockInfo.getBlockIndex(m_currentPosValue);
57 m_blockInfo.m_startByte = blockIndex*m_blockInfo.m_blockSize;
58 if(!m_adaptStream->good()) m_adaptStream->clear();
59 if(m_blockInfo.m_startByte != m_adaptStream->tellg())
61 m_adaptStream->seekg(m_blockInfo.m_startByte);
63 m_adaptStream->read(m_blockInfo.m_blockBufferPtr,
64 m_blockInfo.m_blockSize);
66 if(!m_adaptStream->bad()&&(bytesRead>0))
68 m_blockInfo.m_blockLoaded =
true;
69 m_blockInfo.m_validSize = bytesRead;
70 if((m_blockInfo.m_validSize<=0)||(!m_blockInfo.isWithinValidWindow(m_currentPosValue)))
72 m_blockInfo.m_blockLoaded =
false;
80 off_type offset, std::ios_base::seekdir dir, std::ios_base::openmode )
84 syncCurrentPosition();
85 pos_type result = pos_type(off_type(-1));
91 case std::ios_base::beg:
94 result = seekpos(pos, std::ios_base::in);
97 case std::ios_base::cur:
100 result = seekpos(pos, std::ios_base::in);
103 case std::ios_base::end:
111 result = m_adaptStream->rdbuf()->pubseekoff(pos, dir);
112 m_currentPosValue = result;
127 std::ios_base::openmode mode)
132 <<
"BlockStreamBuffer::seekpos DEBUG: entered with absolute position: " << pos <<
"\n";
134 pos_type result = pos_type(off_type(-1));
138 if(pos == m_currentPosValue)
142 else if(m_blockInfo.isLoaded()&&m_blockInfo.isWithinValidWindow(pos))
145 m_currentPosValue = result;
149 result = m_adaptStream->rdbuf()->pubseekpos(pos, mode);
150 m_currentPosValue = result;
158 <<
"BlockStreamBuffer::seekpos DEBUG: leaving\n";
171 <<
"BlockStreamBuffer::xsgetn DEBUG: entered ......"<<
n<<
"\n";
174 std::streamsize result = EOF;
180 syncCurrentPosition();
182 while(bytesNeedToRead>0)
184 if(!m_blockInfo.isWithinValidWindow(m_currentPosValue))
189 if(m_blockInfo.isLoaded())
193 if(delta <= bytesNeedToRead)
195 std::memcpy(s+bytesRead,
196 m_blockInfo.getBufferStart(m_currentPosValue),
199 bytesNeedToRead-=delta;
200 m_currentPosValue+=delta;
204 std::memcpy(s+bytesRead,
205 m_blockInfo.getBufferStart(m_currentPosValue),
207 m_currentPosValue+=bytesNeedToRead;
208 bytesRead+=bytesNeedToRead;
225 <<
"BlockStreamBuffer::xsgetn DEBUG: leaving ......\n";
236 <<
"BlockStreamBuffer::underflow DEBUG: entered ......\n";
239 if(!m_adaptStream)
return EOF;
241 syncCurrentPosition();
242 if(!m_blockInfo.isWithinValidWindow(m_currentPosValue))
247 if(!m_blockInfo.isLoaded())
255 <<
"BlockStreamBuffer::underflow DEBUG: leaving ......\n";
263 if(m_blockInfo.isLoaded()&&gptr())
265 m_currentPosValue = (m_blockInfo.m_startByte+(gptr()-eback()));
std::vector< char > m_blockBuffer
The block buffer that we set the buf pointers to.
virtual std::streambuf * setbuf(char *s, std::streamsize n)
This is a virtual method that can be overriden.
ossim_int64 m_blockSize
Is the size of the buffer.
char * m_blockBufferPtr
Starting address of the block.
virtual int underflow()
underflow is overriden from the base streambuf.
void loadBlock()
loadBlock will load data into the current block and call the setgPtrs to adjust the internal pointers...
void syncCurrentPosition()
syncCurrentPosition is a utility method that we call internally in the overriden protected methods th...
os2<< "> n<< " > nendobj n
unsigned long long ossim_uint64
virtual std::streamsize xsgetn(char_type *s, std::streamsize n)
xsgetn is a protected virtual method that we override from the base streambuf.
std::basic_istream< char > istream
Base class for char input streams.
virtual pos_type seekoff(off_type offset, std::ios_base::seekdir dir, std::ios_base::openmode mode=std::ios_base::in|std::ios_base::out)
this is a protected method overriden from streambuf base.
BlockStreamBuffer(ossim::istream *adaptStream=0, ossim_uint64 blockSize=0)
void setgPtrs()
setgPtrs calls setg and sets the eback egptr and gptr.
BlockBufInfo m_blockInfo
Holds the information about the block.
virtual pos_type seekpos(pos_type pos, std::ios_base::openmode mode=std::ios_base::in|std::ios_base::out)
seekpos is overriden from the base streambuf class.
unsigned char ossim_uint8
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)