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

Generated by: LCOV version 1.14