GDAL
gdal_drivermanager.h
1/******************************************************************************
2 *
3 * Name: gdal_drivermanager.h
4 * Project: GDAL Core
5 * Purpose: Declaration of GDALDriverManager class
6 * Author: Frank Warmerdam, warmerdam@pobox.com
7 *
8 ******************************************************************************
9 * Copyright (c) 1998, Frank Warmerdam
10 * Copyright (c) 2007-2014, Even Rouault <even dot rouault at spatialys.com>
11 *
12 * SPDX-License-Identifier: MIT
13 ****************************************************************************/
14
15#ifndef GDALDRIVERMANAGER_H_INCLUDED
16#define GDALDRIVERMANAGER_H_INCLUDED
17
18#include "cpl_port.h"
19#include "cpl_string.h"
20#include "gdal.h"
21#include "gdal_majorobject.h"
22
23#include <memory>
24#include <set>
25#include <vector>
26
27class GDALDriver;
29
30/* ******************************************************************** */
31/* GDALDriverManager */
32/* ******************************************************************** */
33
40
41class CPL_DLL GDALDriverManager final : public GDALMajorObject
42{
43 int nDrivers = 0;
44 GDALDriver **papoDrivers = nullptr;
45 std::map<CPLString, GDALDriver *> oMapNameToDrivers{};
46 std::string m_osPluginPath{};
47 std::string m_osDriversIniPath{};
48 mutable std::string m_osLastTriedDirectory{};
49 std::set<std::string> m_oSetPluginFileNames{};
50 bool m_bInDeferredDriverLoading = false;
51 std::map<std::string, std::unique_ptr<GDALDriver>> m_oMapRealDrivers{};
52 std::vector<std::unique_ptr<GDALDriver>> m_aoHiddenDrivers{};
53
54 GDALDriver *GetDriver_unlocked(int iDriver)
55 {
56 return (iDriver >= 0 && iDriver < nDrivers) ? papoDrivers[iDriver]
57 : nullptr;
58 }
59
60 GDALDriver *GetDriverByName_unlocked(const char *pszName) const;
61
62 static void CleanupPythonDrivers();
63
64 std::string GetPluginFullPath(const char *pszFilename) const;
65
66 int RegisterDriver(GDALDriver *, bool bHidden);
67
68 CPL_DISALLOW_COPY_ASSIGN(GDALDriverManager)
69
70 protected:
71 friend class GDALPluginDriverProxy;
72 friend GDALDatasetH CPL_STDCALL
73 GDALOpenEx(const char *pszFilename, unsigned int nOpenFlags,
74 const char *const *papszAllowedDrivers,
75 const char *const *papszOpenOptions,
76 const char *const *papszSiblingFiles);
77
79 static char **GetSearchPaths(const char *pszGDAL_DRIVER_PATH);
81
82 public:
83 GDALDriverManager();
84 ~GDALDriverManager() override;
85
86 int GetDriverCount(void) const;
88 GDALDriver *GetDriverByName(const char *);
89
90 int RegisterDriver(GDALDriver *);
92
93 // AutoLoadDrivers is a no-op if compiled with GDAL_NO_AUTOLOAD defined.
94 void AutoLoadDrivers();
95 void AutoSkipDrivers();
96 void ReorderDrivers();
97 static CPLErr LoadPlugin(const char *name);
98
99 static void AutoLoadPythonDrivers();
100
101 void DeclareDeferredPluginDriver(GDALPluginDriverProxy *poProxyDriver);
102
104 int GetDriverCount(bool bIncludeHidden) const;
105 GDALDriver *GetDriver(int iDriver, bool bIncludeHidden);
106 bool IsKnownDriver(const char *pszDriverName) const;
107 GDALDriver *GetHiddenDriverByName(const char *pszName);
109};
110
112GDALDriverManager CPL_DLL *GetGDALDriverManager(void);
114
115#endif
Class for managing the registration of file format drivers.
Definition gdal_drivermanager.h:42
void DeregisterDriver(GDALDriver *)
Deregister the passed driver.
Definition gdaldrivermanager.cpp:673
int GetDriverCount(void) const
Fetch the number of registered drivers.
Definition gdaldrivermanager.cpp:344
static CPLErr LoadPlugin(const char *name)
Load a single GDAL driver/plugin from shared libraries.
Definition gdaldrivermanager.cpp:914
static void AutoLoadPythonDrivers()
Auto-load GDAL drivers from Python scripts.
Definition gdalpythondriverloader.cpp:1915
void AutoSkipDrivers()
This method unload undesirable drivers.
Definition gdaldrivermanager.cpp:786
void AutoLoadDrivers()
Auto-load GDAL drivers from shared libraries.
Definition gdaldrivermanager.cpp:1036
void DeclareDeferredPluginDriver(GDALPluginDriverProxy *poProxyDriver)
Declare a driver that will be loaded as a plugin, when actually needed.
Definition gdaldrivermanager.cpp:1713
GDALDriver * GetDriverByName(const char *)
Fetch a driver based on the short name.
Definition gdaldrivermanager.cpp:731
GDALDriver * GetDriver(int)
Fetch driver by index.
Definition gdaldrivermanager.cpp:429
void ReorderDrivers()
Reorder drivers according to the order of the drivers.ini file.
Definition gdaldrivermanager.cpp:1181
Format specific driver.
Definition gdal_driver.h:63
GDALMajorObject(const GDALMajorObject &)=default
Copy constructor.
Proxy for a plugin driver.
Definition gdalplugindriverproxy.h:67
CPLErr
Error category.
Definition cpl_error.h:37
Core portability definitions for CPL.
#define CPL_C_END
Macro to end a block of C symbols.
Definition cpl_port.h:289
#define CPL_C_START
Macro to start a block of C symbols.
Definition cpl_port.h:285
#define CPL_DISALLOW_COPY_ASSIGN(ClassName)
Helper to remove the copy and assignment constructors so that the compiler will not generate the defa...
Definition cpl_port.h:936
Various convenience functions for working with strings and string lists.
Public (C callable) GDAL entry points.
GDALDatasetH GDALOpenEx(const char *pszFilename, unsigned int nOpenFlags, const char *const *papszAllowedDrivers, const char *const *papszOpenOptions, const char *const *papszSiblingFiles)
Open a raster or vector file as a GDALDataset.
Definition gdaldataset.cpp:3914
void * GDALDatasetH
Opaque type used for the C bindings of the C++ GDALDataset class.
Definition gdal_fwd.h:42