Commit 220d93cb authored by Cédric Traizet's avatar Cédric Traizet

ENH : moved remaining functions in version proxy to OGRHelpers

parent 89792ded
......@@ -27,6 +27,7 @@
#include <cassert>
#include <boost/range/begin.hpp>
#include <boost/range/end.hpp>
#include "ogr_feature.h"
#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
......@@ -43,6 +44,8 @@
#include "OTBGdalAdaptersExport.h"
class GDALDataset;
namespace otb
{
namespace ogr
......@@ -105,6 +108,35 @@ private:
std::vector<char const*> m_raw;
};
/**
* Return the list of available drivers.
*
* \return A vector of string containing the list of available drivers.
*/
OTBGdalAdapters_EXPORT
std::vector<std::string> GetAvailableDriversAsStringVector();
/**
* Return the list of files composing the dataset.
*
* \param dataset Pointer to the dataset to get the file list from. Will not be
* checked for null pointer.
*
* \return A vector of string containing the list of files.
*/
OTBGdalAdapters_EXPORT
std::vector<std::string> GetFileListAsStringVector(GDALDataset * dataset);
/**
* Returns true if the field 'index' is set and not-null in the given feature
*
* Before gdal 2.2, it calls OGRFeature::IsFieldSet().
* After gdal 2.2, it calls OGRFeature::IsFieldSetAndNotNull()
*/
OTBGdalAdapters_EXPORT
bool IsFieldSetAndNotNull(OGRFeature *feat, int index);
} // ogr namespace
} // end namespace otb
......
......@@ -76,30 +76,6 @@ namespace version_proxy
*
* \return A vector of string containing the list of files.
*/
OTBGdalAdapters_EXPORT
std::vector<std::string> GetFileListAsStringVector(GDALDataset * dataset);
/**
* Return the list of available drivers.
*
* Calls OGRSFDriverRegistrar::GetRegistrar() for gdal 1.x
* implementation and GetGDALDriverManager() for gdal 2.x
* implementation.
*
* \return A vector of string containing the list of available drivers.
*/
OTBGdalAdapters_EXPORT
std::vector<std::string> GetAvailableDriversAsStringVector();
/**
* Returns true if the field 'index' is set and not-null in the given feature
*
* Before gdal 2.2, it calls OGRFeature::IsFieldSet().
* After gdal 2.2, it calls OGRFeature::IsFieldSetAndNotNull()
*/
OTBGdalAdapters_EXPORT
bool IsFieldSetAndNotNull(OGRFeature *feat, int index);
}
}
......
......@@ -30,6 +30,7 @@ set(OTBGdalAdapters_SRC
otbOGRDataSourceWrapper.cxx
otbOGRVersionProxy.cxx
otbOGRExtendedFilenameToOptions.cxx
otbOGRHelpers.cxx
)
add_library(OTBGdalAdapters ${OTBGdalAdapters_SRC})
......
......@@ -829,7 +829,7 @@ void otb::ogr::DataSource::SyncToDisk()
std::string otb::ogr::DataSource::GetDatasetDescription() const
{
std::vector<std::string> files =
otb::ogr::version_proxy::GetFileListAsStringVector( m_DataSource );
otb::ogr::GetFileListAsStringVector( m_DataSource );
std::string description = "";
for( std::vector<std::string>::const_iterator it = files.begin() ;
it!=files.end() ; ++it )
......
......@@ -167,7 +167,7 @@ std::ostream & otb::ogr::Field::UncheckedPrintSelf(
bool otb::ogr::Field::UncheckedHasBeenSet() const
{
return otb::ogr::version_proxy::IsFieldSetAndNotNull(m_Feature.get(), m_index);
return otb::ogr::IsFieldSetAndNotNull(m_Feature.get(), m_index);
}
void otb::ogr::Field::UncheckedUnset() const
......
/*
* Copyright (C) 2005-2017 Centre National d'Etudes Spatiales (CNES)
*
* This file is part of Orfeo Toolbox
*
* https://www.orfeo-toolbox.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "otbOGRHelpers.h"
#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wshadow"
#include "gdal_priv.h"
#include "ogr_feature.h"
#pragma GCC diagnostic pop
#else
#include "gdal_priv.h"
#include "ogr_feature.h"
#endif // __GNUC__ || __clang__
namespace otb
{
namespace ogr
{
std::vector<std::string> GetAvailableDriversAsStringVector()
{
std::vector<std::string> ret;
int nbDrivers = GetGDALDriverManager()->GetDriverCount();
for(int i = 0; i < nbDrivers;++i)
{
ret.push_back(GDALGetDriverShortName(GetGDALDriverManager()->GetDriver(i)));
}
return ret;
}
namespace raii
{
// This class is used in the next function, so as to prevent any
// resource leak on char ** returned by dataset->GetFileList()
class CharPPCapsule
{
public:
CharPPCapsule(char ** in)
: m_P(in)
{}
const char ** P() const
{
return const_cast<const char **>(m_P);
}
~CharPPCapsule()
{
if(m_P)
CSLDestroy(m_P);
}
private:
char ** m_P;
};
}
std::vector<std::string> GetFileListAsStringVector(GDALDataset * dataset)
{
std::vector<std::string> ret;
raii::CharPPCapsule capsule(dataset->GetFileList());
std::string files_str="";
if(capsule.P())
{
unsigned int i = 0;
while(capsule.P()[i]!=NULL)
{
ret.push_back(std::string(capsule.P()[i]));
++i;
}
}
return ret;
}
/*----------------------[GDAL 2.2 change on IsFieldSet()]---------------------*/
bool IsFieldSetAndNotNull(OGRFeature *feat, int index)
{
#if GDAL_VERSION_NUM<2020000
return feat->IsFieldSet(index);
#else
return feat->IsFieldSetAndNotNull(index);
#endif
}
}
} // end namespaces
\ No newline at end of file
......@@ -42,96 +42,12 @@
#include "ogr_feature.h"
#endif // __GNUC__ || __clang__
namespace otb
namespace otbscon
{
namespace ogr
{
namespace version_proxy
{
#if GDAL_VERSION_NUM>=2000000
namespace raii
{
// This class is used in the next function, so as to prevent any
// resource leak on char ** returned by dataset->GetFileList()
class CharPPCapsule
{
public:
CharPPCapsule(char ** in)
: m_P(in)
{}
const char ** P() const
{
return const_cast<const char **>(m_P);
}
~CharPPCapsule()
{
if(m_P)
CSLDestroy(m_P);
}
private:
char ** m_P;
};
}
#endif
std::vector<std::string> GetFileListAsStringVector(GDALDataset * dataset)
{
std::vector<std::string> ret;
#if GDAL_VERSION_NUM<2000000
ret.push_back(std::string(dataset->GetName()));
#else
raii::CharPPCapsule capsule(dataset->GetFileList());
std::string files_str="";
if(capsule.P())
{
unsigned int i = 0;
while(capsule.P()[i]!=NULL)
{
ret.push_back(std::string(capsule.P()[i]));
++i;
}
}
#endif
return ret;
}
std::vector<std::string> GetAvailableDriversAsStringVector()
{
std::vector<std::string> ret;
#if GDAL_VERSION_NUM<2000000
int nbDrivers = OGRSFDriverRegistrar::GetRegistrar()->GetDriverCount();
for(int i = 0; i < nbDrivers;++i)
{
ret.push_back(OGRSFDriverRegistrar::GetRegistrar()->GetDriver(i)->GetName());
}
#else
int nbDrivers = GetGDALDriverManager()->GetDriverCount();
for(int i = 0; i < nbDrivers;++i)
{
ret.push_back(GDALGetDriverShortName(GetGDALDriverManager()->GetDriver(i)));
}
#endif
return ret;
}
/*----------------------[GDAL 2.2 change on IsFieldSet()]---------------------*/
bool IsFieldSetAndNotNull(OGRFeature *feat, int index)
{
#if GDAL_VERSION_NUM<2020000
return feat->IsFieldSet(index);
#else
return feat->IsFieldSetAndNotNull(index);
#endif
}
}
}
} // end namespace
......
......@@ -209,7 +209,7 @@ void OGRIOHelper
otb::VectorDataKeywordlist kwl;
for (int fieldNum = 0; fieldNum < feature->GetFieldCount(); ++fieldNum)
{
if (ogr::version_proxy::IsFieldSetAndNotNull(feature, fieldNum))
if (ogr::IsFieldSetAndNotNull(feature, fieldNum))
{
kwl.AddField(feature->GetFieldDefnRef(fieldNum), feature->GetRawFieldRef(fieldNum));
}
......
......@@ -49,6 +49,7 @@
#include "otbPrintableImageFilter.h"
#include "otbStreamingShrinkImageFilter.h"
#include "otbOGRVersionProxy.h"
#include "otbOGRHelpers.h"
#include "otbConfigure.h"
......@@ -1786,7 +1787,7 @@ int TestHelper::RegressionTestOgrFile(const char *testOgrFilename, const char *b
{
std::cout << "FAILURE:\n" "Unable to open REF datasource `" << ref_pszDataSource << "' with the following drivers." << std::endl;
std::vector<std::string> drivers = ogr::version_proxy::GetAvailableDriversAsStringVector();
std::vector<std::string> drivers = ogr::GetAvailableDriversAsStringVector();
for (std::vector<std::string>::const_iterator it = drivers.begin();it!=drivers.end();++it)
{
......@@ -1804,7 +1805,7 @@ int TestHelper::RegressionTestOgrFile(const char *testOgrFilename, const char *b
{
std::cout << "FAILURE:\n""Unable to open TEST datasource `" << test_pszDataSource << "' with the following drivers." << std::endl;
std::vector<std::string> drivers = ogr::version_proxy::GetAvailableDriversAsStringVector();
std::vector<std::string> drivers = ogr::GetAvailableDriversAsStringVector();
for (std::vector<std::string>::const_iterator it = drivers.begin();it!=drivers.end();++it)
{
......@@ -1823,8 +1824,8 @@ int TestHelper::RegressionTestOgrFile(const char *testOgrFilename, const char *b
// TODO: Improve this check as it will stop as soon as one of the
// list ends (i.e. it does not guarantee that all files are present)
std::vector<std::string> refFileList = otb::ogr::version_proxy::GetFileListAsStringVector(ref_poDS);
std::vector<std::string> testFileList = otb::ogr::version_proxy::GetFileListAsStringVector(test_poDS);
std::vector<std::string> refFileList = otb::ogr::GetFileListAsStringVector(ref_poDS);
std::vector<std::string> testFileList = otb::ogr::GetFileListAsStringVector(test_poDS);
unsigned int fileId = 0;
......@@ -1961,7 +1962,7 @@ void TestHelper::DumpOGRFeature(FILE* fpOut, OGRFeature* feature, char** papszOp
poFDefn->GetNameRef(),
OGRFieldDefn::GetFieldTypeName(poFDefn->GetType()));
if (ogr::version_proxy::IsFieldSetAndNotNull(feature, iField)) fprintf(fpOut, "%s\n", feature->GetFieldAsString(iField));
if (ogr::IsFieldSetAndNotNull(feature, iField)) fprintf(fpOut, "%s\n", feature->GetFieldAsString(iField));
else fprintf(fpOut, "(null)\n");
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment