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  
    176176/*      Other...                                                        */ 
    177177/* ==================================================================== */ 
    178178 
     179typedef char** (*VSICustomReadDirCallback)(const char* pszPath); 
     180void CPL_DLL VSIInstallCustomReadDirCallback(VSICustomReadDirCallback _pfnCustomReadDir); 
     181 
    179182#define CPLReadDir VSIReadDir 
    180183char CPL_DLL **VSIReadDir( const char * ); 
     184char CPL_DLL **VSIReadDirDefault( const char *pszPath ); 
    181185int CPL_DLL VSIMkdir( const char * pathname, long mode ); 
    182186int CPL_DLL VSIRmdir( const char * pathname ); 
    183187int CPL_DLL VSIUnlink( const char * pathname ); 
  • port/cpl_vsil.cpp

    old new  
    3333 
    3434CPL_CVSID("$Id$"); 
    3535 
     36static VSICustomReadDirCallback pfnCustomReadDir = NULL; 
     37 
    3638/************************************************************************/ 
     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 
     55void 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 
     72char **VSIReadDirDefault(const char *pszPath) 
     73{ 
     74    VSIFilesystemHandler *poFSHandler =  
     75        VSIFileManager::GetHandler( pszPath ); 
     76 
     77    return poFSHandler->ReadDir( pszPath ); 
     78} 
     79 
     80/************************************************************************/ 
    3781/*                             VSIReadDir()                             */ 
    3882/************************************************************************/ 
    3983 
     
    4791 * 
    4892 * Note that no error is issued via CPLError() if the directory path is 
    4993 * invalid, though NULL is returned. 
     94 * 
     95 * This function will used the callback installed by VSIInstallCustomReadDirCallback 
     96 * if available. 
    5097 *  
    5198 * This function used to be known as CPLReadDir(), but the old name is now  
    5299 * deprecated.  
     
    58105 
    59106char **VSIReadDir(const char *pszPath) 
    60107{ 
    61     VSIFilesystemHandler *poFSHandler =  
    62         VSIFileManager::GetHandler( pszPath ); 
     108    if (pfnCustomReadDir) 
     109    { 
     110        char** papszDir = pfnCustomReadDir(pszPath); 
     111        if (papszDir) 
     112            return papszDir; 
     113    } 
    63114 
    64     return poFSHandler->ReadDir( pszPath ); 
     115    return VSIReadDirDefault(pszPath); 
    65116} 
    66117 
    67118/************************************************************************/