MCPcopy Create free account
hub / github.com/OSGeo/gdal / SetAutoCompleteFunctionForFilename

Method SetAutoCompleteFunctionForFilename

gcore/gdalalgorithm.cpp:3845–3960  ·  view source on GitHub ↗

static */

Source from the content-addressed store, hash-verified

3843
3844/* static */
3845void GDALAlgorithm::SetAutoCompleteFunctionForFilename(
3846 GDALInConstructionAlgorithmArg &arg, GDALArgDatasetType type)
3847{
3848 arg.SetAutoCompleteFunction(
3849 [&arg,
3850 type](const std::string &currentValue) -> std::vector<std::string>
3851 {
3852 std::vector<std::string> oRet;
3853
3854 if (arg.IsHidden())
3855 return oRet;
3856
3857 {
3858 CPLErrorStateBackuper oBackuper(CPLQuietErrorHandler);
3859 VSIStatBufL sStat;
3860 if (!currentValue.empty() && currentValue.back() != '/' &&
3861 VSIStatL(currentValue.c_str(), &sStat) == 0)
3862 {
3863 return oRet;
3864 }
3865 }
3866
3867 auto poDM = GetGDALDriverManager();
3868 std::set<std::string> oExtensions;
3869 if (type)
3870 {
3871 for (int i = 0; i < poDM->GetDriverCount(); ++i)
3872 {
3873 auto poDriver = poDM->GetDriver(i);
3874 if (((type & GDAL_OF_RASTER) != 0 &&
3875 poDriver->GetMetadataItem(GDAL_DCAP_RASTER)) ||
3876 ((type & GDAL_OF_VECTOR) != 0 &&
3877 poDriver->GetMetadataItem(GDAL_DCAP_VECTOR)) ||
3878 ((type & GDAL_OF_MULTIDIM_RASTER) != 0 &&
3879 poDriver->GetMetadataItem(GDAL_DCAP_MULTIDIM_RASTER)))
3880 {
3881 const char *pszExtensions =
3882 poDriver->GetMetadataItem(GDAL_DMD_EXTENSIONS);
3883 if (pszExtensions)
3884 {
3885 const CPLStringList aosExts(
3886 CSLTokenizeString2(pszExtensions, " ", 0));
3887 for (const char *pszExt : cpl::Iterate(aosExts))
3888 oExtensions.insert(CPLString(pszExt).tolower());
3889 }
3890 }
3891 }
3892 }
3893
3894 std::string osDir;
3895 const CPLStringList aosVSIPrefixes(VSIGetFileSystemsPrefixes());
3896 std::string osPrefix;
3897 if (STARTS_WITH(currentValue.c_str(), "/vsi"))
3898 {
3899 for (const char *pszPrefix : cpl::Iterate(aosVSIPrefixes))
3900 {
3901 if (STARTS_WITH(currentValue.c_str(), pszPrefix))
3902 {

Callers

nothing calls this directly

Calls 15

VSIStatLFunction · 0.85
GetGDALDriverManagerFunction · 0.85
CSLTokenizeString2Function · 0.85
IterateFunction · 0.85
CPLStringFunction · 0.85
CPLGetDirnameSafeFunction · 0.85
moveFunction · 0.85
VSIOpenDirFunction · 0.85
VSIGetDirectorySeparatorFunction · 0.85
CPLGetFilenameFunction · 0.85
VSIGetNextDirEntryFunction · 0.85

Tested by

no test coverage detected