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-06-19 21:24:00 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      629604 : 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        2367 :     bool operator!=(const GDALExtendedDataType &other) const
      80             :     {
      81        2367 :         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     9663696 :     GDALExtendedDataTypeClass GetClass() const
      98             :     {
      99     9663696 :         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    15433488 :     GDALDataType GetNumericDataType() const
     108             :     {
     109    15433488 :         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         608 :     GDALExtendedDataTypeSubType GetSubType() const
     119             :     {
     120         608 :         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       92246 :     size_t GetSize() const
     140             :     {
     141       92246 :         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         433 :     const GDALRasterAttributeTable *GetRAT() const
     164             :     {
     165         433 :         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       24739 : 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       14011 : 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       13043 :     void SetSelf(const std::shared_ptr<GDALGroup> &self)
     340             :     {
     341       13043 :         m_pSelf = self;
     342       13043 :     }
     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        2778 :     const std::string &GetName() const
     362             :     {
     363        2778 :         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      325986 :     const std::string &GetFullName() const
     371             :     {
     372      325986 :         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          91 :     GetDataTypes() const
     383             :     {
     384          91 :         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 papszGroupDiscoverOptions = nullptr,
     395             :         CSLConstList papszArrayDiscoverOptions = nullptr,
     396             :         CSLConstList papszGroupOpenOptions = nullptr) const;
     397             : 
     398             :     std::vector<std::shared_ptr<GDALMDArray>>
     399             :     GetMDArrays(CSLConstList papszDiscoverOptions = nullptr,
     400             :                 CSLConstList papszOpenOptions = nullptr) const;
     401             : 
     402             :     std::vector<std::shared_ptr<GDALMDArray>>
     403             :     GetMDArraysRecursive(CSLConstList papszGroupDiscoverOptions = nullptr,
     404             :                          CSLConstList papszArrayDiscoverOptions = nullptr,
     405             :                          CSLConstList papszGroupOpenOptions = nullptr,
     406             :                          CSLConstList papszArrayOpenOptions = nullptr) const;
     407             : 
     408             :     virtual std::vector<std::string>
     409             :     GetGroupNames(CSLConstList papszOptions = nullptr) const;
     410             :     virtual std::shared_ptr<GDALGroup>
     411             :     OpenGroup(const std::string &osName,
     412             :               CSLConstList papszOptions = nullptr) const;
     413             : 
     414             :     std::vector<std::shared_ptr<GDALGroup>>
     415             :     GetGroups(CSLConstList papszDiscoverOptions = nullptr,
     416             :               CSLConstList papszOpenOptions = nullptr) const;
     417             : 
     418             :     std::vector<std::shared_ptr<GDALGroup>>
     419             :     GetGroupsRecursive(CSLConstList papszDiscoverOptions = nullptr,
     420             :                        CSLConstList papszOpenOptions = nullptr) const;
     421             : 
     422             :     virtual std::vector<std::string>
     423             :     GetVectorLayerNames(CSLConstList papszOptions = nullptr) const;
     424             :     virtual OGRLayer *
     425             :     OpenVectorLayer(const std::string &osName,
     426             :                     CSLConstList papszOptions = nullptr) const;
     427             : 
     428             :     virtual std::vector<std::shared_ptr<GDALDimension>>
     429             :     GetDimensions(CSLConstList papszOptions = nullptr) const;
     430             : 
     431             :     std::vector<std::shared_ptr<GDALDimension>>
     432             :     GetDimensionsRecursive(CSLConstList papszDimensionDiscoverOptions = nullptr,
     433             :                            CSLConstList papszGroupDiscoverOptions = nullptr,
     434             :                            CSLConstList papszArrayDiscoverOptions = nullptr,
     435             :                            CSLConstList papszGroupOpenOptions = nullptr,
     436             :                            CSLConstList papszArrayOpenOptions = nullptr) const;
     437             : 
     438             :     virtual std::shared_ptr<GDALGroup>
     439             :     CreateGroup(const std::string &osName, CSLConstList papszOptions = nullptr);
     440             : 
     441             :     virtual bool DeleteGroup(const std::string &osName,
     442             :                              CSLConstList papszOptions = nullptr);
     443             : 
     444             :     virtual std::shared_ptr<GDALDimension>
     445             :     CreateDimension(const std::string &osName, const std::string &osType,
     446             :                     const std::string &osDirection, GUInt64 nSize,
     447             :                     CSLConstList papszOptions = nullptr);
     448             : 
     449             :     virtual std::shared_ptr<GDALMDArray> CreateMDArray(
     450             :         const std::string &osName,
     451             :         const std::vector<std::shared_ptr<GDALDimension>> &aoDimensions,
     452             :         const GDALExtendedDataType &oDataType,
     453             :         CSLConstList papszOptions = nullptr);
     454             : 
     455             :     virtual bool DeleteMDArray(const std::string &osName,
     456             :                                CSLConstList papszOptions = nullptr);
     457             : 
     458             :     GUInt64 GetTotalCopyCost() const;
     459             : 
     460             :     virtual bool CopyFrom(const std::shared_ptr<GDALGroup> &poDstRootGroup,
     461             :                           GDALDataset *poSrcDS,
     462             :                           const std::shared_ptr<GDALGroup> &poSrcGroup,
     463             :                           bool bStrict, GUInt64 &nCurCost,
     464             :                           const GUInt64 nTotalCost,
     465             :                           GDALProgressFunc pfnProgress, void *pProgressData,
     466             :                           CSLConstList papszOptions = nullptr);
     467             : 
     468             :     virtual CSLConstList GetStructuralInfo() const;
     469             : 
     470             :     std::shared_ptr<GDALMDArray>
     471             :     OpenMDArrayFromFullname(const std::string &osFullName,
     472             :                             CSLConstList papszOptions = nullptr) const;
     473             : 
     474             :     std::shared_ptr<GDALAttribute>
     475             :     OpenAttributeFromFullname(const std::string &osFullName,
     476             :                               CSLConstList papszOptions = nullptr) const;
     477             : 
     478             :     std::shared_ptr<GDALMDArray>
     479             :     ResolveMDArray(const std::string &osName, const std::string &osStartingPath,
     480             :                    CSLConstList papszOptions = nullptr) const;
     481             : 
     482             :     std::shared_ptr<GDALGroup>
     483             :     OpenGroupFromFullname(const std::string &osFullName,
     484             :                           CSLConstList papszOptions = nullptr) const;
     485             : 
     486             :     std::shared_ptr<GDALDimension>
     487             :     OpenDimensionFromFullname(const std::string &osFullName) const;
     488             : 
     489             :     virtual void ClearStatistics();
     490             : 
     491             :     virtual bool Rename(const std::string &osNewName);
     492             : 
     493             :     std::shared_ptr<GDALGroup>
     494             :     SubsetDimensionFromSelection(const std::string &osSelection) const;
     495             : 
     496             :     void RecursivelyVisitArrays(
     497             :         std::function<void(const std::shared_ptr<GDALMDArray> &)> visitor);
     498             : 
     499             :     //! @cond Doxygen_Suppress
     500             :     virtual void ParentRenamed(const std::string &osNewParentFullName);
     501             : 
     502             :     virtual void Deleted();
     503             : 
     504             :     virtual void ParentDeleted();
     505             : 
     506          23 :     const std::string &GetContext() const
     507             :     {
     508          23 :         return m_osContext;
     509             :     }
     510             : 
     511             :     //! @endcond
     512             : 
     513             :     //! @cond Doxygen_Suppress
     514             :     static constexpr GUInt64 COPY_COST = 1000;
     515             :     //! @endcond
     516             : };
     517             : 
     518             : /* ******************************************************************** */
     519             : /*                          GDALAbstractMDArray                         */
     520             : /* ******************************************************************** */
     521             : 
     522             : /**
     523             :  * Abstract class, implemented by GDALAttribute and GDALMDArray.
     524             :  *
     525             :  * @since GDAL 3.1
     526             :  */
     527      174031 : class CPL_DLL GDALAbstractMDArray
     528             : {
     529             :   protected:
     530             :     //! @cond Doxygen_Suppress
     531             :     std::string m_osName{};
     532             : 
     533             :     // This is actually a path of the form "/parent_path/{m_osName}"
     534             :     std::string m_osFullName{};
     535             :     std::weak_ptr<GDALAbstractMDArray> m_pSelf{};
     536             : 
     537             :     //! Can be set to false by the owing object, when deleting this object
     538             :     bool m_bValid = true;
     539             : 
     540             :     GDALAbstractMDArray(const std::string &osParentName,
     541             :                         const std::string &osName);
     542             : 
     543       14486 :     void SetSelf(const std::shared_ptr<GDALAbstractMDArray> &self)
     544             :     {
     545       14486 :         m_pSelf = self;
     546       14486 :     }
     547             : 
     548             :     bool CheckValidAndErrorOutIfNot() const;
     549             : 
     550             :     bool CheckReadWriteParams(const GUInt64 *arrayStartIdx, const size_t *count,
     551             :                               const GInt64 *&arrayStep,
     552             :                               const GPtrDiff_t *&bufferStride,
     553             :                               const GDALExtendedDataType &bufferDataType,
     554             :                               const void *buffer,
     555             :                               const void *buffer_alloc_start,
     556             :                               size_t buffer_alloc_size,
     557             :                               std::vector<GInt64> &tmp_arrayStep,
     558             :                               std::vector<GPtrDiff_t> &tmp_bufferStride) const;
     559             : 
     560             :     virtual bool
     561             :     IRead(const GUInt64 *arrayStartIdx,    // array of size GetDimensionCount()
     562             :           const size_t *count,             // array of size GetDimensionCount()
     563             :           const GInt64 *arrayStep,         // step in elements
     564             :           const GPtrDiff_t *bufferStride,  // stride in elements
     565             :           const GDALExtendedDataType &bufferDataType,
     566             :           void *pDstBuffer) const = 0;
     567             : 
     568             :     virtual bool
     569             :     IWrite(const GUInt64 *arrayStartIdx,    // array of size GetDimensionCount()
     570             :            const size_t *count,             // array of size GetDimensionCount()
     571             :            const GInt64 *arrayStep,         // step in elements
     572             :            const GPtrDiff_t *bufferStride,  // stride in elements
     573             :            const GDALExtendedDataType &bufferDataType, const void *pSrcBuffer);
     574             : 
     575             :     void BaseRename(const std::string &osNewName);
     576             : 
     577          47 :     virtual void NotifyChildrenOfRenaming()
     578             :     {
     579          47 :     }
     580             : 
     581          46 :     virtual void NotifyChildrenOfDeletion()
     582             :     {
     583          46 :     }
     584             : 
     585             :     //! @endcond
     586             : 
     587             :   public:
     588             :     virtual ~GDALAbstractMDArray();
     589             : 
     590             :     /** Return the name of an array or attribute.
     591             :      *
     592             :      * This is the same as the C function GDALMDArrayGetName() or
     593             :      * GDALAttributeGetName().
     594             :      */
     595      114264 :     const std::string &GetName() const
     596             :     {
     597      114264 :         return m_osName;
     598             :     }
     599             : 
     600             :     /** Return the name of an array or attribute.
     601             :      *
     602             :      * This is the same as the C function GDALMDArrayGetFullName() or
     603             :      * GDALAttributeGetFullName().
     604             :      */
     605       21258 :     const std::string &GetFullName() const
     606             :     {
     607       21258 :         return m_osFullName;
     608             :     }
     609             : 
     610             :     GUInt64 GetTotalElementsCount() const;
     611             : 
     612             :     virtual size_t GetDimensionCount() const;
     613             : 
     614             :     virtual const std::vector<std::shared_ptr<GDALDimension>> &
     615             :     GetDimensions() const = 0;
     616             : 
     617             :     virtual const GDALExtendedDataType &GetDataType() const = 0;
     618             : 
     619             :     virtual std::vector<GUInt64> GetBlockSize() const;
     620             : 
     621             :     virtual std::vector<size_t>
     622             :     GetProcessingChunkSize(size_t nMaxChunkMemory) const;
     623             : 
     624             :     /* clang-format off */
     625             :     /** Type of pfnFunc argument of ProcessPerChunk().
     626             :      * @param array Array on which ProcessPerChunk was called.
     627             :      * @param chunkArrayStartIdx Values representing the starting index to use
     628             :      *                           in each dimension (in [0, aoDims[i].GetSize()-1] range)
     629             :      *                           for the current chunk.
     630             :      *                           Will be nullptr for a zero-dimensional array.
     631             :      * @param chunkCount         Values representing the number of values to use in
     632             :      *                           each dimension for the current chunk.
     633             :      *                           Will be nullptr for a zero-dimensional array.
     634             :      * @param iCurChunk          Number of current chunk being processed.
     635             :      *                           In [1, nChunkCount] range.
     636             :      * @param nChunkCount        Total number of chunks to process.
     637             :      * @param pUserData          User data.
     638             :      * @return return true in case of success.
     639             :      */
     640             :     typedef bool (*FuncProcessPerChunkType)(
     641             :                         GDALAbstractMDArray *array,
     642             :                         const GUInt64 *chunkArrayStartIdx,
     643             :                         const size_t *chunkCount,
     644             :                         GUInt64 iCurChunk,
     645             :                         GUInt64 nChunkCount,
     646             :                         void *pUserData);
     647             :     /* clang-format on */
     648             : 
     649             :     virtual bool ProcessPerChunk(const GUInt64 *arrayStartIdx,
     650             :                                  const GUInt64 *count, const size_t *chunkSize,
     651             :                                  FuncProcessPerChunkType pfnFunc,
     652             :                                  void *pUserData);
     653             : 
     654             :     virtual bool
     655             :     Read(const GUInt64 *arrayStartIdx,    // array of size GetDimensionCount()
     656             :          const size_t *count,             // array of size GetDimensionCount()
     657             :          const GInt64 *arrayStep,         // step in elements
     658             :          const GPtrDiff_t *bufferStride,  // stride in elements
     659             :          const GDALExtendedDataType &bufferDataType, void *pDstBuffer,
     660             :          const void *pDstBufferAllocStart = nullptr,
     661             :          size_t nDstBufferAllocSize = 0) const;
     662             : 
     663             :     bool
     664             :     Write(const GUInt64 *arrayStartIdx,    // array of size GetDimensionCount()
     665             :           const size_t *count,             // array of size GetDimensionCount()
     666             :           const GInt64 *arrayStep,         // step in elements
     667             :           const GPtrDiff_t *bufferStride,  // stride in elements
     668             :           const GDALExtendedDataType &bufferDataType, const void *pSrcBuffer,
     669             :           const void *pSrcBufferAllocStart = nullptr,
     670             :           size_t nSrcBufferAllocSize = 0);
     671             : 
     672             :     virtual bool Rename(const std::string &osNewName);
     673             : 
     674             :     //! @cond Doxygen_Suppress
     675             :     virtual void Deleted();
     676             : 
     677             :     virtual void ParentDeleted();
     678             : 
     679             :     virtual void ParentRenamed(const std::string &osNewParentFullName);
     680             :     //! @endcond
     681             : };
     682             : 
     683             : /* ******************************************************************** */
     684             : /*                              GDALRawResult                           */
     685             : /* ******************************************************************** */
     686             : 
     687             : /**
     688             :  * Store the raw result of an attribute value, which might contain dynamically
     689             :  * allocated structures (like pointer to strings).
     690             :  *
     691             :  * @since GDAL 3.1
     692             :  */
     693             : class CPL_DLL GDALRawResult
     694             : {
     695             :   private:
     696             :     GDALExtendedDataType m_dt;
     697             :     size_t m_nEltCount;
     698             :     size_t m_nSize;
     699             :     GByte *m_raw;
     700             : 
     701             :     void FreeMe();
     702             : 
     703             :     GDALRawResult(const GDALRawResult &) = delete;
     704             :     GDALRawResult &operator=(const GDALRawResult &) = delete;
     705             : 
     706             :   protected:
     707             :     friend class GDALAttribute;
     708             :     //! @cond Doxygen_Suppress
     709             :     GDALRawResult(GByte *raw, const GDALExtendedDataType &dt, size_t nEltCount);
     710             :     //! @endcond
     711             : 
     712             :   public:
     713             :     ~GDALRawResult();
     714             :     GDALRawResult(GDALRawResult &&);
     715             :     GDALRawResult &operator=(GDALRawResult &&);
     716             : 
     717             :     /** Return byte at specified index. */
     718             :     const GByte &operator[](size_t idx) const
     719             :     {
     720             :         return m_raw[idx];
     721             :     }
     722             : 
     723             :     /** Return pointer to the start of data. */
     724         642 :     const GByte *data() const
     725             :     {
     726         642 :         return m_raw;
     727             :     }
     728             : 
     729             :     /** Return the size in bytes of the raw result. */
     730         284 :     size_t size() const
     731             :     {
     732         284 :         return m_nSize;
     733             :     }
     734             : 
     735             :     //! @cond Doxygen_Suppress
     736             :     GByte *StealData();
     737             :     //! @endcond
     738             : };
     739             : 
     740             : /* ******************************************************************** */
     741             : /*                              GDALAttribute                           */
     742             : /* ******************************************************************** */
     743             : 
     744             : /* clang-format off */
     745             : /**
     746             :  * Class modeling an attribute that has a name, a value and a type, and is
     747             :  * typically used to describe a metadata item. The value can be (for the
     748             :  * HDF5 format) in the general case a multidimensional array of "any" type
     749             :  * (in most cases, this will be a single value of string or numeric type)
     750             :  *
     751             :  * This is based on the <a href="https://portal.opengeospatial.org/files/81716#_hdf5_attribute">HDF5
     752             :  * attribute concept</a>
     753             :  *
     754             :  * @since GDAL 3.1
     755             :  */
     756             : /* clang-format on */
     757             : 
     758      163303 : class CPL_DLL GDALAttribute : virtual public GDALAbstractMDArray
     759             : {
     760             :     mutable std::string m_osCachedVal{};
     761             : 
     762             :   protected:
     763             :     //! @cond Doxygen_Suppress
     764             :     GDALAttribute(const std::string &osParentName, const std::string &osName);
     765             :     //! @endcond
     766             : 
     767             :   public:
     768             :     //! @cond Doxygen_Suppress
     769             :     ~GDALAttribute() override;
     770             :     //! @endcond
     771             : 
     772             :     std::vector<GUInt64> GetDimensionsSize() const;
     773             : 
     774             :     GDALRawResult ReadAsRaw() const;
     775             :     const char *ReadAsString() const;
     776             :     int ReadAsInt() const;
     777             :     int64_t ReadAsInt64() const;
     778             :     double ReadAsDouble() const;
     779             :     CPLStringList ReadAsStringArray() const;
     780             :     std::vector<int> ReadAsIntArray() const;
     781             :     std::vector<int64_t> ReadAsInt64Array() const;
     782             :     std::vector<double> ReadAsDoubleArray() const;
     783             : 
     784             :     using GDALAbstractMDArray::Write;
     785             :     bool Write(const void *pabyValue, size_t nLen);
     786             :     bool Write(const char *);
     787             :     bool WriteInt(int);
     788             :     bool WriteInt64(int64_t);
     789             :     bool Write(double);
     790             :     bool Write(CSLConstList);
     791             :     bool Write(const int *, size_t);
     792             :     bool Write(const int64_t *, size_t);
     793             :     bool Write(const double *, size_t);
     794             : 
     795             :     //! @cond Doxygen_Suppress
     796             :     static constexpr GUInt64 COPY_COST = 100;
     797             :     //! @endcond
     798             : };
     799             : 
     800             : /************************************************************************/
     801             : /*                         GDALAttributeString                          */
     802             : /************************************************************************/
     803             : 
     804             : //! @cond Doxygen_Suppress
     805             : class CPL_DLL GDALAttributeString final : public GDALAttribute
     806             : {
     807             :     std::vector<std::shared_ptr<GDALDimension>> m_dims{};
     808             :     GDALExtendedDataType m_dt = GDALExtendedDataType::CreateString();
     809             :     std::string m_osValue;
     810             : 
     811             :   protected:
     812             :     bool IRead(const GUInt64 *, const size_t *, const GInt64 *,
     813             :                const GPtrDiff_t *, const GDALExtendedDataType &bufferDataType,
     814             :                void *pDstBuffer) const override;
     815             : 
     816             :   public:
     817             :     GDALAttributeString(const std::string &osParentName,
     818             :                         const std::string &osName, const std::string &osValue,
     819             :                         GDALExtendedDataTypeSubType eSubType = GEDTST_NONE);
     820             : 
     821             :     const std::vector<std::shared_ptr<GDALDimension>> &
     822             :     GetDimensions() const override;
     823             : 
     824             :     const GDALExtendedDataType &GetDataType() const override;
     825             : };
     826             : 
     827             : //! @endcond
     828             : 
     829             : /************************************************************************/
     830             : /*                         GDALAttributeNumeric                         */
     831             : /************************************************************************/
     832             : 
     833             : //! @cond Doxygen_Suppress
     834             : class CPL_DLL GDALAttributeNumeric final : public GDALAttribute
     835             : {
     836             :     std::vector<std::shared_ptr<GDALDimension>> m_dims{};
     837             :     GDALExtendedDataType m_dt;
     838             :     int m_nValue = 0;
     839             :     double m_dfValue = 0;
     840             :     std::vector<GUInt32> m_anValuesUInt32{};
     841             : 
     842             :   protected:
     843             :     bool IRead(const GUInt64 *, const size_t *, const GInt64 *,
     844             :                const GPtrDiff_t *, const GDALExtendedDataType &bufferDataType,
     845             :                void *pDstBuffer) const override;
     846             : 
     847             :   public:
     848             :     GDALAttributeNumeric(const std::string &osParentName,
     849             :                          const std::string &osName, double dfValue);
     850             :     GDALAttributeNumeric(const std::string &osParentName,
     851             :                          const std::string &osName, int nValue);
     852             :     GDALAttributeNumeric(const std::string &osParentName,
     853             :                          const std::string &osName,
     854             :                          const std::vector<GUInt32> &anValues);
     855             : 
     856             :     const std::vector<std::shared_ptr<GDALDimension>> &
     857             :     GetDimensions() const override;
     858             : 
     859             :     const GDALExtendedDataType &GetDataType() const override;
     860             : };
     861             : 
     862             : //! @endcond
     863             : 
     864             : /* ******************************************************************** */
     865             : /*                              GDALMDArray                             */
     866             : /* ******************************************************************** */
     867             : 
     868             : /* clang-format off */
     869             : /**
     870             :  * Class modeling a multi-dimensional array. It has a name, values organized
     871             :  * as an array and a list of GDALAttribute.
     872             :  *
     873             :  * This is based on the <a href="https://portal.opengeospatial.org/files/81716#_hdf5_dataset">HDF5
     874             :  * dataset concept</a>
     875             :  *
     876             :  * @since GDAL 3.1
     877             :  */
     878             : /* clang-format on */
     879             : 
     880             : class CPL_DLL GDALMDArray : virtual public GDALAbstractMDArray,
     881             :                             public GDALIHasAttribute
     882             : {
     883             :     friend class GDALMDArrayResampled;
     884             :     std::shared_ptr<GDALMDArray>
     885             :     GetView(const std::vector<GUInt64> &indices) const;
     886             : 
     887             :     inline std::shared_ptr<GDALMDArray>
     888          19 :     atInternal(const std::vector<GUInt64> &indices) const
     889             :     {
     890          19 :         return GetView(indices);
     891             :     }
     892             : 
     893             :     template <typename... GUInt64VarArg>
     894             :     // cppcheck-suppress functionStatic
     895             :     inline std::shared_ptr<GDALMDArray>
     896           7 :     atInternal(std::vector<GUInt64> &indices, GUInt64 idx,
     897             :                GUInt64VarArg... tail) const
     898             :     {
     899           7 :         indices.push_back(idx);
     900           7 :         return atInternal(indices, tail...);
     901             :     }
     902             : 
     903             :     // Used for example by GDALSubsetGroup to distinguish a derived group
     904             :     //from its original, without altering its name
     905             :     const std::string m_osContext{};
     906             : 
     907             :     mutable bool m_bHasTriedCachedArray = false;
     908             :     mutable std::shared_ptr<GDALMDArray> m_poCachedArray{};
     909             : 
     910             :   protected:
     911             :     //! @cond Doxygen_Suppress
     912             :     GDALMDArray(const std::string &osParentName, const std::string &osName,
     913             :                 const std::string &osContext = std::string());
     914             : 
     915             :     virtual bool IAdviseRead(const GUInt64 *arrayStartIdx, const size_t *count,
     916             :                              CSLConstList papszOptions) const;
     917             : 
     918        3671 :     virtual bool IsCacheable() const
     919             :     {
     920        3671 :         return true;
     921             :     }
     922             : 
     923             :     virtual bool SetStatistics(bool bApproxStats, double dfMin, double dfMax,
     924             :                                double dfMean, double dfStdDev,
     925             :                                GUInt64 nValidCount, CSLConstList papszOptions);
     926             : 
     927             :     static std::string MassageName(const std::string &inputName);
     928             : 
     929             :     std::shared_ptr<GDALGroup>
     930             :     GetCacheRootGroup(bool bCanCreate, std::string &osCacheFilenameOut) const;
     931             : 
     932             :     // Returns if bufferStride values express a transposed view of the array
     933             :     bool IsTransposedRequest(const size_t *count,
     934             :                              const GPtrDiff_t *bufferStride) const;
     935             : 
     936             :     // Should only be called if IsTransposedRequest() returns true
     937             :     bool ReadForTransposedRequest(const GUInt64 *arrayStartIdx,
     938             :                                   const size_t *count, const GInt64 *arrayStep,
     939             :                                   const GPtrDiff_t *bufferStride,
     940             :                                   const GDALExtendedDataType &bufferDataType,
     941             :                                   void *pDstBuffer) const;
     942             : 
     943             :     bool IsStepOneContiguousRowMajorOrderedSameDataType(
     944             :         const size_t *count, const GInt64 *arrayStep,
     945             :         const GPtrDiff_t *bufferStride,
     946             :         const GDALExtendedDataType &bufferDataType) const;
     947             : 
     948             :     // Should only be called if IsStepOneContiguousRowMajorOrderedSameDataType()
     949             :     // returns false
     950             :     bool ReadUsingContiguousIRead(const GUInt64 *arrayStartIdx,
     951             :                                   const size_t *count, const GInt64 *arrayStep,
     952             :                                   const GPtrDiff_t *bufferStride,
     953             :                                   const GDALExtendedDataType &bufferDataType,
     954             :                                   void *pDstBuffer) const;
     955             : 
     956             :     static std::shared_ptr<GDALMDArray> CreateGLTOrthorectified(
     957             :         const std::shared_ptr<GDALMDArray> &poParent,
     958             :         const std::shared_ptr<GDALGroup> &poRootGroup,
     959             :         const std::shared_ptr<GDALMDArray> &poGLTX,
     960             :         const std::shared_ptr<GDALMDArray> &poGLTY, int nGLTIndexOffset,
     961             :         const std::vector<double> &adfGeoTransform, CSLConstList papszOptions);
     962             : 
     963             :     //! @endcond
     964             : 
     965             :   public:
     966             :     GUInt64 GetTotalCopyCost() const;
     967             : 
     968             :     virtual bool CopyFrom(GDALDataset *poSrcDS, const GDALMDArray *poSrcArray,
     969             :                           bool bStrict, GUInt64 &nCurCost,
     970             :                           const GUInt64 nTotalCost,
     971             :                           GDALProgressFunc pfnProgress, void *pProgressData);
     972             : 
     973             :     /** Return whether an array is writable. */
     974             :     virtual bool IsWritable() const = 0;
     975             : 
     976             :     /** Return the filename that contains that array.
     977             :      *
     978             :      * This is used in particular for caching.
     979             :      *
     980             :      * Might be empty if the array is not linked to a file.
     981             :      *
     982             :      * @since GDAL 3.4
     983             :      */
     984             :     virtual const std::string &GetFilename() const = 0;
     985             : 
     986             :     virtual CSLConstList GetStructuralInfo() const;
     987             : 
     988             :     virtual const std::string &GetUnit() const;
     989             : 
     990             :     virtual bool SetUnit(const std::string &osUnit);
     991             : 
     992             :     virtual bool SetSpatialRef(const OGRSpatialReference *poSRS);
     993             : 
     994             :     virtual std::shared_ptr<OGRSpatialReference> GetSpatialRef() const;
     995             : 
     996             :     virtual const void *GetRawNoDataValue() const;
     997             : 
     998             :     double GetNoDataValueAsDouble(bool *pbHasNoData = nullptr) const;
     999             : 
    1000             :     int64_t GetNoDataValueAsInt64(bool *pbHasNoData = nullptr) const;
    1001             : 
    1002             :     uint64_t GetNoDataValueAsUInt64(bool *pbHasNoData = nullptr) const;
    1003             : 
    1004             :     virtual bool SetRawNoDataValue(const void *pRawNoData);
    1005             : 
    1006             :     //! @cond Doxygen_Suppress
    1007           5 :     bool SetNoDataValue(int nNoData)
    1008             :     {
    1009           5 :         return SetNoDataValue(static_cast<int64_t>(nNoData));
    1010             :     }
    1011             : 
    1012             :     //! @endcond
    1013             : 
    1014             :     bool SetNoDataValue(double dfNoData);
    1015             : 
    1016             :     bool SetNoDataValue(int64_t nNoData);
    1017             : 
    1018             :     bool SetNoDataValue(uint64_t nNoData);
    1019             : 
    1020             :     virtual bool Resize(const std::vector<GUInt64> &anNewDimSizes,
    1021             :                         CSLConstList papszOptions);
    1022             : 
    1023             :     virtual double GetOffset(bool *pbHasOffset = nullptr,
    1024             :                              GDALDataType *peStorageType = nullptr) const;
    1025             : 
    1026             :     virtual double GetScale(bool *pbHasScale = nullptr,
    1027             :                             GDALDataType *peStorageType = nullptr) const;
    1028             : 
    1029             :     virtual bool SetOffset(double dfOffset,
    1030             :                            GDALDataType eStorageType = GDT_Unknown);
    1031             : 
    1032             :     virtual bool SetScale(double dfScale,
    1033             :                           GDALDataType eStorageType = GDT_Unknown);
    1034             : 
    1035             :     std::shared_ptr<GDALMDArray> GetSelf() const;
    1036             : 
    1037             :     std::shared_ptr<GDALMDArray> GetView(const std::string &viewExpr) const;
    1038             : 
    1039             :     std::shared_ptr<GDALMDArray> operator[](const std::string &fieldName) const;
    1040             : 
    1041             :     /** Return a view of the array using integer indexing.
    1042             :      *
    1043             :      * Equivalent of GetView("[indices_0,indices_1,.....,indices_last]")
    1044             :      *
    1045             :      * Example:
    1046             :      * \code
    1047             :      * ar->at(0,3,2)
    1048             :      * \endcode
    1049             :      */
    1050             :     // sphinx 4.1.0 / breathe 4.30.0 don't like typename...
    1051             :     //! @cond Doxygen_Suppress
    1052             :     template <typename... GUInt64VarArg>
    1053             :     //! @endcond
    1054             :     // cppcheck-suppress functionStatic
    1055          19 :     std::shared_ptr<GDALMDArray> at(GUInt64 idx, GUInt64VarArg... tail) const
    1056             :     {
    1057          38 :         std::vector<GUInt64> indices;
    1058          19 :         indices.push_back(idx);
    1059          38 :         return atInternal(indices, tail...);
    1060             :     }
    1061             : 
    1062             :     virtual std::shared_ptr<GDALMDArray>
    1063             :     Transpose(const std::vector<int> &anMapNewAxisToOldAxis) const;
    1064             : 
    1065             :     std::shared_ptr<GDALMDArray> GetUnscaled(
    1066             :         double dfOverriddenScale = std::numeric_limits<double>::quiet_NaN(),
    1067             :         double dfOverriddenOffset = std::numeric_limits<double>::quiet_NaN(),
    1068             :         double dfOverriddenDstNodata =
    1069             :             std::numeric_limits<double>::quiet_NaN()) const;
    1070             : 
    1071             :     virtual std::shared_ptr<GDALMDArray>
    1072             :     GetMask(CSLConstList papszOptions) const;
    1073             : 
    1074             :     virtual std::shared_ptr<GDALMDArray>
    1075             :     GetResampled(const std::vector<std::shared_ptr<GDALDimension>> &apoNewDims,
    1076             :                  GDALRIOResampleAlg resampleAlg,
    1077             :                  const OGRSpatialReference *poTargetSRS,
    1078             :                  CSLConstList papszOptions) const;
    1079             : 
    1080             :     std::shared_ptr<GDALMDArray>
    1081             :     GetGridded(const std::string &osGridOptions,
    1082             :                const std::shared_ptr<GDALMDArray> &poXArray = nullptr,
    1083             :                const std::shared_ptr<GDALMDArray> &poYArray = nullptr,
    1084             :                CSLConstList papszOptions = nullptr) const;
    1085             : 
    1086             :     static std::vector<std::shared_ptr<GDALMDArray>>
    1087             :     GetMeshGrid(const std::vector<std::shared_ptr<GDALMDArray>> &apoArrays,
    1088             :                 CSLConstList papszOptions = nullptr);
    1089             : 
    1090             :     virtual GDALDataset *
    1091             :     AsClassicDataset(size_t iXDim, size_t iYDim,
    1092             :                      const std::shared_ptr<GDALGroup> &poRootGroup = nullptr,
    1093             :                      CSLConstList papszOptions = nullptr) const;
    1094             : 
    1095             :     virtual CPLErr GetStatistics(bool bApproxOK, bool bForce, double *pdfMin,
    1096             :                                  double *pdfMax, double *pdfMean,
    1097             :                                  double *padfStdDev, GUInt64 *pnValidCount,
    1098             :                                  GDALProgressFunc pfnProgress,
    1099             :                                  void *pProgressData);
    1100             : 
    1101             :     virtual bool ComputeStatistics(bool bApproxOK, double *pdfMin,
    1102             :                                    double *pdfMax, double *pdfMean,
    1103             :                                    double *pdfStdDev, GUInt64 *pnValidCount,
    1104             :                                    GDALProgressFunc, void *pProgressData,
    1105             :                                    CSLConstList papszOptions);
    1106             : 
    1107             :     virtual void ClearStatistics();
    1108             : 
    1109             :     virtual std::vector<std::shared_ptr<GDALMDArray>>
    1110             :     GetCoordinateVariables() const;
    1111             : 
    1112             :     bool AdviseRead(const GUInt64 *arrayStartIdx, const size_t *count,
    1113             :                     CSLConstList papszOptions = nullptr) const;
    1114             : 
    1115             :     virtual bool IsRegularlySpaced(double &dfStart, double &dfIncrement) const;
    1116             : 
    1117             :     bool GuessGeoTransform(size_t nDimX, size_t nDimY, bool bPixelIsPoint,
    1118             :                            GDALGeoTransform &gt) const;
    1119             : 
    1120             :     bool GuessGeoTransform(size_t nDimX, size_t nDimY, bool bPixelIsPoint,
    1121             :                            double adfGeoTransform[6]) const;
    1122             : 
    1123             :     bool Cache(CSLConstList papszOptions = nullptr) const;
    1124             : 
    1125             :     bool
    1126             :     Read(const GUInt64 *arrayStartIdx,    // array of size GetDimensionCount()
    1127             :          const size_t *count,             // array of size GetDimensionCount()
    1128             :          const GInt64 *arrayStep,         // step in elements
    1129             :          const GPtrDiff_t *bufferStride,  // stride in elements
    1130             :          const GDALExtendedDataType &bufferDataType, void *pDstBuffer,
    1131             :          const void *pDstBufferAllocStart = nullptr,
    1132             :          size_t nDstBufferAllocSize = 0) const override final;
    1133             : 
    1134             :     virtual std::shared_ptr<GDALGroup> GetRootGroup() const;
    1135             : 
    1136             :     virtual bool GetRawBlockInfo(const uint64_t *panBlockCoordinates,
    1137             :                                  GDALMDArrayRawBlockInfo &info) const;
    1138             : 
    1139             :     virtual int GetOverviewCount() const;
    1140             : 
    1141             :     virtual std::shared_ptr<GDALMDArray> GetOverview(int idx) const;
    1142             : 
    1143             :     virtual CPLErr BuildOverviews(const char *pszResampling, int nOverviews,
    1144             :                                   const int *panOverviewList,
    1145             :                                   GDALProgressFunc pfnProgress,
    1146             :                                   void *pProgressData,
    1147             :                                   CSLConstList papszOptions);
    1148             : 
    1149             :     bool HasSameShapeAs(const GDALMDArray &other) const;
    1150             : 
    1151             :     static void CopyContiguousBufferToBuffer(
    1152             :         const size_t nDims, const size_t *count, const void *pSrcBuffer,
    1153             :         const GDALExtendedDataType &srcType, void *pDstBuffer,
    1154             :         const GDALExtendedDataType &dstType, const GPtrDiff_t *dstStride);
    1155             : 
    1156             :     std::shared_ptr<GDALMDArray> operator+(
    1157             :         const std::shared_ptr<GDALMDArray> &other) const CPL_WARN_UNUSED_RESULT;
    1158             :     std::shared_ptr<GDALMDArray> operator-(
    1159             :         const std::shared_ptr<GDALMDArray> &other) const CPL_WARN_UNUSED_RESULT;
    1160             :     std::shared_ptr<GDALMDArray> operator*(
    1161             :         const std::shared_ptr<GDALMDArray> &other) const CPL_WARN_UNUSED_RESULT;
    1162             :     std::shared_ptr<GDALMDArray> operator/(
    1163             :         const std::shared_ptr<GDALMDArray> &other) const CPL_WARN_UNUSED_RESULT;
    1164             : 
    1165             :     //! @cond Doxygen_Suppress
    1166             :     static constexpr GUInt64 COPY_COST = 1000;
    1167             : 
    1168             :     bool CopyFromAllExceptValues(const GDALMDArray *poSrcArray, bool bStrict,
    1169             :                                  GUInt64 &nCurCost, const GUInt64 nTotalCost,
    1170             :                                  GDALProgressFunc pfnProgress,
    1171             :                                  void *pProgressData);
    1172             : 
    1173             :     struct Range
    1174             :     {
    1175             :         GUInt64 m_nStartIdx;
    1176             :         GInt64 m_nIncr;
    1177             : 
    1178        1602 :         explicit Range(GUInt64 nStartIdx = 0, GInt64 nIncr = 0)
    1179        1602 :             : m_nStartIdx(nStartIdx), m_nIncr(nIncr)
    1180             :         {
    1181        1602 :         }
    1182             :     };
    1183             : 
    1184             :     struct ViewSpec
    1185             :     {
    1186             :         std::string m_osFieldName{};
    1187             : 
    1188             :         // or
    1189             : 
    1190             :         std::vector<size_t>
    1191             :             m_mapDimIdxToParentDimIdx{};  // of size m_dims.size()
    1192             :         std::vector<Range>
    1193             :             m_parentRanges{};  // of size m_poParent->GetDimensionCount()
    1194             :     };
    1195             : 
    1196             :     virtual std::shared_ptr<GDALMDArray>
    1197             :     GetView(const std::string &viewExpr, bool bRenameDimensions,
    1198             :             std::vector<ViewSpec> &viewSpecs) const;
    1199             : 
    1200        2200 :     const std::string &GetContext() const
    1201             :     {
    1202        2200 :         return m_osContext;
    1203             :     }
    1204             : 
    1205             :     //! @endcond
    1206             : };
    1207             : 
    1208             : //! @cond Doxygen_Suppress
    1209             : bool CPL_DLL GDALMDRasterIOFromBand(
    1210             :     GDALRasterBand *poBand, GDALRWFlag eRWFlag, size_t iDimX, size_t iDimY,
    1211             :     const GUInt64 *arrayStartIdx, const size_t *count, const GInt64 *arrayStep,
    1212             :     const GPtrDiff_t *bufferStride, const GDALExtendedDataType &bufferDataType,
    1213             :     void *pBuffer);
    1214             : 
    1215             : //! @endcond
    1216             : 
    1217             : /************************************************************************/
    1218             : /*                      GDALMDArrayRegularlySpaced                      */
    1219             : /************************************************************************/
    1220             : 
    1221             : //! @cond Doxygen_Suppress
    1222             : class CPL_DLL GDALMDArrayRegularlySpaced final : public GDALMDArray
    1223             : {
    1224             :     double m_dfStart = 0;
    1225             :     double m_dfIncrement = 0;
    1226             :     double m_dfOffsetInIncrement = 0;
    1227             :     const GDALExtendedDataType m_dt = GDALExtendedDataType::Create(GDT_Float64);
    1228             :     const std::vector<std::shared_ptr<GDALDimension>> m_dims;
    1229             :     std::vector<std::shared_ptr<GDALAttribute>> m_attributes{};
    1230             :     const std::string m_osEmptyFilename{};
    1231             : 
    1232             :   protected:
    1233             :     bool IRead(const GUInt64 *, const size_t *, const GInt64 *,
    1234             :                const GPtrDiff_t *, const GDALExtendedDataType &bufferDataType,
    1235             :                void *pDstBuffer) const override;
    1236             : 
    1237             :   public:
    1238             :     GDALMDArrayRegularlySpaced(const std::string &osParentName,
    1239             :                                const std::string &osName,
    1240             :                                const std::shared_ptr<GDALDimension> &poDim,
    1241             :                                double dfStart, double dfIncrement,
    1242             :                                double dfOffsetInIncrement);
    1243             : 
    1244             :     static std::shared_ptr<GDALMDArrayRegularlySpaced>
    1245             :     Create(const std::string &osParentName, const std::string &osName,
    1246             :            const std::shared_ptr<GDALDimension> &poDim, double dfStart,
    1247             :            double dfIncrement, double dfOffsetInIncrement);
    1248             : 
    1249           0 :     bool IsWritable() const override
    1250             :     {
    1251           0 :         return false;
    1252             :     }
    1253             : 
    1254         237 :     const std::string &GetFilename() const override
    1255             :     {
    1256         237 :         return m_osEmptyFilename;
    1257             :     }
    1258             : 
    1259             :     const std::vector<std::shared_ptr<GDALDimension>> &
    1260             :     GetDimensions() const override;
    1261             : 
    1262             :     const GDALExtendedDataType &GetDataType() const override;
    1263             : 
    1264             :     std::vector<std::shared_ptr<GDALAttribute>>
    1265             :         GetAttributes(CSLConstList) const override;
    1266             : 
    1267             :     void AddAttribute(const std::shared_ptr<GDALAttribute> &poAttr);
    1268             : 
    1269             :     bool IsRegularlySpaced(double &dfStart, double &dfIncrement) const override;
    1270             : };
    1271             : 
    1272             : //! @endcond
    1273             : 
    1274             : /* ******************************************************************** */
    1275             : /*                            GDALDimension                             */
    1276             : /* ******************************************************************** */
    1277             : 
    1278             : /**
    1279             :  * Class modeling a a dimension / axis used to index multidimensional arrays.
    1280             :  * It has a name, a size (that is the number of values that can be indexed along
    1281             :  * the dimension), a type (see GDALDimension::GetType()), a direction
    1282             :  * (see GDALDimension::GetDirection()), a unit and can optionally point to a
    1283             :  * GDALMDArray variable, typically one-dimensional, describing the values taken
    1284             :  * by the dimension. For a georeferenced GDALMDArray and its X dimension, this
    1285             :  * will be typically the values of the easting/longitude for each grid point.
    1286             :  *
    1287             :  * @since GDAL 3.1
    1288             :  */
    1289       13740 : class CPL_DLL GDALDimension
    1290             : {
    1291             :   public:
    1292             :     //! @cond Doxygen_Suppress
    1293             :     GDALDimension(const std::string &osParentName, const std::string &osName,
    1294             :                   const std::string &osType, const std::string &osDirection,
    1295             :                   GUInt64 nSize);
    1296             :     //! @endcond
    1297             : 
    1298             :     virtual ~GDALDimension();
    1299             : 
    1300             :     /** Return the name.
    1301             :      *
    1302             :      * This is the same as the C function GDALDimensionGetName()
    1303             :      */
    1304       13106 :     const std::string &GetName() const
    1305             :     {
    1306       13106 :         return m_osName;
    1307             :     }
    1308             : 
    1309             :     /** Return the full name.
    1310             :      *
    1311             :      * This is the same as the C function GDALDimensionGetFullName()
    1312             :      */
    1313        1893 :     const std::string &GetFullName() const
    1314             :     {
    1315        1893 :         return m_osFullName;
    1316             :     }
    1317             : 
    1318             :     /** Return the axis type.
    1319             :      *
    1320             :      * Predefined values are:
    1321             :      * HORIZONTAL_X, HORIZONTAL_Y, VERTICAL, TEMPORAL, PARAMETRIC
    1322             :      * Other values might be returned. Empty value means unknown.
    1323             :      *
    1324             :      * This is the same as the C function GDALDimensionGetType()
    1325             :      */
    1326        2546 :     const std::string &GetType() const
    1327             :     {
    1328        2546 :         return m_osType;
    1329             :     }
    1330             : 
    1331             :     /** Return the axis direction.
    1332             :      *
    1333             :      * Predefined values are:
    1334             :      * EAST, WEST, SOUTH, NORTH, UP, DOWN, FUTURE, PAST
    1335             :      * Other values might be returned. Empty value means unknown.
    1336             :      *
    1337             :      * This is the same as the C function GDALDimensionGetDirection()
    1338             :      */
    1339        1104 :     const std::string &GetDirection() const
    1340             :     {
    1341        1104 :         return m_osDirection;
    1342             :     }
    1343             : 
    1344             :     /** Return the size, that is the number of values along the dimension.
    1345             :      *
    1346             :      * This is the same as the C function GDALDimensionGetSize()
    1347             :      */
    1348       75443 :     GUInt64 GetSize() const
    1349             :     {
    1350       75443 :         return m_nSize;
    1351             :     }
    1352             : 
    1353             :     virtual std::shared_ptr<GDALMDArray> GetIndexingVariable() const;
    1354             : 
    1355             :     virtual bool
    1356             :     SetIndexingVariable(std::shared_ptr<GDALMDArray> poIndexingVariable);
    1357             : 
    1358             :     virtual bool Rename(const std::string &osNewName);
    1359             : 
    1360             :     //! @cond Doxygen_Suppress
    1361             :     virtual void ParentRenamed(const std::string &osNewParentFullName);
    1362             : 
    1363             :     virtual void ParentDeleted();
    1364             :     //! @endcond
    1365             : 
    1366             :   protected:
    1367             :     //! @cond Doxygen_Suppress
    1368             :     std::string m_osName;
    1369             :     std::string m_osFullName;
    1370             :     std::string m_osType;
    1371             :     std::string m_osDirection;
    1372             :     GUInt64 m_nSize;
    1373             : 
    1374             :     void BaseRename(const std::string &osNewName);
    1375             : 
    1376             :     //! @endcond
    1377             : };
    1378             : 
    1379             : /************************************************************************/
    1380             : /*                    GDALDimensionWeakIndexingVar()                    */
    1381             : /************************************************************************/
    1382             : 
    1383             : //! @cond Doxygen_Suppress
    1384             : class CPL_DLL GDALDimensionWeakIndexingVar : public GDALDimension
    1385             : {
    1386             :     std::weak_ptr<GDALMDArray> m_poIndexingVariable{};
    1387             : 
    1388             :   public:
    1389             :     GDALDimensionWeakIndexingVar(const std::string &osParentName,
    1390             :                                  const std::string &osName,
    1391             :                                  const std::string &osType,
    1392             :                                  const std::string &osDirection, GUInt64 nSize);
    1393             : 
    1394             :     std::shared_ptr<GDALMDArray> GetIndexingVariable() const override;
    1395             : 
    1396             :     bool SetIndexingVariable(
    1397             :         std::shared_ptr<GDALMDArray> poIndexingVariable) override;
    1398             : 
    1399             :     void SetSize(GUInt64 nNewSize);
    1400             : };
    1401             : 
    1402             : //! @endcond
    1403             : 
    1404             : #endif

Generated by: LCOV version 1.14