本文整理汇总了C++中VSIVirtualHandle::Seek方法的典型用法代码示例。如果您正苦于以下问题:C++ VSIVirtualHandle::Seek方法的具体用法?C++ VSIVirtualHandle::Seek怎么用?C++ VSIVirtualHandle::Seek使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VSIVirtualHandle
的用法示例。
在下文中一共展示了VSIVirtualHandle::Seek方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: VSIFSeekL
int VSIFSeekL( VSILFILE * fp, vsi_l_offset nOffset, int nWhence )
{
VSIVirtualHandle *poFileHandle = (VSIVirtualHandle *) fp;
return poFileHandle->Seek( nOffset, nWhence );
}
示例2: Seek
int VSIBufferedReaderHandle::Seek( vsi_l_offset nOffset, int nWhence )
{
//CPLDebug( "BUFFERED", "Seek(%d,%d)", (int)nOffset, (int)nWhence);
bEOF = FALSE;
if (nWhence == SEEK_CUR)
nCurOffset += nOffset;
else if (nWhence == SEEK_END)
{
poBaseHandle->Seek(nOffset, nWhence);
nCurOffset = poBaseHandle->Tell();
bNeedBaseHandleSeek = TRUE;
}
else
nCurOffset = nOffset;
return 0;
}
示例3: Stat
int VSISparseFileFilesystemHandler::Stat( const char * pszFilename,
VSIStatBufL * psStatBuf,
int nFlags )
{
VSIVirtualHandle *poFile = Open( pszFilename, "r" );
memset( psStatBuf, 0, sizeof(VSIStatBufL) );
if( poFile == NULL )
return -1;
poFile->Seek( 0, SEEK_END );
size_t nLength = (size_t) poFile->Tell();
delete poFile;
int nResult = VSIStatExL( pszFilename + strlen("/vsisparse/"),
psStatBuf, nFlags );
psStatBuf->st_size = nLength;
return nResult;
}
示例4: LoadBlocks
int VSICachedFile::LoadBlocks( size_t nStartBlock, size_t nBlockCount,
void *pBuffer, size_t nBufferSize )
{
if( nBlockCount == 0 )
return 1;
if( apoCache.size() < nStartBlock + nBlockCount )
apoCache.resize( nStartBlock + nBlockCount );
/* -------------------------------------------------------------------- */
/* When we want to load only one block, we can directly load it */
/* into the target buffer with no concern about intermediaries. */
/* -------------------------------------------------------------------- */
if( nBlockCount == 1 )
{
poBase->Seek( nStartBlock * CHUNK_SIZE, SEEK_SET );
apoCache[nStartBlock] = new VSICacheChunk();
VSICacheChunk *poBlock = apoCache[nStartBlock];
poBlock->iBlock = nStartBlock;
poBlock->nDataFilled = poBase->Read( poBlock->abyData, 1, CHUNK_SIZE );
nCacheUsed += poBlock->nDataFilled;
// Merges into the LRU list.
Demote( poBlock );
return 1;
}
/* -------------------------------------------------------------------- */
/* If the buffer is quite large but not quite large enough to */
/* hold all the blocks we will take the pain of splitting the */
/* io request in two in order to avoid allocating a large */
/* temporary buffer. */
/* -------------------------------------------------------------------- */
if( nBufferSize > CHUNK_SIZE * 20
&& nBufferSize < nBlockCount * CHUNK_SIZE )
{
if( !LoadBlocks( nStartBlock, 2, pBuffer, nBufferSize ) )
return 0;
return LoadBlocks( nStartBlock+2, nBlockCount-2, pBuffer, nBufferSize );
}
/* -------------------------------------------------------------------- */
/* Do we need to allocate our own buffer? */
/* -------------------------------------------------------------------- */
GByte *pabyWorkBuffer = (GByte *) pBuffer;
if( nBufferSize < CHUNK_SIZE * nBlockCount )
pabyWorkBuffer = (GByte *) CPLMalloc(CHUNK_SIZE * nBlockCount);
/* -------------------------------------------------------------------- */
/* Read the whole request into the working buffer. */
/* -------------------------------------------------------------------- */
if( poBase->Seek( nStartBlock * CHUNK_SIZE, SEEK_SET ) != 0 )
return 0;
size_t nDataRead = poBase->Read( pabyWorkBuffer, 1, nBlockCount*CHUNK_SIZE);
if( nBlockCount * CHUNK_SIZE > nDataRead + CHUNK_SIZE - 1 )
nBlockCount = (nDataRead + CHUNK_SIZE - 1) / CHUNK_SIZE;
for( size_t i = 0; i < nBlockCount; i++ )
{
VSICacheChunk *poBlock = new VSICacheChunk();
poBlock->iBlock = nStartBlock + i;
CPLAssert( apoCache[i+nStartBlock] == NULL );
apoCache[i + nStartBlock] = poBlock;
if( nDataRead >= (i+1) * CHUNK_SIZE )
poBlock->nDataFilled = CHUNK_SIZE;
else
poBlock->nDataFilled = nDataRead - i*CHUNK_SIZE;
memcpy( poBlock->abyData, pabyWorkBuffer + i*CHUNK_SIZE,
(size_t) poBlock->nDataFilled );
nCacheUsed += poBlock->nDataFilled;
// Merges into the LRU list.
Demote( poBlock );
}
if( pabyWorkBuffer != pBuffer )
CPLFree( pabyWorkBuffer );
return 1;
}
示例5: Read
size_t VSIBufferedReaderHandle::Read( void *pBuffer, size_t nSize, size_t nMemb )
{
const size_t nTotalToRead = nSize * nMemb;
//CPLDebug( "BUFFERED", "Read(%d)", (int)nTotalToRead);
if (nSize == 0)
return 0;
if (nBufferSize != 0 &&
nCurOffset >= nBufferOffset && nCurOffset <= nBufferOffset + nBufferSize)
{
/* We try to read from an offset located within the buffer */
const int nReadInBuffer = (int) MIN(nTotalToRead, nBufferOffset + nBufferSize - nCurOffset);
memcpy(pBuffer, pabyBuffer + nCurOffset - nBufferOffset, nReadInBuffer);
const int nToReadInFile = nTotalToRead - nReadInBuffer;
if (nToReadInFile > 0)
{
/* The beginning of the the data to read is located in the buffer */
/* but the end must be read from the file */
if (bNeedBaseHandleSeek)
poBaseHandle->Seek(nBufferOffset + nBufferSize, SEEK_SET);
bNeedBaseHandleSeek = FALSE;
//CPLAssert(poBaseHandle->Tell() == nBufferOffset + nBufferSize);
const int nReadInFile = poBaseHandle->Read((GByte*)pBuffer + nReadInBuffer, 1, nToReadInFile);
const int nRead = nReadInBuffer + nReadInFile;
nBufferSize = MIN(nRead, MAX_BUFFER_SIZE);
nBufferOffset = nCurOffset + nRead - nBufferSize;
memcpy(pabyBuffer, (GByte*)pBuffer + nRead - nBufferSize, nBufferSize);
nCurOffset += nRead;
//CPLAssert(poBaseHandle->Tell() == nBufferOffset + nBufferSize);
//CPLAssert(poBaseHandle->Tell() == nCurOffset);
bEOF = poBaseHandle->Eof();
return nRead / nSize;
}
else
{
/* The data to read is completely located within the buffer */
nCurOffset += nTotalToRead;
return nTotalToRead / nSize;
}
}
else
{
/* We try either to read before or after the buffer, so a seek is necessary */
poBaseHandle->Seek(nCurOffset, SEEK_SET);
bNeedBaseHandleSeek = FALSE;
const int nReadInFile = poBaseHandle->Read(pBuffer, 1, nTotalToRead);
nBufferSize = MIN(nReadInFile, MAX_BUFFER_SIZE);
nBufferOffset = nCurOffset + nReadInFile - nBufferSize;
memcpy(pabyBuffer, (GByte*)pBuffer + nReadInFile - nBufferSize, nBufferSize);
nCurOffset += nReadInFile;
//CPLAssert(poBaseHandle->Tell() == nBufferOffset + nBufferSize);
//CPLAssert(poBaseHandle->Tell() == nCurOffset);
bEOF = poBaseHandle->Eof();
return nReadInFile / nSize;
}
}