Ticket #2158: gdal_svn_trunk_read_dir_custom.patch
| File gdal_svn_trunk_read_dir_custom.patch, 3.6 kB (added by rouault, 3 months ago) |
|---|
-
port/cpl_vsi.h
old new 176 176 /* Other... */ 177 177 /* ==================================================================== */ 178 178 179 typedef char** (*VSICustomReadDirCallback)(const char* pszPath); 180 void CPL_DLL VSIInstallCustomReadDirCallback(VSICustomReadDirCallback _pfnCustomReadDir); 181 179 182 #define CPLReadDir VSIReadDir 180 183 char CPL_DLL **VSIReadDir( const char * ); 184 char CPL_DLL **VSIReadDirDefault( const char *pszPath ); 181 185 int CPL_DLL VSIMkdir( const char * pathname, long mode ); 182 186 int CPL_DLL VSIRmdir( const char * pathname ); 183 187 int CPL_DLL VSIUnlink( const char * pathname ); -
port/cpl_vsil.cpp
old new 33 33 34 34 CPL_CVSID("$Id$"); 35 35 36 static VSICustomReadDirCallback pfnCustomReadDir = NULL; 37 36 38 /************************************************************************/ 39 /* VSIInstallCustomReadDirCallback() */ 40 /************************************************************************/ 41 42 /** 43 * \brief Install a callback to speed up VSIReadDir 44 * 45 * This function install a callback that can be used by VSIReadDir to speed 46 * up directory file listing. This can be usefull when the calling application 47 * knows that the directory content has not changed for example. 48 * The signature of the callback is : char** cachedReadDir(char* pszPath). 49 * The return value of the callback will be freed by CSLDestroy. 50 * 51 * @note The callback implementation must be thread-safe if GDAL is used 52 * in a multi-threaded application. 53 */ 54 55 void VSIInstallCustomReadDirCallback(VSICustomReadDirCallback _pfnCustomReadDir) 56 { 57 pfnCustomReadDir = _pfnCustomReadDir; 58 } 59 60 /************************************************************************/ 61 /* VSIReadDirDefault() */ 62 /************************************************************************/ 63 64 /** 65 * \brief Read names in a directory. 66 * 67 * This function acts similarly to VSIReadDir, except it does not use 68 * the callback installed by VSIInstallCustomReadDirCallback 69 * 70 */ 71 72 char **VSIReadDirDefault(const char *pszPath) 73 { 74 VSIFilesystemHandler *poFSHandler = 75 VSIFileManager::GetHandler( pszPath ); 76 77 return poFSHandler->ReadDir( pszPath ); 78 } 79 80 /************************************************************************/ 37 81 /* VSIReadDir() */ 38 82 /************************************************************************/ 39 83 … … 47 91 * 48 92 * Note that no error is issued via CPLError() if the directory path is 49 93 * invalid, though NULL is returned. 94 * 95 * This function will used the callback installed by VSIInstallCustomReadDirCallback 96 * if available. 50 97 * 51 98 * This function used to be known as CPLReadDir(), but the old name is now 52 99 * deprecated. … … 58 105 59 106 char **VSIReadDir(const char *pszPath) 60 107 { 61 VSIFilesystemHandler *poFSHandler = 62 VSIFileManager::GetHandler( pszPath ); 108 if (pfnCustomReadDir) 109 { 110 char** papszDir = pfnCustomReadDir(pszPath); 111 if (papszDir) 112 return papszDir; 113 } 63 114 64 return poFSHandler->ReadDir( pszPath);115 return VSIReadDirDefault(pszPath); 65 116 } 66 117 67 118 /************************************************************************/
