📄 cpl_vsil.cpp
字号:
* Analog of the POSIX fseek() call. * * @param fp file handle opened with VSIFOpenL(). * @param nOffset offset in bytes. * @param nWhence one of SEEK_SET, SEEK_CUR or SEEK_END. * * @return 0 on success or -1 one failure. */int VSIFSeekL( FILE * fp, vsi_l_offset nOffset, int nWhence ){ VSIVirtualHandle *poFileHandle = (VSIVirtualHandle *) fp; return poFileHandle->Seek( nOffset, nWhence );}/************************************************************************//* VSIFTellL() *//************************************************************************//** * \brief Tell current file offset. * * Returns the current file read/write offset in bytes from the beginning of * the file. * * This method goes through the VSIFileHandler virtualization and may * work on unusual filesystems such as in memory. * * Analog of the POSIX ftell() call. * * @param fp file handle opened with VSIFOpenL(). * * @return file offset in bytes. */vsi_l_offset VSIFTellL( FILE * fp ){ VSIVirtualHandle *poFileHandle = (VSIVirtualHandle *) fp; return poFileHandle->Tell();}/************************************************************************//* VSIRewindL() *//************************************************************************/void VSIRewindL( FILE * fp ){ VSIFSeekL( fp, 0, SEEK_SET );}/************************************************************************//* VSIFFlushL() *//************************************************************************//** * \brief Flush pending writes to disk. * * For files in write or update mode and on filesystem types where it is * applicable, all pending output on the file is flushed to the physical disk. * * This method goes through the VSIFileHandler virtualization and may * work on unusual filesystems such as in memory. * * Analog of the POSIX fflush() call. * * @param fp file handle opened with VSIFOpenL(). * * @return 0 on success or -1 on error. */int VSIFFlushL( FILE * fp ){ VSIVirtualHandle *poFileHandle = (VSIVirtualHandle *) fp; return poFileHandle->Flush();}/************************************************************************//* VSIFReadL() *//************************************************************************//** * \brief Read bytes from file. * * Reads nCount objects of nSize bytes from the indicated file at the * current offset into the indicated buffer. * * This method goes through the VSIFileHandler virtualization and may * work on unusual filesystems such as in memory. * * Analog of the POSIX fread() call. * * @param pBuffer the buffer into which the data should be read (at least * nCount * nSize bytes in size. * @param nSize size of objects to read in bytes. * @param nCount number of objects to read. * @param fp file handle opened with VSIFOpenL(). * * @return number of objects successfully read. */size_t VSIFReadL( void * pBuffer, size_t nSize, size_t nCount, FILE * fp ){ VSIVirtualHandle *poFileHandle = (VSIVirtualHandle *) fp; return poFileHandle->Read( pBuffer, nSize, nCount );}/************************************************************************//* VSIFWriteL() *//************************************************************************//** * \brief Write bytes to file. * * Writess nCount objects of nSize bytes to the indicated file at the * current offset into the indicated buffer. * * This method goes through the VSIFileHandler virtualization and may * work on unusual filesystems such as in memory. * * Analog of the POSIX fwrite() call. * * @param pBuffer the buffer from which the data should be written (at least * nCount * nSize bytes in size. * @param nSize size of objects to read in bytes. * @param nCount number of objects to read. * @param fp file handle opened with VSIFOpenL(). * * @return number of objects successfully written. */size_t VSIFWriteL( const void *pBuffer, size_t nSize, size_t nCount, FILE *fp ){ VSIVirtualHandle *poFileHandle = (VSIVirtualHandle *) fp; return poFileHandle->Write( pBuffer, nSize, nCount );}/************************************************************************//* VSIFEofL() *//************************************************************************//** * \brief Test for end of file. * * Returns TRUE (non-zero) if the file read/write offset is currently at the * end of the file. * * This method goes through the VSIFileHandler virtualization and may * work on unusual filesystems such as in memory. * * Analog of the POSIX feof() call. * * @param fp file handle opened with VSIFOpenL(). * * @return TRUE if at EOF else FALSE. */int VSIFEofL( FILE * fp ){ VSIVirtualHandle *poFileHandle = (VSIVirtualHandle *) fp; return poFileHandle->Eof();}/************************************************************************//* ==================================================================== *//* VSIFileManager() *//* ==================================================================== *//************************************************************************//*** Notes on Multithreading:**** The VSIFileManager maintains a list of file type handlers (mem, large** file, etc). It should be thread safe as long as all the handlers are** instantiated before multiple threads begin to operate. **//************************************************************************//* VSIFileManager() *//************************************************************************/VSIFileManager::VSIFileManager(){ poDefaultHandler = NULL;}/************************************************************************//* ~VSIFileManager() *//************************************************************************/VSIFileManager::~VSIFileManager(){ std::map<std::string,VSIFilesystemHandler*>::const_iterator iter; for( iter = oHandlers.begin(); iter != oHandlers.end(); iter++ ) { delete iter->second; } delete poDefaultHandler;}/************************************************************************//* Get() *//************************************************************************/static VSIFileManager *poManager = NULL;VSIFileManager *VSIFileManager::Get(){ if( poManager == NULL ) { poManager = new VSIFileManager; VSIInstallLargeFileHandler(); VSIInstallMemFileHandler(); } return poManager;}/************************************************************************//* GetHandler() *//************************************************************************/VSIFilesystemHandler *VSIFileManager::GetHandler( const char *pszPath ){ VSIFileManager *poThis = Get(); std::map<std::string,VSIFilesystemHandler*>::const_iterator iter; for( iter = poThis->oHandlers.begin(); iter != poThis->oHandlers.end(); iter++ ) { if( strncmp(pszPath,iter->first.c_str(),iter->first.size()) == 0 ) return iter->second; } return poThis->poDefaultHandler;}/************************************************************************//* InstallHandler() *//************************************************************************/void VSIFileManager::InstallHandler( std::string osPrefix, VSIFilesystemHandler *poHandler ){ if( osPrefix == "" ) Get()->poDefaultHandler = poHandler; else Get()->oHandlers[osPrefix] = poHandler;}/************************************************************************//* VSICleanupFileManager() *//************************************************************************/void VSICleanupFileManager(){ if( poManager ) { delete poManager; poManager = NULL; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -