GDALCompatibility.hpp
Go to the documentation of this file.
1 /*
2 
3  This file is part of OpenFLUID software
4  Copyright(c) 2007, INRA - Montpellier SupAgro
5 
6 
7  == GNU General Public License Usage ==
8 
9  OpenFLUID is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  OpenFLUID is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with OpenFLUID. If not, see <http://www.gnu.org/licenses/>.
21 
22 
23  == Other Usage ==
24 
25  Other Usage means a use of OpenFLUID that is inconsistent with the GPL
26  license, and requires a written agreement between You and INRA.
27  Licensees for Other Usage of OpenFLUID may use this file in accordance
28  with the terms contained in the written agreement between You and INRA.
29 
30 */
31 
32 /**
33  @file GDALCompatibility.hpp
34 
35  @author Jean-Christophe FABRE <jean-christophe.fabre@supagro.inra.fr>
36 
37  This file contains macros to help ensuring compatibility
38  between GDAL version 1.xx and 2.xx of this library.
39  These macros mainly apply to vector part (OGR) of the library
40 */
41 
42 
43 
44 #ifndef __OPENFLUID_UTILS_GDALCOMPATIBILITY_HPP__
45 #define __OPENFLUID_UTILS_GDALCOMPATIBILITY_HPP__
46 
47 
48 #include <gdal.h>
49 
50 
51 #if !defined(GDAL_VERSION_MAJOR)
52  #error "GDAL_VERSION_MAJOR not defined"
53 #endif
54 
55 
56 /**
57  Macro for compatibility of vector drivers registering
58 */
59 #if (GDAL_VERSION_MAJOR >= 2)
60  #define GDALAllRegister_COMPAT() GDALAllRegister()
61 #else
62  #define GDALAllRegister_COMPAT() OGRRegisterAll()
63 #endif
64 
65 
66 /**
67  Macro for compatibility of vector data source type
68 */
69 #if (GDAL_VERSION_MAJOR >= 2)
70  #define GDALDataset_COMPAT GDALDataset
71 #else
72  #define GDALDataset_COMPAT OGRDataSource
73 #endif
74 
75 
76 /**
77  Macro for compatibility of vector driver type
78 */
79 #if (GDAL_VERSION_MAJOR >= 2)
80  #define GDALDriver_COMPAT GDALDriver
81 #else
82  #define GDALDriver_COMPAT OGRSFDriver
83 #endif
84 
85 
86 /**
87  Macro for compatibility of vector data opening (in read-write mode)
88  @param _M_path Path to the file(s) to open
89  @return a pointer to a GDALDataset_COMPAT data source
90 */
91 #if (GDAL_VERSION_MAJOR >= 2)
92  #define GDALOpenRW_COMPAT(_M_path) \
93  static_cast<GDALDataset_COMPAT*>(GDALOpenEx(_M_path,GDAL_OF_VECTOR | GDAL_OF_UPDATE,nullptr,nullptr,nullptr));
94 #else
95  #define GDALOpenRW_COMPAT(_M_path) OGRSFDriverRegistrar::Open(_M_path,true);
96 #endif
97 
98 
99 /**
100  Macro for compatibility of vector data opening (in read only mode)
101  @param _M_path Path to the file(s) to open
102  @return a pointer to a GDALDataset_COMPAT data source
103 */
104 #if (GDAL_VERSION_MAJOR >= 2)
105  #define GDALOpenRO_COMPAT(_M_path) \
106  static_cast<GDALDataset_COMPAT*>(GDALOpenEx(_M_path,GDAL_OF_VECTOR | GDAL_OF_READONLY,nullptr,nullptr,nullptr));
107 #else
108  #define GDALOpenRO_COMPAT(_M_path) OGRSFDriverRegistrar::Open(_M_path,false);
109 #endif
110 
111 
112 /**
113  Macro for compatibility of vector data copy
114  @param _M_driver Driver to use for the copy
115  @param _M_srcptr Data source to copy
116  @param _M_destpath Path to the copied file(s)
117  @return a pointer to a GDALDataset_COMPAT data source for the newly copied files
118 */
119 #if (GDAL_VERSION_MAJOR >= 2)
120  #define GDALCopy_COMPAT(_M_driver,_M_srcptr,_M_destpath) \
121  _M_driver->CreateCopy(_M_destpath,_M_srcptr,false,nullptr,nullptr,nullptr)
122 #else
123  #define GDALCopy_COMPAT(_M_driver,_M_srcptr,_M_destpath) \
124  _M_driver->CopyDataSource(_M_srcptr,_M_destpath, nullptr);
125 #endif
126 
127 
128 /**
129  Macro for compatibility of vector data creation
130  @param _M_driver Driver to use for the creation
131  @param _M_path Path to the file(s) to create
132  @return a pointer to a GDALDataset_COMPAT data source for the newly created files
133 */
134 #if (GDAL_VERSION_MAJOR >= 2)
135  #define GDALCreate_COMPAT(_M_driver,_M_path) \
136  _M_driver->Create(_M_path,0,0,0,GDT_Unknown,nullptr)
137 #else
138  #define GDALCreate_COMPAT(_M_driver,_M_path) \
139  _M_driver->CreateDataSource(_M_path, nullptr);
140 #endif
141 
142 
143 /**
144  Macro for compatibility of data source closing
145  @param _M_ptr Pointer to the data source to close
146 */
147 #if (GDAL_VERSION_MAJOR >= 2)
148  #define GDALClose_COMPAT(_M_ptr) GDALClose(_M_ptr);
149 #else
150  #define GDALClose_COMPAT(_M_ptr) OGRDataSource::DestroyDataSource(_M_ptr);
151 #endif
152 
153 
154 /**
155  Macro for compatibility of physical deletion of vector data
156  @param _M_driver Driver to use for the deletion
157  @param _M_path Path to the file(s) to delete
158 */
159 #if (GDAL_VERSION_MAJOR >= 2)
160  #define GDALDelete_COMPAT(_M_driver,_M_path) _M_driver->Delete(_M_path)
161 #else
162  #define GDALDelete_COMPAT(_M_driver,_M_path) _M_driver->DeleteDataSource(_M_path)
163 #endif
164 
165 
166 /**
167  Macro for compatibility of getting a driver by its name
168  @param _M_name Name of the driver
169  @return a pointer to a GDALDriver_COMPAT driver, NULL if not found
170 */
171 #if (GDAL_VERSION_MAJOR >= 2)
172  #define GDALGetDriverByName_COMPAT(_M_name) GetGDALDriverManager()->GetDriverByName(_M_name)
173 #else
174  #define GDALGetDriverByName_COMPAT(_M_name) OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName(_M_name)
175 #endif
176 
177 
178 
179 #endif /* __OPENFLUID_UTILS_GDALCOMPATIBILITY_HPP__ */