Line data Source code
1 : /******************************************************************************
2 : *
3 : * Name: gdal_dataset.h
4 : * Project: GDAL Core
5 : * Purpose: Declaration of GDALDataset 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 GDALDATASET_H_INCLUDED
16 : #define GDALDATASET_H_INCLUDED
17 :
18 : #include "cpl_port.h"
19 : #include "gdal_fwd.h"
20 : #include "gdal.h"
21 : #include "gdal_geotransform.h"
22 : #include "gdal_majorobject.h"
23 : #include "gdal_defaultoverviews.h"
24 : #include "ogr_core.h" // for OGRErr
25 : #include "ogr_feature.h" // for OGRFeatureUniquePtr
26 :
27 : #include <cstddef>
28 : #include <iterator>
29 : #include <memory>
30 : #include <vector>
31 :
32 : /* ******************************************************************** */
33 : /* GDALDataset */
34 : /* ******************************************************************** */
35 :
36 : class OGRGeometry;
37 : class OGRLayer;
38 : class OGRSpatialReference;
39 : class OGRStyleTable;
40 : class swq_select;
41 : class swq_select_parse_options;
42 : class GDALAsyncReader;
43 : class GDALDriver;
44 : class GDALGroup;
45 : class GDALMDArray;
46 : class GDALRasterBand;
47 : class GDALRelationship;
48 :
49 : //! @cond Doxygen_Suppress
50 : typedef struct GDALSQLParseInfo GDALSQLParseInfo;
51 : //! @endcond
52 :
53 : //! @cond Doxygen_Suppress
54 : #if !defined(OPTIONAL_OUTSIDE_GDAL)
55 : #if defined(GDAL_COMPILATION)
56 : #define OPTIONAL_OUTSIDE_GDAL(val)
57 : #else
58 : #define OPTIONAL_OUTSIDE_GDAL(val) = val
59 : #endif
60 : #endif
61 : //! @endcond
62 :
63 : //! @cond Doxygen_Suppress
64 : // This macro can be defined to check that GDALDataset::IRasterIO()
65 : // implementations do not alter the passed panBandList. It is not defined
66 : // by default (and should not!), hence int* is used.
67 : #if defined(GDAL_BANDMAP_TYPE_CONST_SAFE)
68 : #define BANDMAP_TYPE const int *
69 : #else
70 : #define BANDMAP_TYPE int *
71 : #endif
72 : //! @endcond
73 :
74 : /** A set of associated raster bands, usually from one file. */
75 : class CPL_DLL GDALDataset : public GDALMajorObject
76 : {
77 : friend GDALDatasetH CPL_STDCALL
78 : GDALOpenEx(const char *pszFilename, unsigned int nOpenFlags,
79 : const char *const *papszAllowedDrivers,
80 : const char *const *papszOpenOptions,
81 : const char *const *papszSiblingFiles);
82 : friend CPLErr CPL_STDCALL GDALClose(GDALDatasetH hDS);
83 :
84 : friend class GDALDriver;
85 : friend class GDALDefaultOverviews;
86 : friend class GDALProxyDataset;
87 : friend class GDALDriverManager;
88 :
89 : CPL_INTERNAL void AddToDatasetOpenList();
90 :
91 : CPL_INTERNAL void UnregisterFromSharedDataset();
92 :
93 : CPL_INTERNAL static void ReportErrorV(const char *pszDSName,
94 : CPLErr eErrClass, CPLErrorNum err_no,
95 : const char *fmt, va_list args);
96 :
97 : protected:
98 : //! @cond Doxygen_Suppress
99 : GDALDriver *poDriver = nullptr;
100 : GDALAccess eAccess = GA_ReadOnly;
101 :
102 : // Stored raster information.
103 : int nRasterXSize = 512;
104 : int nRasterYSize = 512;
105 : int nBands = 0;
106 : GDALRasterBand **papoBands = nullptr;
107 :
108 : static constexpr int OPEN_FLAGS_CLOSED = -1;
109 : int nOpenFlags =
110 : 0; // set to OPEN_FLAGS_CLOSED after Close() has been called
111 :
112 : int nRefCount = 1;
113 : bool bForceCachedIO = false;
114 : bool bShared = false;
115 : bool bIsInternal = true;
116 : bool bSuppressOnClose = false;
117 :
118 : mutable std::map<std::string, std::unique_ptr<OGRFieldDomain>>
119 : m_oMapFieldDomains{};
120 :
121 : GDALDataset(void);
122 : explicit GDALDataset(int bForceCachedIO);
123 :
124 : void RasterInitialize(int, int);
125 : void SetBand(int nNewBand, GDALRasterBand *poBand);
126 : void SetBand(int nNewBand, std::unique_ptr<GDALRasterBand> poBand);
127 :
128 : GDALDefaultOverviews oOvManager{};
129 :
130 : virtual CPLErr IBuildOverviews(const char *pszResampling, int nOverviews,
131 : const int *panOverviewList, int nListBands,
132 : const int *panBandList,
133 : GDALProgressFunc pfnProgress,
134 : void *pProgressData,
135 : CSLConstList papszOptions);
136 :
137 : virtual CPLErr
138 : IRasterIO(GDALRWFlag eRWFlag, int nXOff, int nYOff, int nXSize, int nYSize,
139 : void *pData, int nBufXSize, int nBufYSize, GDALDataType eBufType,
140 : int nBandCount, BANDMAP_TYPE panBandMap, GSpacing nPixelSpace,
141 : GSpacing nLineSpace, GSpacing nBandSpace,
142 : GDALRasterIOExtraArg *psExtraArg) CPL_WARN_UNUSED_RESULT;
143 :
144 : /* This method should only be be overloaded by GDALProxyDataset */
145 : virtual CPLErr
146 : BlockBasedRasterIO(GDALRWFlag eRWFlag, int nXOff, int nYOff, int nXSize,
147 : int nYSize, void *pData, int nBufXSize, int nBufYSize,
148 : GDALDataType eBufType, int nBandCount,
149 : const int *panBandMap, GSpacing nPixelSpace,
150 : GSpacing nLineSpace, GSpacing nBandSpace,
151 : GDALRasterIOExtraArg *psExtraArg) CPL_WARN_UNUSED_RESULT;
152 : CPLErr BlockBasedFlushCache(bool bAtClosing);
153 :
154 : CPLErr
155 : BandBasedRasterIO(GDALRWFlag eRWFlag, int nXOff, int nYOff, int nXSize,
156 : int nYSize, void *pData, int nBufXSize, int nBufYSize,
157 : GDALDataType eBufType, int nBandCount,
158 : const int *panBandMap, GSpacing nPixelSpace,
159 : GSpacing nLineSpace, GSpacing nBandSpace,
160 : GDALRasterIOExtraArg *psExtraArg) CPL_WARN_UNUSED_RESULT;
161 :
162 : CPLErr
163 : RasterIOResampled(GDALRWFlag eRWFlag, int nXOff, int nYOff, int nXSize,
164 : int nYSize, void *pData, int nBufXSize, int nBufYSize,
165 : GDALDataType eBufType, int nBandCount,
166 : const int *panBandMap, GSpacing nPixelSpace,
167 : GSpacing nLineSpace, GSpacing nBandSpace,
168 : GDALRasterIOExtraArg *psExtraArg) CPL_WARN_UNUSED_RESULT;
169 :
170 : CPLErr ValidateRasterIOOrAdviseReadParameters(
171 : const char *pszCallingFunc, int *pbStopProcessingOnCENone, int nXOff,
172 : int nYOff, int nXSize, int nYSize, int nBufXSize, int nBufYSize,
173 : int nBandCount, const int *panBandMap);
174 :
175 : CPLErr TryOverviewRasterIO(GDALRWFlag eRWFlag, int nXOff, int nYOff,
176 : int nXSize, int nYSize, void *pData,
177 : int nBufXSize, int nBufYSize,
178 : GDALDataType eBufType, int nBandCount,
179 : const int *panBandMap, GSpacing nPixelSpace,
180 : GSpacing nLineSpace, GSpacing nBandSpace,
181 : GDALRasterIOExtraArg *psExtraArg, int *pbTried);
182 :
183 : void ShareLockWithParentDataset(GDALDataset *poParentDataset);
184 :
185 : bool m_bCanBeReopened = false;
186 :
187 : virtual bool CanBeCloned(int nScopeFlags, bool bCanShareState) const;
188 :
189 : friend class GDALThreadSafeDataset;
190 : friend class MEMDataset;
191 : virtual std::unique_ptr<GDALDataset> Clone(int nScopeFlags,
192 : bool bCanShareState) const;
193 :
194 : //! @endcond
195 :
196 : void CleanupPostFileClosing();
197 :
198 : virtual int CloseDependentDatasets();
199 : //! @cond Doxygen_Suppress
200 : int ValidateLayerCreationOptions(const char *const *papszLCO);
201 :
202 : char **papszOpenOptions = nullptr;
203 :
204 : friend class GDALRasterBand;
205 :
206 : // The below methods related to read write mutex are fragile logic, and
207 : // should not be used by out-of-tree code if possible.
208 : int EnterReadWrite(GDALRWFlag eRWFlag);
209 : void LeaveReadWrite();
210 : void InitRWLock();
211 :
212 : void TemporarilyDropReadWriteLock();
213 : void ReacquireReadWriteLock();
214 :
215 : void DisableReadWriteMutex();
216 :
217 : int AcquireMutex();
218 : void ReleaseMutex();
219 :
220 : bool IsAllBands(int nBandCount, const int *panBandList) const;
221 : //! @endcond
222 :
223 : public:
224 : ~GDALDataset() override;
225 :
226 : virtual CPLErr Close();
227 :
228 : int GetRasterXSize() const;
229 : int GetRasterYSize() const;
230 : int GetRasterCount() const;
231 : GDALRasterBand *GetRasterBand(int);
232 : const GDALRasterBand *GetRasterBand(int) const;
233 :
234 : /**
235 : * @brief SetQueryLoggerFunc
236 : * @param pfnQueryLoggerFuncIn query logger function callback
237 : * @param poQueryLoggerArgIn arguments passed to the query logger function
238 : * @return true on success
239 : */
240 : virtual bool SetQueryLoggerFunc(GDALQueryLoggerFunc pfnQueryLoggerFuncIn,
241 : void *poQueryLoggerArgIn);
242 :
243 : /** Class returned by GetBands() that act as a container for raster bands.
244 : */
245 : class CPL_DLL Bands
246 : {
247 : private:
248 : friend class GDALDataset;
249 : GDALDataset *m_poSelf;
250 :
251 7 : CPL_INTERNAL explicit Bands(GDALDataset *poSelf) : m_poSelf(poSelf)
252 : {
253 7 : }
254 :
255 6 : class CPL_DLL Iterator
256 : {
257 : struct Private;
258 : std::unique_ptr<Private> m_poPrivate;
259 :
260 : public:
261 : Iterator(GDALDataset *poDS, bool bStart);
262 : Iterator(const Iterator &oOther); // declared but not defined.
263 : // Needed for gcc 5.4 at least
264 : Iterator(Iterator &&oOther) noexcept; // declared but not defined.
265 : // Needed for gcc 5.4 at least
266 : ~Iterator();
267 : GDALRasterBand *operator*();
268 : Iterator &operator++();
269 : bool operator!=(const Iterator &it) const;
270 : };
271 :
272 : public:
273 : const Iterator begin() const;
274 :
275 : const Iterator end() const;
276 :
277 : size_t size() const;
278 :
279 : GDALRasterBand *operator[](int iBand);
280 : GDALRasterBand *operator[](size_t iBand);
281 : };
282 :
283 : Bands GetBands();
284 :
285 : /** Class returned by GetBands() that act as a container for raster bands.
286 : */
287 : class CPL_DLL ConstBands
288 : {
289 : private:
290 : friend class GDALDataset;
291 : const GDALDataset *const m_poSelf;
292 :
293 4 : CPL_INTERNAL explicit ConstBands(const GDALDataset *poSelf)
294 4 : : m_poSelf(poSelf)
295 : {
296 4 : }
297 :
298 2 : class CPL_DLL Iterator
299 : {
300 : struct Private;
301 : std::unique_ptr<Private> m_poPrivate;
302 :
303 : public:
304 : Iterator(const GDALDataset *poDS, bool bStart);
305 : ~Iterator();
306 : const GDALRasterBand *operator*() const;
307 : Iterator &operator++();
308 : bool operator!=(const Iterator &it) const;
309 : };
310 :
311 : public:
312 : const Iterator begin() const;
313 :
314 : const Iterator end() const;
315 :
316 : size_t size() const;
317 :
318 : const GDALRasterBand *operator[](int iBand) const;
319 : const GDALRasterBand *operator[](size_t iBand) const;
320 : };
321 :
322 : ConstBands GetBands() const;
323 :
324 : virtual CPLErr FlushCache(bool bAtClosing = false);
325 : virtual CPLErr DropCache();
326 :
327 : virtual GIntBig GetEstimatedRAMUsage();
328 :
329 : virtual const OGRSpatialReference *GetSpatialRef() const;
330 : virtual CPLErr SetSpatialRef(const OGRSpatialReference *poSRS);
331 :
332 : virtual const OGRSpatialReference *GetSpatialRefRasterOnly() const;
333 : virtual const OGRSpatialReference *GetSpatialRefVectorOnly() const;
334 :
335 : // Compatibility layer
336 : const char *GetProjectionRef(void) const;
337 : CPLErr SetProjection(const char *pszProjection);
338 :
339 : virtual CPLErr GetGeoTransform(GDALGeoTransform >) const;
340 : virtual CPLErr SetGeoTransform(const GDALGeoTransform >);
341 :
342 : CPLErr GetGeoTransform(double *padfGeoTransform) const
343 : #if defined(GDAL_COMPILATION) && !defined(DOXYGEN_XML)
344 : CPL_WARN_DEPRECATED("Use GetGeoTransform(GDALGeoTransform&) instead")
345 : #endif
346 : ;
347 :
348 : CPLErr SetGeoTransform(const double *padfGeoTransform)
349 : #if defined(GDAL_COMPILATION) && !defined(DOXYGEN_XML)
350 : CPL_WARN_DEPRECATED(
351 : "Use SetGeoTransform(const GDALGeoTransform&) instead")
352 : #endif
353 : ;
354 :
355 : virtual CPLErr GetExtent(OGREnvelope *psExtent,
356 : const OGRSpatialReference *poCRS = nullptr) const;
357 : virtual CPLErr GetExtentWGS84LongLat(OGREnvelope *psExtent) const;
358 :
359 : CPLErr GeolocationToPixelLine(
360 : double dfGeolocX, double dfGeolocY, const OGRSpatialReference *poSRS,
361 : double *pdfPixel, double *pdfLine,
362 : CSLConstList papszTransformerOptions = nullptr) const;
363 :
364 : virtual CPLErr AddBand(GDALDataType eType, char **papszOptions = nullptr);
365 :
366 : virtual void *GetInternalHandle(const char *pszHandleName);
367 : virtual GDALDriver *GetDriver(void);
368 : virtual char **GetFileList(void);
369 :
370 : const char *GetDriverName() const;
371 :
372 : virtual const OGRSpatialReference *GetGCPSpatialRef() const;
373 : virtual int GetGCPCount();
374 : virtual const GDAL_GCP *GetGCPs();
375 : virtual CPLErr SetGCPs(int nGCPCount, const GDAL_GCP *pasGCPList,
376 : const OGRSpatialReference *poGCP_SRS);
377 :
378 : // Compatibility layer
379 : const char *GetGCPProjection() const;
380 : CPLErr SetGCPs(int nGCPCount, const GDAL_GCP *pasGCPList,
381 : const char *pszGCPProjection);
382 :
383 : virtual CPLErr AdviseRead(int nXOff, int nYOff, int nXSize, int nYSize,
384 : int nBufXSize, int nBufYSize, GDALDataType eDT,
385 : int nBandCount, int *panBandList,
386 : char **papszOptions);
387 :
388 : virtual CPLErr CreateMaskBand(int nFlagsIn);
389 :
390 : virtual GDALAsyncReader *
391 : BeginAsyncReader(int nXOff, int nYOff, int nXSize, int nYSize, void *pBuf,
392 : int nBufXSize, int nBufYSize, GDALDataType eBufType,
393 : int nBandCount, int *panBandMap, int nPixelSpace,
394 : int nLineSpace, int nBandSpace, char **papszOptions);
395 : virtual void EndAsyncReader(GDALAsyncReader *poARIO);
396 :
397 : //! @cond Doxygen_Suppress
398 : struct RawBinaryLayout
399 : {
400 : enum class Interleaving
401 : {
402 : UNKNOWN,
403 : BIP,
404 : BIL,
405 : BSQ
406 : };
407 : std::string osRawFilename{};
408 : Interleaving eInterleaving = Interleaving::UNKNOWN;
409 : GDALDataType eDataType = GDT_Unknown;
410 : bool bLittleEndianOrder = false;
411 :
412 : vsi_l_offset nImageOffset = 0;
413 : GIntBig nPixelOffset = 0;
414 : GIntBig nLineOffset = 0;
415 : GIntBig nBandOffset = 0;
416 : };
417 :
418 : virtual bool GetRawBinaryLayout(RawBinaryLayout &);
419 : //! @endcond
420 :
421 : #ifndef DOXYGEN_SKIP
422 : CPLErr RasterIO(GDALRWFlag eRWFlag, int nXOff, int nYOff, int nXSize,
423 : int nYSize, void *pData, int nBufXSize, int nBufYSize,
424 : GDALDataType eBufType, int nBandCount,
425 : const int *panBandMap, GSpacing nPixelSpace,
426 : GSpacing nLineSpace, GSpacing nBandSpace,
427 : GDALRasterIOExtraArg *psExtraArg
428 : OPTIONAL_OUTSIDE_GDAL(nullptr)) CPL_WARN_UNUSED_RESULT;
429 : #else
430 : CPLErr RasterIO(GDALRWFlag eRWFlag, int nXOff, int nYOff, int nXSize,
431 : int nYSize, void *pData, int nBufXSize, int nBufYSize,
432 : GDALDataType eBufType, int nBandCount,
433 : const int *panBandMap, GSpacing nPixelSpace,
434 : GSpacing nLineSpace, GSpacing nBandSpace,
435 : GDALRasterIOExtraArg *psExtraArg) CPL_WARN_UNUSED_RESULT;
436 : #endif
437 :
438 : virtual CPLStringList GetCompressionFormats(int nXOff, int nYOff,
439 : int nXSize, int nYSize,
440 : int nBandCount,
441 : const int *panBandList);
442 : virtual CPLErr ReadCompressedData(const char *pszFormat, int nXOff,
443 : int nYOff, int nXSize, int nYSize,
444 : int nBands, const int *panBandList,
445 : void **ppBuffer, size_t *pnBufferSize,
446 : char **ppszDetailedFormat);
447 :
448 : int Reference();
449 : int Dereference();
450 : int ReleaseRef();
451 :
452 : /** Return access mode.
453 : * @return access mode.
454 : */
455 194472 : GDALAccess GetAccess() const
456 : {
457 194472 : return eAccess;
458 : }
459 :
460 : int GetShared() const;
461 : void MarkAsShared();
462 :
463 : void MarkSuppressOnClose();
464 : void UnMarkSuppressOnClose();
465 :
466 : /** Return MarkSuppressOnClose flag.
467 : * @return MarkSuppressOnClose flag.
468 : */
469 5725734 : bool IsMarkedSuppressOnClose() const
470 : {
471 5725734 : return bSuppressOnClose;
472 : }
473 :
474 : /** Return open options.
475 : * @return open options.
476 : */
477 144062 : char **GetOpenOptions()
478 : {
479 144062 : return papszOpenOptions;
480 : }
481 :
482 : bool IsThreadSafe(int nScopeFlags) const;
483 :
484 : #ifndef DOXYGEN_SKIP
485 : /** Return open options.
486 : * @return open options.
487 : */
488 7 : CSLConstList GetOpenOptions() const
489 : {
490 7 : return papszOpenOptions;
491 : }
492 : #endif
493 :
494 : static GDALDataset **GetOpenDatasets(int *pnDatasetCount);
495 :
496 : #ifndef DOXYGEN_SKIP
497 : CPLErr
498 : BuildOverviews(const char *pszResampling, int nOverviews,
499 : const int *panOverviewList, int nListBands,
500 : const int *panBandList, GDALProgressFunc pfnProgress,
501 : void *pProgressData,
502 : CSLConstList papszOptions OPTIONAL_OUTSIDE_GDAL(nullptr));
503 : #else
504 : CPLErr BuildOverviews(const char *pszResampling, int nOverviews,
505 : const int *panOverviewList, int nListBands,
506 : const int *panBandList, GDALProgressFunc pfnProgress,
507 : void *pProgressData, CSLConstList papszOptions);
508 : #endif
509 :
510 : virtual CPLErr AddOverviews(const std::vector<GDALDataset *> &apoSrcOvrDS,
511 : GDALProgressFunc pfnProgress,
512 : void *pProgressData, CSLConstList papszOptions);
513 :
514 : #ifndef DOXYGEN_XML
515 : void ReportError(CPLErr eErrClass, CPLErrorNum err_no, const char *fmt,
516 : ...) const CPL_PRINT_FUNC_FORMAT(4, 5);
517 :
518 : static void ReportError(const char *pszDSName, CPLErr eErrClass,
519 : CPLErrorNum err_no, const char *fmt, ...)
520 : CPL_PRINT_FUNC_FORMAT(4, 5);
521 : #endif
522 :
523 : char **GetMetadata(const char *pszDomain = "") override;
524 :
525 : // Only defined when Doxygen enabled
526 : #ifdef DOXYGEN_SKIP
527 : CPLErr SetMetadata(char **papszMetadata, const char *pszDomain) override;
528 : CPLErr SetMetadataItem(const char *pszName, const char *pszValue,
529 : const char *pszDomain) override;
530 : #endif
531 :
532 : char **GetMetadataDomainList() override;
533 :
534 : virtual void ClearStatistics();
535 :
536 : std::shared_ptr<GDALMDArray> AsMDArray(CSLConstList papszOptions = nullptr);
537 :
538 : /** Convert a GDALDataset* to a GDALDatasetH.
539 : * @since GDAL 2.3
540 : */
541 31299 : static inline GDALDatasetH ToHandle(GDALDataset *poDS)
542 : {
543 31299 : return static_cast<GDALDatasetH>(poDS);
544 : }
545 :
546 : /** Convert a GDALDatasetH to a GDALDataset*.
547 : * @since GDAL 2.3
548 : */
549 1523779 : static inline GDALDataset *FromHandle(GDALDatasetH hDS)
550 : {
551 1523779 : return static_cast<GDALDataset *>(hDS);
552 : }
553 :
554 : /** @see GDALOpenEx().
555 : * @since GDAL 2.3
556 : */
557 30988 : static GDALDataset *Open(const char *pszFilename,
558 : unsigned int nOpenFlags = 0,
559 : const char *const *papszAllowedDrivers = nullptr,
560 : const char *const *papszOpenOptions = nullptr,
561 : const char *const *papszSiblingFiles = nullptr)
562 : {
563 30988 : return FromHandle(GDALOpenEx(pszFilename, nOpenFlags,
564 : papszAllowedDrivers, papszOpenOptions,
565 30974 : papszSiblingFiles));
566 : }
567 :
568 : /** Object returned by GetFeatures() iterators */
569 : struct FeatureLayerPair
570 : {
571 : /** Unique pointer to a OGRFeature. */
572 : OGRFeatureUniquePtr feature{};
573 :
574 : /** Layer to which the feature belongs to. */
575 : OGRLayer *layer = nullptr;
576 : };
577 :
578 : //! @cond Doxygen_Suppress
579 : // SetEnableOverviews() only to be used by GDALOverviewDataset
580 : void SetEnableOverviews(bool bEnable);
581 :
582 : // Only to be used by driver's GetOverviewCount() method.
583 : bool AreOverviewsEnabled() const;
584 :
585 : static void ReportUpdateNotSupportedByDriver(const char *pszDriverName);
586 : //! @endcond
587 :
588 : private:
589 : class Private;
590 : Private *m_poPrivate;
591 :
592 : CPL_INTERNAL OGRLayer *BuildLayerFromSelectInfo(
593 : swq_select *psSelectInfo, OGRGeometry *poSpatialFilter,
594 : const char *pszDialect, swq_select_parse_options *poSelectParseOptions);
595 : CPLStringList oDerivedMetadataList{};
596 :
597 : public:
598 : virtual int GetLayerCount() const;
599 : virtual const OGRLayer *GetLayer(int iLayer) const;
600 :
601 1865110 : OGRLayer *GetLayer(int iLayer)
602 : {
603 : return const_cast<OGRLayer *>(
604 1865110 : const_cast<const GDALDataset *>(this)->GetLayer(iLayer));
605 : }
606 :
607 : virtual bool IsLayerPrivate(int iLayer) const;
608 :
609 : /** Class returned by GetLayers() that acts as a range of layers.
610 : * @since GDAL 2.3
611 : */
612 : class CPL_DLL Layers
613 : {
614 : private:
615 : friend class GDALDataset;
616 : GDALDataset *m_poSelf;
617 :
618 304 : CPL_INTERNAL explicit Layers(GDALDataset *poSelf) : m_poSelf(poSelf)
619 : {
620 304 : }
621 :
622 : public:
623 : /** Layer iterator.
624 : * @since GDAL 2.3
625 : */
626 618 : class CPL_DLL Iterator
627 : {
628 : struct Private;
629 : std::unique_ptr<Private> m_poPrivate;
630 :
631 : public:
632 : using value_type = OGRLayer *; /**< value_type */
633 : using reference = OGRLayer *; /**< reference */
634 : using difference_type = void; /**< difference_type */
635 : using pointer = void; /**< pointer */
636 : using iterator_category =
637 : std::input_iterator_tag; /**< iterator_category */
638 :
639 : Iterator(); /**< Default constructor */
640 : Iterator(GDALDataset *poDS, bool bStart); /**< Constructor */
641 : Iterator(const Iterator &oOther); /**< Copy constructor */
642 : Iterator(Iterator &&oOther) noexcept; /**< Move constructor */
643 : ~Iterator(); /**< Destructor */
644 :
645 : Iterator &
646 : operator=(const Iterator &oOther); /**< Assignment operator */
647 : Iterator &operator=(
648 : Iterator &&oOther) noexcept; /**< Move assignment operator */
649 :
650 : value_type operator*() const; /**< Dereference operator */
651 : Iterator &operator++(); /**< Pre-increment operator */
652 : Iterator operator++(int); /**< Post-increment operator */
653 : bool operator!=(const Iterator &it)
654 : const; /**< Difference comparison operator */
655 : };
656 :
657 : Iterator begin() const;
658 : Iterator end() const;
659 :
660 : size_t size() const;
661 :
662 : OGRLayer *operator[](int iLayer);
663 : OGRLayer *operator[](size_t iLayer);
664 : OGRLayer *operator[](const char *pszLayername);
665 : };
666 :
667 : Layers GetLayers();
668 :
669 : /** Class returned by GetLayers() that acts as a range of layers.
670 : * @since GDAL 3.12
671 : */
672 : class CPL_DLL ConstLayers
673 : {
674 : private:
675 : friend class GDALDataset;
676 : const GDALDataset *m_poSelf;
677 :
678 17233 : CPL_INTERNAL explicit ConstLayers(const GDALDataset *poSelf)
679 17233 : : m_poSelf(poSelf)
680 : {
681 17233 : }
682 :
683 : public:
684 : /** Layer iterator.
685 : * @since GDAL 3.12
686 : */
687 34476 : class CPL_DLL Iterator
688 : {
689 : struct Private;
690 : std::unique_ptr<Private> m_poPrivate;
691 :
692 : public:
693 : using value_type = const OGRLayer *; /**< value_type */
694 : using reference = const OGRLayer *; /**< reference */
695 : using difference_type = void; /**< difference_type */
696 : using pointer = void; /**< pointer */
697 : using iterator_category =
698 : std::input_iterator_tag; /**< iterator_category */
699 :
700 : Iterator(); /**< Default constructor */
701 : Iterator(const GDALDataset *poDS, bool bStart); /**< Constructor */
702 : Iterator(const Iterator &oOther); /**< Copy constructor */
703 : Iterator(Iterator &&oOther) noexcept; /**< Move constructor */
704 : ~Iterator(); /**< Destructor */
705 :
706 : Iterator &
707 : operator=(const Iterator &oOther); /**< Assignment operator */
708 : Iterator &operator=(
709 : Iterator &&oOther) noexcept; /**< Move assignment operator */
710 :
711 : value_type operator*() const; /**< Dereference operator */
712 : Iterator &operator++(); /**< Pre-increment operator */
713 : Iterator operator++(int); /**< Post-increment operator */
714 : bool operator!=(const Iterator &it)
715 : const; /**< Difference comparison operator */
716 : };
717 :
718 : Iterator begin() const;
719 : Iterator end() const;
720 :
721 : size_t size() const;
722 :
723 : const OGRLayer *operator[](int iLayer);
724 : const OGRLayer *operator[](size_t iLayer);
725 : const OGRLayer *operator[](const char *pszLayername);
726 : };
727 :
728 : ConstLayers GetLayers() const;
729 :
730 : virtual OGRLayer *GetLayerByName(const char *);
731 :
732 : int GetLayerIndex(const char *pszName) const;
733 :
734 : virtual OGRErr DeleteLayer(int iLayer);
735 :
736 : virtual void ResetReading();
737 : virtual OGRFeature *GetNextFeature(OGRLayer **ppoBelongingLayer,
738 : double *pdfProgressPct,
739 : GDALProgressFunc pfnProgress,
740 : void *pProgressData);
741 :
742 : /** Class returned by GetFeatures() that act as a container for vector
743 : * features. */
744 : class CPL_DLL Features
745 : {
746 : private:
747 : friend class GDALDataset;
748 : GDALDataset *m_poSelf;
749 :
750 2 : CPL_INTERNAL explicit Features(GDALDataset *poSelf) : m_poSelf(poSelf)
751 : {
752 2 : }
753 :
754 4 : class CPL_DLL Iterator
755 : {
756 : struct Private;
757 : std::unique_ptr<Private> m_poPrivate;
758 :
759 : public:
760 : Iterator(GDALDataset *poDS, bool bStart);
761 : Iterator(const Iterator &oOther); // declared but not defined.
762 : // Needed for gcc 5.4 at least
763 : Iterator(Iterator &&oOther) noexcept; // declared but not defined.
764 : // Needed for gcc 5.4 at least
765 : ~Iterator();
766 : const FeatureLayerPair &operator*() const;
767 : Iterator &operator++();
768 : bool operator!=(const Iterator &it) const;
769 : };
770 :
771 : public:
772 : const Iterator begin() const;
773 :
774 : const Iterator end() const;
775 : };
776 :
777 : Features GetFeatures();
778 :
779 : virtual int TestCapability(const char *) const;
780 :
781 : virtual std::vector<std::string>
782 : GetFieldDomainNames(CSLConstList papszOptions = nullptr) const;
783 :
784 : virtual const OGRFieldDomain *GetFieldDomain(const std::string &name) const;
785 :
786 : virtual bool AddFieldDomain(std::unique_ptr<OGRFieldDomain> &&domain,
787 : std::string &failureReason);
788 :
789 : virtual bool DeleteFieldDomain(const std::string &name,
790 : std::string &failureReason);
791 :
792 : virtual bool UpdateFieldDomain(std::unique_ptr<OGRFieldDomain> &&domain,
793 : std::string &failureReason);
794 :
795 : virtual std::vector<std::string>
796 : GetRelationshipNames(CSLConstList papszOptions = nullptr) const;
797 :
798 : virtual const GDALRelationship *
799 : GetRelationship(const std::string &name) const;
800 :
801 : virtual bool
802 : AddRelationship(std::unique_ptr<GDALRelationship> &&relationship,
803 : std::string &failureReason);
804 :
805 : virtual bool DeleteRelationship(const std::string &name,
806 : std::string &failureReason);
807 :
808 : virtual bool
809 : UpdateRelationship(std::unique_ptr<GDALRelationship> &&relationship,
810 : std::string &failureReason);
811 :
812 : //! @cond Doxygen_Suppress
813 : OGRLayer *CreateLayer(const char *pszName);
814 :
815 : OGRLayer *CreateLayer(const char *pszName, std::nullptr_t);
816 : //! @endcond
817 :
818 : OGRLayer *CreateLayer(const char *pszName,
819 : const OGRSpatialReference *poSpatialRef,
820 : OGRwkbGeometryType eGType = wkbUnknown,
821 : CSLConstList papszOptions = nullptr);
822 :
823 : OGRLayer *CreateLayer(const char *pszName,
824 : const OGRGeomFieldDefn *poGeomFieldDefn,
825 : CSLConstList papszOptions = nullptr);
826 :
827 : virtual OGRLayer *CopyLayer(OGRLayer *poSrcLayer, const char *pszNewName,
828 : char **papszOptions = nullptr);
829 :
830 : virtual OGRStyleTable *GetStyleTable();
831 : virtual void SetStyleTableDirectly(OGRStyleTable *poStyleTable);
832 :
833 : virtual void SetStyleTable(OGRStyleTable *poStyleTable);
834 :
835 : virtual OGRLayer *ExecuteSQL(const char *pszStatement,
836 : OGRGeometry *poSpatialFilter,
837 : const char *pszDialect);
838 : virtual void ReleaseResultSet(OGRLayer *poResultsSet);
839 : virtual OGRErr AbortSQL();
840 :
841 : int GetRefCount() const;
842 : int GetSummaryRefCount() const;
843 : OGRErr Release();
844 :
845 : virtual OGRErr StartTransaction(int bForce = FALSE);
846 : virtual OGRErr CommitTransaction();
847 : virtual OGRErr RollbackTransaction();
848 :
849 : virtual std::shared_ptr<GDALGroup> GetRootGroup() const;
850 :
851 : static std::string BuildFilename(const char *pszFilename,
852 : const char *pszReferencePath,
853 : bool bRelativeToReferencePath);
854 :
855 : //! @cond Doxygen_Suppress
856 : static int IsGenericSQLDialect(const char *pszDialect);
857 :
858 : // Semi-public methods. Only to be used by in-tree drivers.
859 : GDALSQLParseInfo *
860 : BuildParseInfo(swq_select *psSelectInfo,
861 : swq_select_parse_options *poSelectParseOptions);
862 : static void DestroyParseInfo(GDALSQLParseInfo *psParseInfo);
863 : OGRLayer *ExecuteSQL(const char *pszStatement, OGRGeometry *poSpatialFilter,
864 : const char *pszDialect,
865 : swq_select_parse_options *poSelectParseOptions);
866 :
867 : static constexpr const char *const apszSpecialSubDatasetSyntax[] = {
868 : "NITF_IM:{ANY}:{FILENAME}", "PDF:{ANY}:{FILENAME}",
869 : "RASTERLITE:{FILENAME},{ANY}", "TILEDB:\"{FILENAME}\":{ANY}",
870 : "TILEDB:{FILENAME}:{ANY}"};
871 :
872 : //! @endcond
873 :
874 : protected:
875 : virtual OGRLayer *ICreateLayer(const char *pszName,
876 : const OGRGeomFieldDefn *poGeomFieldDefn,
877 : CSLConstList papszOptions);
878 :
879 : //! @cond Doxygen_Suppress
880 : OGRErr ProcessSQLCreateIndex(const char *);
881 : OGRErr ProcessSQLDropIndex(const char *);
882 : OGRErr ProcessSQLDropTable(const char *);
883 : OGRErr ProcessSQLAlterTableAddColumn(const char *);
884 : OGRErr ProcessSQLAlterTableDropColumn(const char *);
885 : OGRErr ProcessSQLAlterTableAlterColumn(const char *);
886 : OGRErr ProcessSQLAlterTableRenameColumn(const char *);
887 :
888 : OGRStyleTable *m_poStyleTable = nullptr;
889 :
890 : friend class GDALProxyPoolDataset;
891 : //! @endcond
892 :
893 : private:
894 : CPL_DISALLOW_COPY_ASSIGN(GDALDataset)
895 : };
896 :
897 : //! @cond Doxygen_Suppress
898 : struct CPL_DLL GDALDatasetUniquePtrDeleter
899 : {
900 94 : void operator()(GDALDataset *poDataset) const
901 : {
902 94 : GDALClose(poDataset);
903 94 : }
904 : };
905 :
906 : //! @endcond
907 :
908 : //! @cond Doxygen_Suppress
909 : struct CPL_DLL GDALDatasetUniquePtrReleaser
910 : {
911 2290 : void operator()(GDALDataset *poDataset) const
912 : {
913 2290 : if (poDataset)
914 2287 : poDataset->Release();
915 2290 : }
916 : };
917 :
918 : //! @endcond
919 :
920 : /** Unique pointer type for GDALDataset.
921 : * Appropriate for use on datasets open in non-shared mode and onto which
922 : * reference counter has not been manually modified.
923 : * @since GDAL 2.3
924 : */
925 : using GDALDatasetUniquePtr =
926 : std::unique_ptr<GDALDataset, GDALDatasetUniquePtrDeleter>;
927 :
928 : #endif
|