Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OGR_GRASS: fix regression after switch to GetGDALDriverManager #28

Merged
merged 1 commit into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 3 additions & 17 deletions ogrgrass.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ class OGRGRASSDataSource final: public OGRDataSource
OGRGRASSDataSource();
virtual ~OGRGRASSDataSource();

int Open( const char *, int bUpdate, int bTestOpen,
int bSingleNewFile = FALSE );
bool Open( const char *, bool bUpdate, bool bTestOpen,
bool bSingleNewFile = false );

const char *GetName() override { return pszName; }
int GetLayerCount() override { return nLayers; }
Expand All @@ -147,23 +147,9 @@ class OGRGRASSDataSource final: public OGRDataSource
struct Map_info map;
int nLayers;

int bOpened;
bool bOpened;

static bool SplitPath ( char *, char **, char **, char **, char ** );
};

/************************************************************************/
/* OGRGRASSDriver */
/************************************************************************/
class OGRGRASSDriver final: public OGRSFDriver
{
public:
virtual ~OGRGRASSDriver();

const char *GetName() override;
OGRDataSource *Open( const char *, int ) override;

int TestCapability( const char * ) override;
};

#endif /* ndef OGRGRASS_H_INCLUDED */
20 changes: 10 additions & 10 deletions ogrgrassdatasource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ OGRGRASSDataSource::~OGRGRASSDataSource()

typedef int (*GrassErrorHandler)(const char *, int);

int OGRGRASSDataSource::Open( const char * pszNewName, int /*bUpdate*/,
int bTestOpen, int /*bSingleNewFileIn*/ )
bool OGRGRASSDataSource::Open( const char * pszNewName, bool /*bUpdate*/,
bool bTestOpen, bool /*bSingleNewFileIn*/ )
{
VSIStatBuf stat;

Expand All @@ -99,14 +99,14 @@ int OGRGRASSDataSource::Open( const char * pszNewName, int /*bUpdate*/,
/* -------------------------------------------------------------------- */
/* Do the given path contains 'vector' and 'head'? */
/* -------------------------------------------------------------------- */
if ( strstr(pszName,"vector") == NULL || strstr(pszName,"head") == NULL )
if ( strstr(pszName,"vector") == nullptr || strstr(pszName,"head") == nullptr )
{
if( !bTestOpen )
{
CPLError( CE_Failure, CPLE_AppDefined,
"%s is not GRASS vector, access failed.\n", pszName );
}
return FALSE;
return false;
}

/* -------------------------------------------------------------------- */
Expand All @@ -120,7 +120,7 @@ int OGRGRASSDataSource::Open( const char * pszNewName, int /*bUpdate*/,
"%s is not GRASS vector, access failed.\n", pszName );
}

return FALSE;
return false;
}

/* -------------------------------------------------------------------- */
Expand All @@ -135,7 +135,7 @@ int OGRGRASSDataSource::Open( const char * pszNewName, int /*bUpdate*/,
"%s is not GRASS datasource name, access failed.\n",
pszName );
}
return FALSE;
return false;
}

CPLDebug ( "GRASS", "Gisdbase: %s", pszGisdbase );
Expand All @@ -149,7 +149,7 @@ int OGRGRASSDataSource::Open( const char * pszNewName, int /*bUpdate*/,
// GISBASE is path to the directory where GRASS is installed,
// it is necessary because there are database drivers.
if ( !getenv( "GISBASE" ) ) {
static char* gisbaseEnv = NULL;
static char* gisbaseEnv = nullptr;
const char *gisbase = GRASS_GISBASE;
CPLError( CE_Warning, CPLE_AppDefined, "GRASS warning: GISBASE "
"environment variable was not set, using:\n%s", gisbase );
Expand Down Expand Up @@ -191,7 +191,7 @@ int OGRGRASSDataSource::Open( const char * pszNewName, int /*bUpdate*/,
if ( level < 2 ) {
CPLError( CE_Failure, CPLE_AppDefined,
"Cannot open GRASS vector %s on level 2.\n", pszName );
return FALSE;
return false;
}

CPLDebug ( "GRASS", "Num lines = %d", Vect_get_num_lines(&map) );
Expand All @@ -212,9 +212,9 @@ int OGRGRASSDataSource::Open( const char * pszNewName, int /*bUpdate*/,
papoLayers[nLayers++] = poLayer;
}

bOpened = TRUE;
bOpened = true;

return TRUE;
return true;
}

/************************************************************************/
Expand Down
42 changes: 11 additions & 31 deletions ogrgrassdriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,48 +36,26 @@ extern "C" {

CPL_CVSID("$Id$")

/************************************************************************/
/* ~OGRGRASSDriver() */
/************************************************************************/
OGRGRASSDriver::~OGRGRASSDriver()
{
}

/************************************************************************/
/* GetName() */
/************************************************************************/
const char *OGRGRASSDriver::GetName()
{
return "OGR_GRASS";
}

/************************************************************************/
/* Open() */
/************************************************************************/
OGRDataSource *OGRGRASSDriver::Open( const char * pszFilename,
int bUpdate )
static auto GRASSDatasetOpen(GDALOpenInfo *poOpenInfo) -> GDALDataset*
{
OGRGRASSDataSource *poDS = new OGRGRASSDataSource();
auto *poDS = new OGRGRASSDataSource();

bool bUpdate = poOpenInfo->eAccess == GA_Update;

if( !poDS->Open( pszFilename, bUpdate, TRUE ) )
if( !poDS->Open( poOpenInfo->pszFilename, bUpdate, true ))
{
delete poDS;
return NULL;
return nullptr;
}
else
{
return poDS;
}
}

/************************************************************************/
/* TestCapability() */
/************************************************************************/
int OGRGRASSDriver::TestCapability( const char * /*pszCap*/ )
{
return FALSE;
}

/************************************************************************/
/* RegisterOGRGRASS() */
/************************************************************************/
Expand All @@ -86,15 +64,17 @@ void RegisterOGRGRASS()
if (! GDAL_CHECK_VERSION("OGR/GRASS driver"))
return;

if( GDALGetDriverByName( "OGR_GRASS" ) != NULL )
if( GDALGetDriverByName( "OGR_GRASS" ) != nullptr )
return;

OGRGRASSDriver *poDriver = new OGRGRASSDriver();
auto *poDriver = new GDALDriver();

poDriver->SetDescription( "GRASS" );
poDriver->SetDescription( "OGR_GRASS" );
poDriver->SetMetadataItem( GDAL_DCAP_VECTOR, "YES" );
poDriver->SetMetadataItem( GDAL_DMD_LONGNAME, "GRASS Vectors (5.7+)" );
poDriver->SetMetadataItem( GDAL_DMD_HELPTOPIC, "drivers/vector/grass.html" );

poDriver->pfnOpen = GRASSDatasetOpen;

GetGDALDriverManager()->RegisterDriver(poDriver);
}