OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimGdalPluginInit.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 // Copyright (C) 2005 David Burken, all rights reserved.
3 //
4 // License: LGPL
5 //
6 // See LICENSE.txt file in the top level directory for more details.
7 //
8 // Author: David Burken
9 //*******************************************************************
10 // $Id: ossimGdalPluginInit.cpp 18971 2011-02-25 19:53:30Z gpotts $
11 #include <gdal.h>
14 #include <ossim/base/ossimRegExp.h>
15 #include <ossimGdalFactory.h>
16 #include <ossimGdalObjectFactory.h>
18 #include <ossimGdalInfoFactory.h>
27 
28 static void setGdalDescription(ossimString& description)
29 {
30  description = "GDAL Plugin\n\n";
31 
32  int driverCount = GDALGetDriverCount();
33  int idx = 0;
34  description += "GDAL Supported formats\n";
35  for(idx = 0; idx < driverCount; ++idx)
36  {
37  GDALDriverH driver = GDALGetDriver(idx);
38  if(driver)
39  {
40  description += " name: ";
41  description += ossimString(GDALGetDriverShortName(driver)) + " " + ossimString(GDALGetDriverLongName(driver)) + "\n";
42  }
43  }
44 }
45 static void setValidDrivers(const ossimKeywordlist& options){
46  int driverCount = GDALGetDriverCount();
47  int idx = 0;
48  ossimString driverRegExString = ossimEnvironmentUtility::instance()->getEnvironmentVariable("GDAL_ENABLE_DRIVERS");
49  ossimRegExp driverRegEx;
50  std::function<bool(GDALDriverH, ossimRegExp &)>
51  isDriverEnabled = [](GDALDriverH driver, ossimRegExp &regExpression) -> bool { return true; };
52 
53  // check env variables first
54  //
55  if (!driverRegExString.empty())
56  {
57  isDriverEnabled = [](GDALDriverH driver, ossimRegExp &regExpression) -> bool { return regExpression.find(GDALGetDriverShortName(driver)); };
58  }
59  else
60  {
61  driverRegExString = ossimEnvironmentUtility::instance()->getEnvironmentVariable("GDAL_DISABLE_DRIVERS");
62  if (!driverRegExString.empty())
63  {
64  isDriverEnabled = [](GDALDriverH driver, ossimRegExp &regExpression) -> bool { return !regExpression.find(GDALGetDriverShortName(driver)); };
65  }
66  }
67  // now check properties
68  if (driverRegExString.empty())
69  {
70  driverRegExString = options.find("enable_drivers");
71  if (!driverRegExString.empty())
72  {
73  isDriverEnabled = [](GDALDriverH driver, ossimRegExp &regExpression) -> bool { return regExpression.find(GDALGetDriverShortName(driver)); };
74  }
75  else
76  {
77  driverRegExString = options.find("disable_drivers");
78  if (!driverRegExString.empty())
79  {
80  isDriverEnabled = [](GDALDriverH driver, ossimRegExp &regExpression) -> bool { return !regExpression.find(GDALGetDriverShortName(driver)); };
81  }
82  }
83  }
84  if (!driverRegExString.empty())
85  {
86  driverRegEx.compile(driverRegExString.c_str());
87  }
88  for (idx = 0; idx < driverCount; ++idx)
89  {
90  GDALDriverH driver = GDALGetDriver(idx);
91  if (driver)
92  {
93  if (!isDriverEnabled(driver, driverRegEx))
94  {
95  GDALDeregisterDriver(driver);
96  GDALDestroyDriver(driver);
97  }
98  }
99  }
100 }
101 
102 extern "C"
103 {
106  std::vector<ossimString> gdalObjList;
107  const char* getGdalDescription()
108  {
109  return gdalDescription.c_str();
110  }
112  {
113  return (int)gdalObjList.size();
114  }
115  const char* getGdalClassName(int idx)
116  {
117  if(idx < (int)gdalObjList.size())
118  {
119  return gdalObjList[idx].c_str();
120  }
121  return (const char*)0;
122  }
123 
124  /* Note symbols need to be exported on windoze... */
126  ossimSharedObjectInfo** info,
127  const char* options)
128  {
132 
133  *info = &gdalInfo;
134  ossimKeywordlist kwl;
135  kwl.parseString(ossimString(options));
136  /* Register the readers... */
138  ->registerFactory(ossimGdalFactory::instance(), ossimString(kwl.find("read_factory.location")).downcase() == "front");
139 
140  /* Register the writers... */
141  ossimImageWriterFactoryRegistry::instance()->registerFactory(ossimGdalImageWriterFactory::instance(), ossimString(kwl.find("writer_factory.location")).downcase() == "front");
142 
143  /* Register the overview builder factory. */
145 
147 
148  /* Register generic objects... */
150 
151  /* Register gdal info factoy... */
153 
154  setValidDrivers(kwl);
155  setGdalDescription(gdalDescription);
161  }
162 
163  /* Note symbols need to be exported on windoze... */
165  {
167  unregisterFactory(ossimGdalFactory::instance());
168 
170  unregisterFactory(ossimGdalImageWriterFactory::instance());
171 
173  unregisterFactory(ossimGdalOverviewBuilderFactory::instance());
174 
176 
178  unregisterFactory(ossimGdalObjectFactory::instance());
179 
181  unregisterFactory(ossimGdalInfoFactory::instance());
182  }
183 }
const char * getGdalDescription()
static ossimGdalObjectFactory * instance()
int getGdalNumberOfClassNames()
Represents serializable keyword/value map.
const char * find(const char *key) const
virtual void getTypeNameList(std::vector< ossimString > &typeList) const
static ossimImageWriterFactoryRegistry * instance()
ossimSharedLibraryGetNumberOfClassNamesPtr getNumberOfClassNames
static ossimGdalFactory * instance()
virtual void getTypeNameList(std::vector< ossimString > &typeList) const
Adds list of objects this factory supports.
static ossimObjectFactoryRegistry * instance()
std::vector< ossimString > gdalObjList
virtual void getTypeNameList(std::vector< ossimString > &typeList) const
ossimSharedObjectInfo gdalInfo
void unregisterFactory(T *factory)
Will remove the factory from the registry.
static ossimGdalOverviewBuilderFactory * instance()
static instance method.
static ossimGdalInfoFactory * instance()
virtual void getTypeNameList(std::vector< ossimString > &typeList) const
ossimSharedLibraryGetDescriptionPtr getDescription
void compile(const char *)
#define OSSIM_PLUGINS_DLL
void registerFactory(T *factory, bool pushToFrontFlag=false)
Will register a factory to the factory list.
ossimString gdalDescription
virtual bool parseString(const std::string &inString)
ossimSharedLibraryGetClassNamesPtr getClassName
const char * getGdalClassName(int idx)
static ossimProjectionFactoryRegistry * instance()
static ossimOverviewBuilderFactoryRegistry * instance()
instance method for access to theInstance pointer.
static ossimEnvironmentUtility * instance()
static ossimInfoFactoryRegistry * instance()
instance method
static ossimGdalProjectionFactory * instance()
static ossimGdalImageWriterFactory * instance()
const char * c_str() const
Returns a pointer to a null-terminated array of characters representing the string&#39;s contents...
Definition: ossimString.h:396
bool empty() const
Definition: ossimString.h:411
ossimString getEnvironmentVariable(const ossimString &variable) const
OSSIM_PLUGINS_DLL void ossimSharedLibraryInitialize(ossimSharedObjectInfo **info, const char *options)
static ossimImageHandlerRegistry * instance()
virtual void getTypeNameList(std::vector< ossimString > &typeList) const
Method to populate a list of supported types for the factory.
OSSIM_PLUGINS_DLL void ossimSharedLibraryFinalize()
bool find(const char *)
std::string::size_type find(const std::string &s, std::string::size_type pos=0) const
Searches for s as a substring of *this, beginning at character pos of *this.
Definition: ossimString.h:753
void registerFactory(ossimInfoFactoryInterface *factory)
Method to add factory to registry.