LCOV - code coverage report
Current view: top level - gcore/multidim - gdal_multidim.h (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 87 93 93.5 %
Date: 2026-05-29 23:25:07 Functions: 51 60 85.0 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Name:     gdal_multidim.h
       4             :  * Project:  GDAL Core
       5             :  * Purpose:  Declaration of classes for multidimensional support
       6             :  * Author:   Even Rouault <even.rouault at spatialys.com>
       7             :  *
       8             :  ******************************************************************************
       9             :  * Copyright (c) 2019, Even Rouault <even.rouault at spatialys.com>
      10             :  *
      11             :  * SPDX-License-Identifier: MIT
      12             :  ****************************************************************************/
      13             : 
      14             : #ifndef GDALMULTIDIM_H_INCLUDED
      15             : #define GDALMULTIDIM_H_INCLUDED
      16             : 
      17             : #include "cpl_conv.h"
      18             : #include "cpl_string.h"
      19             : #include "gdal.h"
      20             : #include "gdal_geotransform.h"
      21             : 
      22             : #include <cstddef>
      23             : #include <cstdint>
      24             : #include <functional>
      25             : #include <limits>
      26             : #include <memory>
      27             : #include <vector>
      28             : 
      29             : /* ******************************************************************** */
      30             : /*                       Multidimensional array API                     */
      31             : /* ******************************************************************** */
      32             : 
      33             : class GDALMDArray;
      34             : class GDALAttribute;
      35             : class GDALDataset;
      36             : class GDALDimension;
      37             : class GDALEDTComponent;
      38             : class GDALRasterAttributeTable;
      39             : class GDALRasterBand;
      40             : class OGRLayer;
      41             : class OGRSpatialReference;
      42             : 
      43             : /* ******************************************************************** */
      44             : /*                         GDALExtendedDataType                         */
      45             : /* ******************************************************************** */
      46             : 
      47             : /**
      48             :  * Class used to represent potentially complex data types.
      49             :  * Several classes of data types are supported: numeric (based on GDALDataType),
      50             :  * compound or string.
      51             :  *
      52             :  * @since GDAL 3.1
      53             :  */
      54      625040 : class CPL_DLL GDALExtendedDataType
      55             : {
      56             :   public:
      57             :     ~GDALExtendedDataType();
      58             : 
      59             :     GDALExtendedDataType(GDALExtendedDataType &&);
      60             :     GDALExtendedDataType(const GDALExtendedDataType &);
      61             : 
      62             :     GDALExtendedDataType &operator=(const GDALExtendedDataType &);
      63             :     GDALExtendedDataType &operator=(GDALExtendedDataType &&);
      64             : 
      65             :     static GDALExtendedDataType Create(GDALDataType eType);
      66             :     static GDALExtendedDataType
      67             :     Create(const std::string &osName, GDALDataType eBaseType,
      68             :            std::unique_ptr<GDALRasterAttributeTable>);
      69             :     static GDALExtendedDataType
      70             :     Create(const std::string &osName, size_t nTotalSize,
      71             :            std::vector<std::unique_ptr<GDALEDTComponent>> &&components);
      72             :     static GDALExtendedDataType
      73             :     CreateString(size_t nMaxStringLength = 0,
      74             :                  GDALExtendedDataTypeSubType eSubType = GEDTST_NONE);
      75             : 
      76             :     bool operator==(const GDALExtendedDataType &) const;
      77             : 
      78             :     /** Non-equality operator */
      79        2054 :     bool operator!=(const GDALExtendedDataType &other) const
      80             :     {
      81        2054 :         return !(operator==(other));
      82             :     }
      83             : 
      84             :     /** Return type name.
      85             :      *
      86             :      * This is the same as the C function GDALExtendedDataTypeGetName()
      87             :      */
      88          25 :     const std::string &GetName() const
      89             :     {
      90          25 :         return m_osName;
      91             :     }
      92             : 
      93             :     /** Return type class.
      94             :      *
      95             :      * This is the same as the C function GDALExtendedDataTypeGetClass()
      96             :      */
      97     9629428 :     GDALExtendedDataTypeClass GetClass() const
      98             :     {
      99     9629428 :         return m_eClass;
     100             :     }
     101             : 
     102             :     /** Return numeric data type (only valid when GetClass() == GEDTC_NUMERIC)
     103             :      *
     104             :      * This is the same as the C function
     105             :      * GDALExtendedDataTypeGetNumericDataType()
     106             :      */
     107    15401792 :     GDALDataType GetNumericDataType() const
     108             :     {
     109    15401792 :         return m_eNumericDT;
     110             :     }
     111             : 
     112             :     /** Return subtype.
     113             :      *
     114             :      * This is the same as the C function GDALExtendedDataTypeGetSubType()
     115             :      *
     116             :      * @since 3.4
     117             :      */
     118         606 :     GDALExtendedDataTypeSubType GetSubType() const
     119             :     {
     120         606 :         return m_eSubType;
     121             :     }
     122             : 
     123             :     /** Return the components of the data type (only valid when GetClass() ==
     124             :      * GEDTC_COMPOUND)
     125             :      *
     126             :      * This is the same as the C function GDALExtendedDataTypeGetComponents()
     127             :      */
     128     2083512 :     const std::vector<std::unique_ptr<GDALEDTComponent>> &GetComponents() const
     129             :     {
     130     2083512 :         return m_aoComponents;
     131             :     }
     132             : 
     133             :     /** Return data type size in bytes.
     134             :      *
     135             :      * For a string, this will be size of a char* pointer.
     136             :      *
     137             :      * This is the same as the C function GDALExtendedDataTypeGetSize()
     138             :      */
     139       88359 :     size_t GetSize() const
     140             :     {
     141       88359 :         return m_nSize;
     142             :     }
     143             : 
     144             :     /** Return the maximum length of a string in bytes.
     145             :      *
     146             :      * 0 indicates unknown/unlimited string.
     147             :      */
     148          26 :     size_t GetMaxStringLength() const
     149             :     {
     150          26 :         return m_nMaxStringLength;
     151             :     }
     152             : 
     153             :     /** Return associated raster attribute table, when there is one.
     154             :      *
     155             :      * For the netCDF driver, the RAT will capture enumerated types, with
     156             :      * a "value" column with an integer value and a "name" column with the
     157             :      * associated name.
     158             :      *
     159             :      * This is the same as the C function GDALExtendedDataTypeGetRAT()
     160             :      *
     161             :      * @since 3.12
     162             :      */
     163         454 :     const GDALRasterAttributeTable *GetRAT() const
     164             :     {
     165         454 :         return m_poRAT.get();
     166             :     }
     167             : 
     168             :     bool CanConvertTo(const GDALExtendedDataType &other) const;
     169             : 
     170             :     bool NeedsFreeDynamicMemory() const;
     171             : 
     172             :     void FreeDynamicMemory(void *pBuffer) const;
     173             : 
     174             :     static bool CopyValue(const void *pSrc, const GDALExtendedDataType &srcType,
     175             :                           void *pDst, const GDALExtendedDataType &dstType);
     176             : 
     177             :     static bool CopyValues(const void *pSrc,
     178             :                            const GDALExtendedDataType &srcType,
     179             :                            GPtrDiff_t nSrcStrideInElts, void *pDst,
     180             :                            const GDALExtendedDataType &dstType,
     181             :                            GPtrDiff_t nDstStrideInElts, size_t nValues);
     182             : 
     183             :   private:
     184             :     GDALExtendedDataType(size_t nMaxStringLength,
     185             :                          GDALExtendedDataTypeSubType eSubType);
     186             :     explicit GDALExtendedDataType(GDALDataType eType);
     187             :     GDALExtendedDataType(const std::string &osName, GDALDataType eBaseType,
     188             :                          std::unique_ptr<GDALRasterAttributeTable>);
     189             :     GDALExtendedDataType(
     190             :         const std::string &osName, size_t nTotalSize,
     191             :         std::vector<std::unique_ptr<GDALEDTComponent>> &&components);
     192             : 
     193             :     std::string m_osName{};
     194             :     GDALExtendedDataTypeClass m_eClass = GEDTC_NUMERIC;
     195             :     GDALExtendedDataTypeSubType m_eSubType = GEDTST_NONE;
     196             :     GDALDataType m_eNumericDT = GDT_Unknown;
     197             :     std::vector<std::unique_ptr<GDALEDTComponent>> m_aoComponents{};
     198             :     size_t m_nSize = 0;
     199             :     size_t m_nMaxStringLength = 0;
     200             :     std::unique_ptr<GDALRasterAttributeTable> m_poRAT{};
     201             : };
     202             : 
     203             : /* ******************************************************************** */
     204             : /*                            GDALEDTComponent                          */
     205             : /* ******************************************************************** */
     206             : 
     207             : /**
     208             :  * Class for a component of a compound extended data type.
     209             :  *
     210             :  * @since GDAL 3.1
     211             :  */
     212        9202 : class CPL_DLL GDALEDTComponent
     213             : {
     214             :   public:
     215             :     ~GDALEDTComponent();
     216             :     GDALEDTComponent(const std::string &name, size_t offset,
     217             :                      const GDALExtendedDataType &type);
     218             :     GDALEDTComponent(const GDALEDTComponent &);
     219             : 
     220             :     bool operator==(const GDALEDTComponent &) const;
     221             : 
     222             :     /** Return the name.
     223             :      *
     224             :      * This is the same as the C function GDALEDTComponentGetName().
     225             :      */
     226       10333 :     const std::string &GetName() const
     227             :     {
     228       10333 :         return m_osName;
     229             :     }
     230             : 
     231             :     /** Return the offset (in bytes) of the component in the compound data type.
     232             :      *
     233             :      * This is the same as the C function GDALEDTComponentGetOffset().
     234             :      */
     235       17475 :     size_t GetOffset() const
     236             :     {
     237       17475 :         return m_nOffset;
     238             :     }
     239             : 
     240             :     /** Return the data type of the component.
     241             :      *
     242             :      * This is the same as the C function GDALEDTComponentGetType().
     243             :      */
     244    20991768 :     const GDALExtendedDataType &GetType() const
     245             :     {
     246    20991768 :         return m_oType;
     247             :     }
     248             : 
     249             :   private:
     250             :     std::string m_osName;
     251             :     size_t m_nOffset;
     252             :     GDALExtendedDataType m_oType;
     253             : };
     254             : 
     255             : /* ******************************************************************** */
     256             : /*                            GDALIHasAttribute                         */
     257             : /* ******************************************************************** */
     258             : 
     259             : /**
     260             :  * Interface used to get a single GDALAttribute or a set of GDALAttribute
     261             :  *
     262             :  * @since GDAL 3.1
     263             :  */
     264       23914 : class CPL_DLL GDALIHasAttribute
     265             : {
     266             :   protected:
     267             :     std::shared_ptr<GDALAttribute>
     268             :     GetAttributeFromAttributes(const std::string &osName) const;
     269             : 
     270             :   public:
     271             :     virtual ~GDALIHasAttribute();
     272             : 
     273             :     virtual std::shared_ptr<GDALAttribute>
     274             :     GetAttribute(const std::string &osName) const;
     275             : 
     276             :     virtual std::vector<std::shared_ptr<GDALAttribute>>
     277             :     GetAttributes(CSLConstList papszOptions = nullptr) const;
     278             : 
     279             :     virtual std::shared_ptr<GDALAttribute>
     280             :     CreateAttribute(const std::string &osName,
     281             :                     const std::vector<GUInt64> &anDimensions,
     282             :                     const GDALExtendedDataType &oDataType,
     283             :                     CSLConstList papszOptions = nullptr);
     284             : 
     285             :     virtual bool DeleteAttribute(const std::string &osName,
     286             :                                  CSLConstList papszOptions = nullptr);
     287             : };
     288             : 
     289             : /* ******************************************************************** */
     290             : /*                               GDALGroup                              */
     291             : /* ******************************************************************** */
     292             : 
     293             : /* clang-format off */
     294             : /**
     295             :  * Class modeling a named container of GDALAttribute, GDALMDArray, OGRLayer or
     296             :  * other GDALGroup. Hence GDALGroup can describe a hierarchy of objects.
     297             :  *
     298             :  * This is based on the <a href="https://portal.opengeospatial.org/files/81716#_hdf5_group">HDF5 group
     299             :  * concept</a>
     300             :  *
     301             :  * @since GDAL 3.1
     302             :  */
     303             : /* clang-format on */
     304             : 
     305       13693 : class CPL_DLL GDALGroup : public GDALIHasAttribute
     306             : {
     307             :   protected:
     308             :     //! @cond Doxygen_Suppress
     309             :     std::string m_osName{};
     310             : 
     311             :     // This is actually a path of the form "/parent_path/{m_osName}"
     312             :     std::string m_osFullName{};
     313             : 
     314             :     // Used for example by GDALSubsetGroup to distinguish a derived group
     315             :     //from its original, without altering its name
     316             :     const std::string m_osContext{};
     317             : 
     318             :     // List of types owned by the group.
     319             :     std::vector<std::shared_ptr<GDALExtendedDataType>> m_apoTypes{};
     320             : 
     321             :     //! Weak pointer to this
     322             :     std::weak_ptr<GDALGroup> m_pSelf{};
     323             : 
     324             :     //! Can be set to false by the owing group, when deleting this object
     325             :     bool m_bValid = true;
     326             : 
     327             :     GDALGroup(const std::string &osParentName, const std::string &osName,
     328             :               const std::string &osContext = std::string());
     329             : 
     330             :     const GDALGroup *
     331             :     GetInnerMostGroup(const std::string &osPathOrArrayOrDim,
     332             :                       std::shared_ptr<GDALGroup> &curGroupHolder,
     333             :                       std::string &osLastPart) const;
     334             : 
     335             :     void BaseRename(const std::string &osNewName);
     336             : 
     337             :     bool CheckValidAndErrorOutIfNot() const;
     338             : 
     339       12747 :     void SetSelf(const std::shared_ptr<GDALGroup> &self)
     340             :     {
     341       12747 :         m_pSelf = self;
     342       12747 :     }
     343             : 
     344           0 :     virtual void NotifyChildrenOfRenaming()
     345             :     {
     346           0 :     }
     347             : 
     348           0 :     virtual void NotifyChildrenOfDeletion()
     349             :     {
     350           0 :     }
     351             : 
     352             :     //! @endcond
     353             : 
     354             :   public:
     355             :     ~GDALGroup() override;
     356             : 
     357             :     /** Return the name of the group.
     358             :      *
     359             :      * This is the same as the C function GDALGroupGetName().
     360             :      */
     361        2389 :     const std::string &GetName() const
     362             :     {
     363        2389 :         return m_osName;
     364             :     }
     365             : 
     366             :     /** Return the full name of the group.
     367             :      *
     368             :      * This is the same as the C function GDALGroupGetFullName().
     369             :      */
     370      323841 :     const std::string &GetFullName() const
     371             :     {
     372      323841 :         return m_osFullName;
     373             :     }
     374             : 
     375             :     /** Return data types associated with the group (typically enumerations)
     376             :      *
     377             :      * This is the same as the C function GDALGroupGetDataTypeCount() and GDALGroupGetDataType()
     378             :      *
     379             :      * @since 3.12
     380             :      */
     381             :     const std::vector<std::shared_ptr<GDALExtendedDataType>> &
     382          90 :     GetDataTypes() const
     383             :     {
     384          90 :         return m_apoTypes;
     385             :     }
     386             : 
     387             :     virtual std::vector<std::string>
     388             :     GetMDArrayNames(CSLConstList papszOptions = nullptr) const;
     389             :     virtual std::shared_ptr<GDALMDArray>
     390             :     OpenMDArray(const std::string &osName,
     391             :                 CSLConstList papszOptions = nullptr) const;
     392             : 
     393             :     std::vector<std::string> GetMDArrayFullNamesRecursive(
     394             :         CSLConstList papszGroupOptions = nullptr,
     395             :         CSLConstList papszArrayOptions = nullptr) const;
     396             : 
     397             :     virtual std::vector<std::string>
     398             :     GetGroupNames(CSLConstList papszOptions = nullptr) const;
     399             :     virtual std::shared_ptr<GDALGroup>
     400             :     OpenGroup(const std::string &osName,
     401             :               CSLConstList papszOptions = nullptr) const;
     402             : 
     403             :     virtual std::vector<std::string>
     404             :     GetVectorLayerNames(CSLConstList papszOptions = nullptr) const;
     405             :     virtual OGRLayer *
     406             :     OpenVectorLayer(const std::string &osName,
     407             :                     CSLConstList papszOptions = nullptr) const;
     408             : 
     409             :     virtual std::vector<std::shared_ptr<GDALDimension>>
     410             :     GetDimensions(CSLConstList papszOptions = nullptr) const;
     411             : 
     412             :     virtual std::shared_ptr<GDALGroup>
     413             :     CreateGroup(const std::string &osName, CSLConstList papszOptions = nullptr);
     414             : 
     415             :     virtual bool DeleteGroup(const std::string &osName,
     416             :                              CSLConstList papszOptions = nullptr);
     417             : 
     418             :     virtual std::shared_ptr<GDALDimension>
     419             :     CreateDimension(const std::string &osName, const std::string &osType,
     420             :                     const std::string &osDirection, GUInt64 nSize,
     421             :                     CSLConstList papszOptions = nullptr);
     422             : 
     423             :     virtual std::shared_ptr<GDALMDArray> CreateMDArray(
     424             :         const std::string &osName,
     425             :         const std::vector<std::shared_ptr<GDALDimension>> &aoDimensions,
     426             :         const GDALExtendedDataType &oDataType,
     427             :         CSLConstList papszOptions = nullptr);
     428             : 
     429             :     virtual bool DeleteMDArray(const std::string &osName,
     430             :                                CSLConstList papszOptions = nullptr);
     431             : 
     432             :     GUInt64 GetTotalCopyCost() const;
     433             : 
     434             :     virtual bool CopyFrom(const std::shared_ptr<GDALGroup> &poDstRootGroup,
     435             :                           GDALDataset *poSrcDS,
     436             :                           const std::shared_ptr<GDALGroup> &poSrcGroup,
     437             :                           bool bStrict, GUInt64 &nCurCost,
     438             :                           const GUInt64 nTotalCost,
     439             :                           GDALProgressFunc pfnProgress, void *pProgressData,
     440             :                           CSLConstList papszOptions = nullptr);
     441             : 
     442             :     virtual CSLConstList GetStructuralInfo() const;
     443             : 
     444             :     std::shared_ptr<GDALMDArray>
     445             :     OpenMDArrayFromFullname(const std::string &osFullName,
     446             :                             CSLConstList papszOptions = nullptr) const;
     447             : 
     448             :     std::shared_ptr<GDALAttribute>
     449             :     OpenAttributeFromFullname(const std::string &osFullName,
     450             :                               CSLConstList papszOptions = nullptr) const;
     451             : 
     452             :     std::shared_ptr<GDALMDArray>
     453             :     ResolveMDArray(const std::string &osName, const std::string &osStartingPath,
     454             :                    CSLConstList papszOptions = nullptr) const;
     455             : 
     456             :     std::shared_ptr<GDALGroup>
     457             :     OpenGroupFromFullname(const std::string &osFullName,
     458             :                           CSLConstList papszOptions = nullptr) const;
     459             : 
     460             :     std::shared_ptr<GDALDimension>
     461             :     OpenDimensionFromFullname(const std::string &osFullName) const;
     462             : 
     463             :     virtual void ClearStatistics();
     464             : 
     465             :     virtual bool Rename(const std::string &osNewName);
     466             : 
     467             :     std::shared_ptr<GDALGroup>
     468             :     SubsetDimensionFromSelection(const std::string &osSelection) const;
     469             : 
     470             :     void RecursivelyVisitArrays(
     471             :         std::function<void(const std::shared_ptr<GDALMDArray> &)> visitor);
     472             : 
     473             :     //! @cond Doxygen_Suppress
     474             :     virtual void ParentRenamed(const std::string &osNewParentFullName);
     475             : 
     476             :     virtual void Deleted();
     477             : 
     478             :     virtual void ParentDeleted();
     479             : 
     480          23 :     const std::string &GetContext() const
     481             :     {
     482          23 :         return m_osContext;
     483             :     }
     484             : 
     485             :     //! @endcond
     486             : 
     487             :     //! @cond Doxygen_Suppress
     488             :     static constexpr GUInt64 COPY_COST = 1000;
     489             :     //! @endcond
     490             : };
     491             : 
     492             : /* ******************************************************************** */
     493             : /*                          GDALAbstractMDArray                         */
     494             : /* ******************************************************************** */
     495             : 
     496             : /**
     497             :  * Abstract class, implemented by GDALAttribute and GDALMDArray.
     498             :  *
     499             :  * @since GDAL 3.1
     500             :  */
     501      172529 : class CPL_DLL GDALAbstractMDArray
     502             : {
     503             :   protected:
     504             :     //! @cond Doxygen_Suppress
     505             :     std::string m_osName{};
     506             : 
     507             :     // This is actually a path of the form "/parent_path/{m_osName}"
     508             :     std::string m_osFullName{};
     509             :     std::weak_ptr<GDALAbstractMDArray> m_pSelf{};
     510             : 
     511             :     //! Can be set to false by the owing object, when deleting this object
     512             :     bool m_bValid = true;
     513             : 
     514             :     GDALAbstractMDArray(const std::string &osParentName,
     515             :                         const std::string &osName);
     516             : 
     517       13261 :     void SetSelf(const std::shared_ptr<GDALAbstractMDArray> &self)
     518             :     {
     519       13261 :         m_pSelf = self;
     520       13261 :     }
     521             : 
     522             :     bool CheckValidAndErrorOutIfNot() const;
     523             : 
     524             :     bool CheckReadWriteParams(const GUInt64 *arrayStartIdx, const size_t *count,
     525             :                               const GInt64 *&arrayStep,
     526             :                               const GPtrDiff_t *&bufferStride,
     527             :                               const GDALExtendedDataType &bufferDataType,
     528             :                               const void *buffer,
     529             :                               const void *buffer_alloc_start,
     530             :                               size_t buffer_alloc_size,
     531             :                               std::vector<GInt64> &tmp_arrayStep,
     532             :                               std::vector<GPtrDiff_t> &tmp_bufferStride) const;
     533             : 
     534             :     virtual bool
     535             :     IRead(const GUInt64 *arrayStartIdx,    // array of size GetDimensionCount()
     536             :           const size_t *count,             // array of size GetDimensionCount()
     537             :           const GInt64 *arrayStep,         // step in elements
     538             :           const GPtrDiff_t *bufferStride,  // stride in elements
     539             :           const GDALExtendedDataType &bufferDataType,
     540             :           void *pDstBuffer) const = 0;
     541             : 
     542             :     virtual bool
     543             :     IWrite(const GUInt64 *arrayStartIdx,    // array of size GetDimensionCount()
     544             :            const size_t *count,             // array of size GetDimensionCount()
     545             :            const GInt64 *arrayStep,         // step in elements
     546             :            const GPtrDiff_t *bufferStride,  // stride in elements
     547             :            const GDALExtendedDataType &bufferDataType, const void *pSrcBuffer);
     548             : 
     549             :     void BaseRename(const std::string &osNewName);
     550             : 
     551          47 :     virtual void NotifyChildrenOfRenaming()
     552             :     {
     553          47 :     }
     554             : 
     555          46 :     virtual void NotifyChildrenOfDeletion()
     556             :     {
     557          46 :     }
     558             : 
     559             :     //! @endcond
     560             : 
     561             :   public:
     562             :     virtual ~GDALAbstractMDArray();
     563             : 
     564             :     /** Return the name of an array or attribute.
     565             :      *
     566             :      * This is the same as the C function GDALMDArrayGetName() or
     567             :      * GDALAttributeGetName().
     568             :      */
     569      112402 :     const std::string &GetName() const
     570             :     {
     571      112402 :         return m_osName;
     572             :     }
     573             : 
     574             :     /** Return the name of an array or attribute.
     575             :      *
     576             :      * This is the same as the C function GDALMDArrayGetFullName() or
     577             :      * GDALAttributeGetFullName().
     578             :      */
     579       20392 :     const std::string &GetFullName() const
     580             :     {
     581       20392 :         return m_osFullName;
     582             :     }
     583             : 
     584             :     GUInt64 GetTotalElementsCount() const;
     585             : 
     586             :     virtual size_t GetDimensionCount() const;
     587             : 
     588             :     virtual const std::vector<std::shared_ptr<GDALDimension>> &
     589             :     GetDimensions() const = 0;
     590             : 
     591             :     virtual const GDALExtendedDataType &GetDataType() const = 0;
     592             : 
     593             :     virtual std::vector<GUInt64> GetBlockSize() const;
     594             : 
     595             :     virtual std::vector<size_t>
     596             :     GetProcessingChunkSize(size_t nMaxChunkMemory) const;
     597             : 
     598             :     /* clang-format off */
     599             :     /** Type of pfnFunc argument of ProcessPerChunk().
     600             :      * @param array Array on which ProcessPerChunk was called.
     601             :      * @param chunkArrayStartIdx Values representing the starting index to use
     602             :      *                           in each dimension (in [0, aoDims[i].GetSize()-1] range)
     603             :      *                           for the current chunk.
     604             :      *                           Will be nullptr for a zero-dimensional array.
     605             :      * @param chunkCount         Values representing the number of values to use in
     606             :      *                           each dimension for the current chunk.
     607             :      *                           Will be nullptr for a zero-dimensional array.
     608             :      * @param iCurChunk          Number of current chunk being processed.
     609             :      *                           In [1, nChunkCount] range.
     610             :      * @param nChunkCount        Total number of chunks to process.
     611             :      * @param pUserData          User data.
     612             :      * @return return true in case of success.
     613             :      */
     614             :     typedef bool (*FuncProcessPerChunkType)(
     615             :                         GDALAbstractMDArray *array,
     616             :                         const GUInt64 *chunkArrayStartIdx,
     617             :                         const size_t *chunkCount,
     618             :                         GUInt64 iCurChunk,
     619             :                         GUInt64 nChunkCount,
     620             :                         void *pUserData);
     621             :     /* clang-format on */
     622             : 
     623             :     virtual bool ProcessPerChunk(const GUInt64 *arrayStartIdx,
     624             :                                  const GUInt64 *count, const size_t *chunkSize,
     625             :                                  FuncProcessPerChunkType pfnFunc,
     626             :                                  void *pUserData);
     627             : 
     628             :     virtual bool
     629             :     Read(const GUInt64 *arrayStartIdx,    // array of size GetDimensionCount()
     630             :          const size_t *count,             // array of size GetDimensionCount()
     631             :          const GInt64 *arrayStep,         // step in elements
     632             :          const GPtrDiff_t *bufferStride,  // stride in elements
     633             :          const GDALExtendedDataType &bufferDataType, void *pDstBuffer,
     634             :          const void *pDstBufferAllocStart = nullptr,
     635             :          size_t nDstBufferAllocSize = 0) const;
     636             : 
     637             :     bool
     638             :     Write(const GUInt64 *arrayStartIdx,    // array of size GetDimensionCount()
     639             :           const size_t *count,             // array of size GetDimensionCount()
     640             :           const GInt64 *arrayStep,         // step in elements
     641             :           const GPtrDiff_t *bufferStride,  // stride in elements
     642             :           const GDALExtendedDataType &bufferDataType, const void *pSrcBuffer,
     643             :           const void *pSrcBufferAllocStart = nullptr,
     644             :           size_t nSrcBufferAllocSize = 0);
     645             : 
     646             :     virtual bool Rename(const std::string &osNewName);
     647             : 
     648             :     //! @cond Doxygen_Suppress
     649             :     virtual void Deleted();
     650             : 
     651             :     virtual void ParentDeleted();
     652             : 
     653             :     virtual void ParentRenamed(const std::string &osNewParentFullName);
     654             :     //! @endcond
     655             : };
     656             : 
     657             : /* ******************************************************************** */
     658             : /*                              GDALRawResult                           */
     659             : /* ******************************************************************** */
     660             : 
     661             : /**
     662             :  * Store the raw result of an attribute value, which might contain dynamically
     663             :  * allocated structures (like pointer to strings).
     664             :  *
     665             :  * @since GDAL 3.1
     666             :  */
     667             : class CPL_DLL GDALRawResult
     668             : {
     669             :   private:
     670             :     GDALExtendedDataType m_dt;
     671             :     size_t m_nEltCount;
     672             :     size_t m_nSize;
     673             :     GByte *m_raw;
     674             : 
     675             :     void FreeMe();
     676             : 
     677             :     GDALRawResult(const GDALRawResult &) = delete;
     678             :     GDALRawResult &operator=(const GDALRawResult &) = delete;
     679             : 
     680             :   protected:
     681             :     friend class GDALAttribute;
     682             :     //! @cond Doxygen_Suppress
     683             :     GDALRawResult(GByte *raw, const GDALExtendedDataType &dt, size_t nEltCount);
     684             :     //! @endcond
     685             : 
     686             :   public:
     687             :     ~GDALRawResult();
     688             :     GDALRawResult(GDALRawResult &&);
     689             :     GDALRawResult &operator=(GDALRawResult &&);
     690             : 
     691             :     /** Return byte at specified index. */
     692             :     const GByte &operator[](size_t idx) const
     693             :     {
     694             :         return m_raw[idx];
     695             :     }
     696             : 
     697             :     /** Return pointer to the start of data. */
     698         524 :     const GByte *data() const
     699             :     {
     700         524 :         return m_raw;
     701             :     }
     702             : 
     703             :     /** Return the size in bytes of the raw result. */
     704         227 :     size_t size() const
     705             :     {
     706         227 :         return m_nSize;
     707             :     }
     708             : 
     709             :     //! @cond Doxygen_Suppress
     710             :     GByte *StealData();
     711             :     //! @endcond
     712             : };
     713             : 
     714             : /* ******************************************************************** */
     715             : /*                              GDALAttribute                           */
     716             : /* ******************************************************************** */
     717             : 
     718             : /* clang-format off */
     719             : /**
     720             :  * Class modeling an attribute that has a name, a value and a type, and is
     721             :  * typically used to describe a metadata item. The value can be (for the
     722             :  * HDF5 format) in the general case a multidimensional array of "any" type
     723             :  * (in most cases, this will be a single value of string or numeric type)
     724             :  *
     725             :  * This is based on the <a href="https://portal.opengeospatial.org/files/81716#_hdf5_attribute">HDF5
     726             :  * attribute concept</a>
     727             :  *
     728             :  * @since GDAL 3.1
     729             :  */
     730             : /* clang-format on */
     731             : 
     732      162308 : class CPL_DLL GDALAttribute : virtual public GDALAbstractMDArray
     733             : {
     734             :     mutable std::string m_osCachedVal{};
     735             : 
     736             :   protected:
     737             :     //! @cond Doxygen_Suppress
     738             :     GDALAttribute(const std::string &osParentName, const std::string &osName);
     739             :     //! @endcond
     740             : 
     741             :   public:
     742             :     //! @cond Doxygen_Suppress
     743             :     ~GDALAttribute() override;
     744             :     //! @endcond
     745             : 
     746             :     std::vector<GUInt64> GetDimensionsSize() const;
     747             : 
     748             :     GDALRawResult ReadAsRaw() const;
     749             :     const char *ReadAsString() const;
     750             :     int ReadAsInt() const;
     751             :     int64_t ReadAsInt64() const;
     752             :     double ReadAsDouble() const;
     753             :     CPLStringList ReadAsStringArray() const;
     754             :     std::vector<int> ReadAsIntArray() const;
     755             :     std::vector<int64_t> ReadAsInt64Array() const;
     756             :     std::vector<double> ReadAsDoubleArray() const;
     757             : 
     758             :     using GDALAbstractMDArray::Write;
     759             :     bool Write(const void *pabyValue, size_t nLen);
     760             :     bool Write(const char *);
     761             :     bool WriteInt(int);
     762             :     bool WriteInt64(int64_t);
     763             :     bool Write(double);
     764             :     bool Write(CSLConstList);
     765             :     bool Write(const int *, size_t);
     766             :     bool Write(const int64_t *, size_t);
     767             :     bool Write(const double *, size_t);
     768             : 
     769             :     //! @cond Doxygen_Suppress
     770             :     static constexpr GUInt64 COPY_COST = 100;
     771             :     //! @endcond
     772             : };
     773             : 
     774             : /************************************************************************/
     775             : /*                         GDALAttributeString                          */
     776             : /************************************************************************/
     777             : 
     778             : //! @cond Doxygen_Suppress
     779             : class CPL_DLL GDALAttributeString final : public GDALAttribute
     780             : {
     781             :     std::vector<std::shared_ptr<GDALDimension>> m_dims{};
     782             :     GDALExtendedDataType m_dt = GDALExtendedDataType::CreateString();
     783             :     std::string m_osValue;
     784             : 
     785             :   protected:
     786             :     bool IRead(const GUInt64 *, const size_t *, const GInt64 *,
     787             :                const GPtrDiff_t *, const GDALExtendedDataType &bufferDataType,
     788             :                void *pDstBuffer) const override;
     789             : 
     790             :   public:
     791             :     GDALAttributeString(const std::string &osParentName,
     792             :                         const std::string &osName, const std::string &osValue,
     793             :                         GDALExtendedDataTypeSubType eSubType = GEDTST_NONE);
     794             : 
     795             :     const std::vector<std::shared_ptr<GDALDimension>> &
     796             :     GetDimensions() const override;
     797             : 
     798             :     const GDALExtendedDataType &GetDataType() const override;
     799             : };
     800             : 
     801             : //! @endcond
     802             : 
     803             : /************************************************************************/
     804             : /*                         GDALAttributeNumeric                         */
     805             : /************************************************************************/
     806             : 
     807             : //! @cond Doxygen_Suppress
     808             : class CPL_DLL GDALAttributeNumeric final : public GDALAttribute
     809             : {
     810             :     std::vector<std::shared_ptr<GDALDimension>> m_dims{};
     811             :     GDALExtendedDataType m_dt;
     812             :     int m_nValue = 0;
     813             :     double m_dfValue = 0;
     814             :     std::vector<GUInt32> m_anValuesUInt32{};
     815             : 
     816             :   protected:
     817             :     bool IRead(const GUInt64 *, const size_t *, const GInt64 *,
     818             :                const GPtrDiff_t *, const GDALExtendedDataType &bufferDataType,
     819             :                void *pDstBuffer) const override;
     820             : 
     821             :   public:
     822             :     GDALAttributeNumeric(const std::string &osParentName,
     823             :                          const std::string &osName, double dfValue);
     824             :     GDALAttributeNumeric(const std::string &osParentName,
     825             :                          const std::string &osName, int nValue);
     826             :     GDALAttributeNumeric(const std::string &osParentName,
     827             :                          const std::string &osName,
     828             :                          const std::vector<GUInt32> &anValues);
     829             : 
     830             :     const std::vector<std::shared_ptr<GDALDimension>> &
     831             :     GetDimensions() const override;
     832             : 
     833             :     const GDALExtendedDataType &GetDataType() const override;
     834             : };
     835             : 
     836             : //! @endcond
     837             : 
     838             : /* ******************************************************************** */
     839             : /*                              GDALMDArray                             */
     840             : /* ******************************************************************** */
     841             : 
     842             : /* clang-format off */
     843             : /**
     844             :  * Class modeling a multi-dimensional array. It has a name, values organized
     845             :  * as an array and a list of GDALAttribute.
     846             :  *
     847             :  * This is based on the <a href="https://portal.opengeospatial.org/files/81716#_hdf5_dataset">HDF5
     848             :  * dataset concept</a>
     849             :  *
     850             :  * @since GDAL 3.1
     851             :  */
     852             : /* clang-format on */
     853             : 
     854             : class CPL_DLL GDALMDArray : virtual public GDALAbstractMDArray,
     855             :                             public GDALIHasAttribute
     856             : {
     857             :     friend class GDALMDArrayResampled;
     858             :     std::shared_ptr<GDALMDArray>
     859             :     GetView(const std::vector<GUInt64> &indices) const;
     860             : 
     861             :     inline std::shared_ptr<GDALMDArray>
     862          19 :     atInternal(const std::vector<GUInt64> &indices) const
     863             :     {
     864          19 :         return GetView(indices);
     865             :     }
     866             : 
     867             :     template <typename... GUInt64VarArg>
     868             :     // cppcheck-suppress functionStatic
     869             :     inline std::shared_ptr<GDALMDArray>
     870           7 :     atInternal(std::vector<GUInt64> &indices, GUInt64 idx,
     871             :                GUInt64VarArg... tail) const
     872             :     {
     873           7 :         indices.push_back(idx);
     874           7 :         return atInternal(indices, tail...);
     875             :     }
     876             : 
     877             :     // Used for example by GDALSubsetGroup to distinguish a derived group
     878             :     //from its original, without altering its name
     879             :     const std::string m_osContext{};
     880             : 
     881             :     mutable bool m_bHasTriedCachedArray = false;
     882             :     mutable std::shared_ptr<GDALMDArray> m_poCachedArray{};
     883             : 
     884             :   protected:
     885             :     //! @cond Doxygen_Suppress
     886             :     GDALMDArray(const std::string &osParentName, const std::string &osName,
     887             :                 const std::string &osContext = std::string());
     888             : 
     889             :     virtual bool IAdviseRead(const GUInt64 *arrayStartIdx, const size_t *count,
     890             :                              CSLConstList papszOptions) const;
     891             : 
     892        3506 :     virtual bool IsCacheable() const
     893             :     {
     894        3506 :         return true;
     895             :     }
     896             : 
     897             :     virtual bool SetStatistics(bool bApproxStats, double dfMin, double dfMax,
     898             :                                double dfMean, double dfStdDev,
     899             :                                GUInt64 nValidCount, CSLConstList papszOptions);
     900             : 
     901             :     static std::string MassageName(const std::string &inputName);
     902             : 
     903             :     std::shared_ptr<GDALGroup>
     904             :     GetCacheRootGroup(bool bCanCreate, std::string &osCacheFilenameOut) const;
     905             : 
     906             :     // Returns if bufferStride values express a transposed view of the array
     907             :     bool IsTransposedRequest(const size_t *count,
     908             :                              const GPtrDiff_t *bufferStride) const;
     909             : 
     910             :     // Should only be called if IsTransposedRequest() returns true
     911             :     bool ReadForTransposedRequest(const GUInt64 *arrayStartIdx,
     912             :                                   const size_t *count, const GInt64 *arrayStep,
     913             :                                   const GPtrDiff_t *bufferStride,
     914             :                                   const GDALExtendedDataType &bufferDataType,
     915             :                                   void *pDstBuffer) const;
     916             : 
     917             :     bool IsStepOneContiguousRowMajorOrderedSameDataType(
     918             :         const size_t *count, const GInt64 *arrayStep,
     919             :         const GPtrDiff_t *bufferStride,
     920             :         const GDALExtendedDataType &bufferDataType) const;
     921             : 
     922             :     // Should only be called if IsStepOneContiguousRowMajorOrderedSameDataType()
     923             :     // returns false
     924             :     bool ReadUsingContiguousIRead(const GUInt64 *arrayStartIdx,
     925             :                                   const size_t *count, const GInt64 *arrayStep,
     926             :                                   const GPtrDiff_t *bufferStride,
     927             :                                   const GDALExtendedDataType &bufferDataType,
     928             :                                   void *pDstBuffer) const;
     929             : 
     930             :     static std::shared_ptr<GDALMDArray> CreateGLTOrthorectified(
     931             :         const std::shared_ptr<GDALMDArray> &poParent,
     932             :         const std::shared_ptr<GDALGroup> &poRootGroup,
     933             :         const std::shared_ptr<GDALMDArray> &poGLTX,
     934             :         const std::shared_ptr<GDALMDArray> &poGLTY, int nGLTIndexOffset,
     935             :         const std::vector<double> &adfGeoTransform, CSLConstList papszOptions);
     936             : 
     937             :     //! @endcond
     938             : 
     939             :   public:
     940             :     GUInt64 GetTotalCopyCost() const;
     941             : 
     942             :     virtual bool CopyFrom(GDALDataset *poSrcDS, const GDALMDArray *poSrcArray,
     943             :                           bool bStrict, GUInt64 &nCurCost,
     944             :                           const GUInt64 nTotalCost,
     945             :                           GDALProgressFunc pfnProgress, void *pProgressData);
     946             : 
     947             :     /** Return whether an array is writable. */
     948             :     virtual bool IsWritable() const = 0;
     949             : 
     950             :     /** Return the filename that contains that array.
     951             :      *
     952             :      * This is used in particular for caching.
     953             :      *
     954             :      * Might be empty if the array is not linked to a file.
     955             :      *
     956             :      * @since GDAL 3.4
     957             :      */
     958             :     virtual const std::string &GetFilename() const = 0;
     959             : 
     960             :     virtual CSLConstList GetStructuralInfo() const;
     961             : 
     962             :     virtual const std::string &GetUnit() const;
     963             : 
     964             :     virtual bool SetUnit(const std::string &osUnit);
     965             : 
     966             :     virtual bool SetSpatialRef(const OGRSpatialReference *poSRS);
     967             : 
     968             :     virtual std::shared_ptr<OGRSpatialReference> GetSpatialRef() const;
     969             : 
     970             :     virtual const void *GetRawNoDataValue() const;
     971             : 
     972             :     double GetNoDataValueAsDouble(bool *pbHasNoData = nullptr) const;
     973             : 
     974             :     int64_t GetNoDataValueAsInt64(bool *pbHasNoData = nullptr) const;
     975             : 
     976             :     uint64_t GetNoDataValueAsUInt64(bool *pbHasNoData = nullptr) const;
     977             : 
     978             :     virtual bool SetRawNoDataValue(const void *pRawNoData);
     979             : 
     980             :     //! @cond Doxygen_Suppress
     981           5 :     bool SetNoDataValue(int nNoData)
     982             :     {
     983           5 :         return SetNoDataValue(static_cast<int64_t>(nNoData));
     984             :     }
     985             : 
     986             :     //! @endcond
     987             : 
     988             :     bool SetNoDataValue(double dfNoData);
     989             : 
     990             :     bool SetNoDataValue(int64_t nNoData);
     991             : 
     992             :     bool SetNoDataValue(uint64_t nNoData);
     993             : 
     994             :     virtual bool Resize(const std::vector<GUInt64> &anNewDimSizes,
     995             :                         CSLConstList papszOptions);
     996             : 
     997             :     virtual double GetOffset(bool *pbHasOffset = nullptr,
     998             :                              GDALDataType *peStorageType = nullptr) const;
     999             : 
    1000             :     virtual double GetScale(bool *pbHasScale = nullptr,
    1001             :                             GDALDataType *peStorageType = nullptr) const;
    1002             : 
    1003             :     virtual bool SetOffset(double dfOffset,
    1004             :                            GDALDataType eStorageType = GDT_Unknown);
    1005             : 
    1006             :     virtual bool SetScale(double dfScale,
    1007             :                           GDALDataType eStorageType = GDT_Unknown);
    1008             : 
    1009             :     std::shared_ptr<GDALMDArray> GetView(const std::string &viewExpr) const;
    1010             : 
    1011             :     std::shared_ptr<GDALMDArray> operator[](const std::string &fieldName) const;
    1012             : 
    1013             :     /** Return a view of the array using integer indexing.
    1014             :      *
    1015             :      * Equivalent of GetView("[indices_0,indices_1,.....,indices_last]")
    1016             :      *
    1017             :      * Example:
    1018             :      * \code
    1019             :      * ar->at(0,3,2)
    1020             :      * \endcode
    1021             :      */
    1022             :     // sphinx 4.1.0 / breathe 4.30.0 don't like typename...
    1023             :     //! @cond Doxygen_Suppress
    1024             :     template <typename... GUInt64VarArg>
    1025             :     //! @endcond
    1026             :     // cppcheck-suppress functionStatic
    1027          19 :     std::shared_ptr<GDALMDArray> at(GUInt64 idx, GUInt64VarArg... tail) const
    1028             :     {
    1029          38 :         std::vector<GUInt64> indices;
    1030          19 :         indices.push_back(idx);
    1031          38 :         return atInternal(indices, tail...);
    1032             :     }
    1033             : 
    1034             :     virtual std::shared_ptr<GDALMDArray>
    1035             :     Transpose(const std::vector<int> &anMapNewAxisToOldAxis) const;
    1036             : 
    1037             :     std::shared_ptr<GDALMDArray> GetUnscaled(
    1038             :         double dfOverriddenScale = std::numeric_limits<double>::quiet_NaN(),
    1039             :         double dfOverriddenOffset = std::numeric_limits<double>::quiet_NaN(),
    1040             :         double dfOverriddenDstNodata =
    1041             :             std::numeric_limits<double>::quiet_NaN()) const;
    1042             : 
    1043             :     virtual std::shared_ptr<GDALMDArray>
    1044             :     GetMask(CSLConstList papszOptions) const;
    1045             : 
    1046             :     virtual std::shared_ptr<GDALMDArray>
    1047             :     GetResampled(const std::vector<std::shared_ptr<GDALDimension>> &apoNewDims,
    1048             :                  GDALRIOResampleAlg resampleAlg,
    1049             :                  const OGRSpatialReference *poTargetSRS,
    1050             :                  CSLConstList papszOptions) const;
    1051             : 
    1052             :     std::shared_ptr<GDALMDArray>
    1053             :     GetGridded(const std::string &osGridOptions,
    1054             :                const std::shared_ptr<GDALMDArray> &poXArray = nullptr,
    1055             :                const std::shared_ptr<GDALMDArray> &poYArray = nullptr,
    1056             :                CSLConstList papszOptions = nullptr) const;
    1057             : 
    1058             :     static std::vector<std::shared_ptr<GDALMDArray>>
    1059             :     GetMeshGrid(const std::vector<std::shared_ptr<GDALMDArray>> &apoArrays,
    1060             :                 CSLConstList papszOptions = nullptr);
    1061             : 
    1062             :     virtual GDALDataset *
    1063             :     AsClassicDataset(size_t iXDim, size_t iYDim,
    1064             :                      const std::shared_ptr<GDALGroup> &poRootGroup = nullptr,
    1065             :                      CSLConstList papszOptions = nullptr) const;
    1066             : 
    1067             :     virtual CPLErr GetStatistics(bool bApproxOK, bool bForce, double *pdfMin,
    1068             :                                  double *pdfMax, double *pdfMean,
    1069             :                                  double *padfStdDev, GUInt64 *pnValidCount,
    1070             :                                  GDALProgressFunc pfnProgress,
    1071             :                                  void *pProgressData);
    1072             : 
    1073             :     virtual bool ComputeStatistics(bool bApproxOK, double *pdfMin,
    1074             :                                    double *pdfMax, double *pdfMean,
    1075             :                                    double *pdfStdDev, GUInt64 *pnValidCount,
    1076             :                                    GDALProgressFunc, void *pProgressData,
    1077             :                                    CSLConstList papszOptions);
    1078             : 
    1079             :     virtual void ClearStatistics();
    1080             : 
    1081             :     virtual std::vector<std::shared_ptr<GDALMDArray>>
    1082             :     GetCoordinateVariables() const;
    1083             : 
    1084             :     bool AdviseRead(const GUInt64 *arrayStartIdx, const size_t *count,
    1085             :                     CSLConstList papszOptions = nullptr) const;
    1086             : 
    1087             :     virtual bool IsRegularlySpaced(double &dfStart, double &dfIncrement) const;
    1088             : 
    1089             :     bool GuessGeoTransform(size_t nDimX, size_t nDimY, bool bPixelIsPoint,
    1090             :                            GDALGeoTransform &gt) const;
    1091             : 
    1092             :     bool GuessGeoTransform(size_t nDimX, size_t nDimY, bool bPixelIsPoint,
    1093             :                            double adfGeoTransform[6]) const;
    1094             : 
    1095             :     bool Cache(CSLConstList papszOptions = nullptr) const;
    1096             : 
    1097             :     bool
    1098             :     Read(const GUInt64 *arrayStartIdx,    // array of size GetDimensionCount()
    1099             :          const size_t *count,             // array of size GetDimensionCount()
    1100             :          const GInt64 *arrayStep,         // step in elements
    1101             :          const GPtrDiff_t *bufferStride,  // stride in elements
    1102             :          const GDALExtendedDataType &bufferDataType, void *pDstBuffer,
    1103             :          const void *pDstBufferAllocStart = nullptr,
    1104             :          size_t nDstBufferAllocSize = 0) const override final;
    1105             : 
    1106             :     virtual std::shared_ptr<GDALGroup> GetRootGroup() const;
    1107             : 
    1108             :     virtual bool GetRawBlockInfo(const uint64_t *panBlockCoordinates,
    1109             :                                  GDALMDArrayRawBlockInfo &info) const;
    1110             : 
    1111             :     virtual int GetOverviewCount() const;
    1112             : 
    1113             :     virtual std::shared_ptr<GDALMDArray> GetOverview(int idx) const;
    1114             : 
    1115             :     virtual CPLErr BuildOverviews(const char *pszResampling, int nOverviews,
    1116             :                                   const int *panOverviewList,
    1117             :                                   GDALProgressFunc pfnProgress,
    1118             :                                   void *pProgressData,
    1119             :                                   CSLConstList papszOptions);
    1120             : 
    1121             :     //! @cond Doxygen_Suppress
    1122             :     static constexpr GUInt64 COPY_COST = 1000;
    1123             : 
    1124             :     bool CopyFromAllExceptValues(const GDALMDArray *poSrcArray, bool bStrict,
    1125             :                                  GUInt64 &nCurCost, const GUInt64 nTotalCost,
    1126             :                                  GDALProgressFunc pfnProgress,
    1127             :                                  void *pProgressData);
    1128             : 
    1129             :     struct Range
    1130             :     {
    1131             :         GUInt64 m_nStartIdx;
    1132             :         GInt64 m_nIncr;
    1133             : 
    1134        1602 :         explicit Range(GUInt64 nStartIdx = 0, GInt64 nIncr = 0)
    1135        1602 :             : m_nStartIdx(nStartIdx), m_nIncr(nIncr)
    1136             :         {
    1137        1602 :         }
    1138             :     };
    1139             : 
    1140             :     struct ViewSpec
    1141             :     {
    1142             :         std::string m_osFieldName{};
    1143             : 
    1144             :         // or
    1145             : 
    1146             :         std::vector<size_t>
    1147             :             m_mapDimIdxToParentDimIdx{};  // of size m_dims.size()
    1148             :         std::vector<Range>
    1149             :             m_parentRanges{};  // of size m_poParent->GetDimensionCount()
    1150             :     };
    1151             : 
    1152             :     virtual std::shared_ptr<GDALMDArray>
    1153             :     GetView(const std::string &viewExpr, bool bRenameDimensions,
    1154             :             std::vector<ViewSpec> &viewSpecs) const;
    1155             : 
    1156        2070 :     const std::string &GetContext() const
    1157             :     {
    1158        2070 :         return m_osContext;
    1159             :     }
    1160             : 
    1161             :     //! @endcond
    1162             : };
    1163             : 
    1164             : //! @cond Doxygen_Suppress
    1165             : bool CPL_DLL GDALMDRasterIOFromBand(
    1166             :     GDALRasterBand *poBand, GDALRWFlag eRWFlag, size_t iDimX, size_t iDimY,
    1167             :     const GUInt64 *arrayStartIdx, const size_t *count, const GInt64 *arrayStep,
    1168             :     const GPtrDiff_t *bufferStride, const GDALExtendedDataType &bufferDataType,
    1169             :     void *pBuffer);
    1170             : 
    1171             : //! @endcond
    1172             : 
    1173             : /************************************************************************/
    1174             : /*                      GDALMDArrayRegularlySpaced                      */
    1175             : /************************************************************************/
    1176             : 
    1177             : //! @cond Doxygen_Suppress
    1178             : class CPL_DLL GDALMDArrayRegularlySpaced final : public GDALMDArray
    1179             : {
    1180             :     double m_dfStart = 0;
    1181             :     double m_dfIncrement = 0;
    1182             :     double m_dfOffsetInIncrement = 0;
    1183             :     const GDALExtendedDataType m_dt = GDALExtendedDataType::Create(GDT_Float64);
    1184             :     const std::vector<std::shared_ptr<GDALDimension>> m_dims;
    1185             :     std::vector<std::shared_ptr<GDALAttribute>> m_attributes{};
    1186             :     const std::string m_osEmptyFilename{};
    1187             : 
    1188             :   protected:
    1189             :     bool IRead(const GUInt64 *, const size_t *, const GInt64 *,
    1190             :                const GPtrDiff_t *, const GDALExtendedDataType &bufferDataType,
    1191             :                void *pDstBuffer) const override;
    1192             : 
    1193             :   public:
    1194             :     GDALMDArrayRegularlySpaced(const std::string &osParentName,
    1195             :                                const std::string &osName,
    1196             :                                const std::shared_ptr<GDALDimension> &poDim,
    1197             :                                double dfStart, double dfIncrement,
    1198             :                                double dfOffsetInIncrement);
    1199             : 
    1200             :     static std::shared_ptr<GDALMDArrayRegularlySpaced>
    1201             :     Create(const std::string &osParentName, const std::string &osName,
    1202             :            const std::shared_ptr<GDALDimension> &poDim, double dfStart,
    1203             :            double dfIncrement, double dfOffsetInIncrement);
    1204             : 
    1205           0 :     bool IsWritable() const override
    1206             :     {
    1207           0 :         return false;
    1208             :     }
    1209             : 
    1210         237 :     const std::string &GetFilename() const override
    1211             :     {
    1212         237 :         return m_osEmptyFilename;
    1213             :     }
    1214             : 
    1215             :     const std::vector<std::shared_ptr<GDALDimension>> &
    1216             :     GetDimensions() const override;
    1217             : 
    1218             :     const GDALExtendedDataType &GetDataType() const override;
    1219             : 
    1220             :     std::vector<std::shared_ptr<GDALAttribute>>
    1221             :         GetAttributes(CSLConstList) const override;
    1222             : 
    1223             :     void AddAttribute(const std::shared_ptr<GDALAttribute> &poAttr);
    1224             : 
    1225             :     bool IsRegularlySpaced(double &dfStart, double &dfIncrement) const override;
    1226             : };
    1227             : 
    1228             : //! @endcond
    1229             : 
    1230             : /* ******************************************************************** */
    1231             : /*                            GDALDimension                             */
    1232             : /* ******************************************************************** */
    1233             : 
    1234             : /**
    1235             :  * Class modeling a a dimension / axis used to index multidimensional arrays.
    1236             :  * It has a name, a size (that is the number of values that can be indexed along
    1237             :  * the dimension), a type (see GDALDimension::GetType()), a direction
    1238             :  * (see GDALDimension::GetDirection()), a unit and can optionally point to a
    1239             :  * GDALMDArray variable, typically one-dimensional, describing the values taken
    1240             :  * by the dimension. For a georeferenced GDALMDArray and its X dimension, this
    1241             :  * will be typically the values of the easting/longitude for each grid point.
    1242             :  *
    1243             :  * @since GDAL 3.1
    1244             :  */
    1245       13401 : class CPL_DLL GDALDimension
    1246             : {
    1247             :   public:
    1248             :     //! @cond Doxygen_Suppress
    1249             :     GDALDimension(const std::string &osParentName, const std::string &osName,
    1250             :                   const std::string &osType, const std::string &osDirection,
    1251             :                   GUInt64 nSize);
    1252             :     //! @endcond
    1253             : 
    1254             :     virtual ~GDALDimension();
    1255             : 
    1256             :     /** Return the name.
    1257             :      *
    1258             :      * This is the same as the C function GDALDimensionGetName()
    1259             :      */
    1260       12815 :     const std::string &GetName() const
    1261             :     {
    1262       12815 :         return m_osName;
    1263             :     }
    1264             : 
    1265             :     /** Return the full name.
    1266             :      *
    1267             :      * This is the same as the C function GDALDimensionGetFullName()
    1268             :      */
    1269        1811 :     const std::string &GetFullName() const
    1270             :     {
    1271        1811 :         return m_osFullName;
    1272             :     }
    1273             : 
    1274             :     /** Return the axis type.
    1275             :      *
    1276             :      * Predefined values are:
    1277             :      * HORIZONTAL_X, HORIZONTAL_Y, VERTICAL, TEMPORAL, PARAMETRIC
    1278             :      * Other values might be returned. Empty value means unknown.
    1279             :      *
    1280             :      * This is the same as the C function GDALDimensionGetType()
    1281             :      */
    1282        2481 :     const std::string &GetType() const
    1283             :     {
    1284        2481 :         return m_osType;
    1285             :     }
    1286             : 
    1287             :     /** Return the axis direction.
    1288             :      *
    1289             :      * Predefined values are:
    1290             :      * EAST, WEST, SOUTH, NORTH, UP, DOWN, FUTURE, PAST
    1291             :      * Other values might be returned. Empty value means unknown.
    1292             :      *
    1293             :      * This is the same as the C function GDALDimensionGetDirection()
    1294             :      */
    1295        1078 :     const std::string &GetDirection() const
    1296             :     {
    1297        1078 :         return m_osDirection;
    1298             :     }
    1299             : 
    1300             :     /** Return the size, that is the number of values along the dimension.
    1301             :      *
    1302             :      * This is the same as the C function GDALDimensionGetSize()
    1303             :      */
    1304       73079 :     GUInt64 GetSize() const
    1305             :     {
    1306       73079 :         return m_nSize;
    1307             :     }
    1308             : 
    1309             :     virtual std::shared_ptr<GDALMDArray> GetIndexingVariable() const;
    1310             : 
    1311             :     virtual bool
    1312             :     SetIndexingVariable(std::shared_ptr<GDALMDArray> poIndexingVariable);
    1313             : 
    1314             :     virtual bool Rename(const std::string &osNewName);
    1315             : 
    1316             :     //! @cond Doxygen_Suppress
    1317             :     virtual void ParentRenamed(const std::string &osNewParentFullName);
    1318             : 
    1319             :     virtual void ParentDeleted();
    1320             :     //! @endcond
    1321             : 
    1322             :   protected:
    1323             :     //! @cond Doxygen_Suppress
    1324             :     std::string m_osName;
    1325             :     std::string m_osFullName;
    1326             :     std::string m_osType;
    1327             :     std::string m_osDirection;
    1328             :     GUInt64 m_nSize;
    1329             : 
    1330             :     void BaseRename(const std::string &osNewName);
    1331             : 
    1332             :     //! @endcond
    1333             : };
    1334             : 
    1335             : /************************************************************************/
    1336             : /*                    GDALDimensionWeakIndexingVar()                    */
    1337             : /************************************************************************/
    1338             : 
    1339             : //! @cond Doxygen_Suppress
    1340             : class CPL_DLL GDALDimensionWeakIndexingVar : public GDALDimension
    1341             : {
    1342             :     std::weak_ptr<GDALMDArray> m_poIndexingVariable{};
    1343             : 
    1344             :   public:
    1345             :     GDALDimensionWeakIndexingVar(const std::string &osParentName,
    1346             :                                  const std::string &osName,
    1347             :                                  const std::string &osType,
    1348             :                                  const std::string &osDirection, GUInt64 nSize);
    1349             : 
    1350             :     std::shared_ptr<GDALMDArray> GetIndexingVariable() const override;
    1351             : 
    1352             :     bool SetIndexingVariable(
    1353             :         std::shared_ptr<GDALMDArray> poIndexingVariable) override;
    1354             : 
    1355             :     void SetSize(GUInt64 nNewSize);
    1356             : };
    1357             : 
    1358             : //! @endcond
    1359             : 
    1360             : #endif

Generated by: LCOV version 1.14