# GDALExtendedDataType C++ API

## GDALExtendedDataType class

class GDALExtendedDataType

  Class used to represent potentially complex data types.

  Several classes of data types are supported: numeric (based on GDALDataType), compound or string.

  Since

    GDAL 3.1

  Public Functions

  GDALExtendedDataType(const GDALExtendedDataType&)

    Copy constructor.

  GDALExtendedDataType &operator=(GDALExtendedDataType&&)

    Move assignment.

  bool operator==(const GDALExtendedDataType&) const

    Equality operator.

    This is the same as the C function GDALExtendedDataTypeEquals().

  inline bool operator!=(const GDALExtendedDataType &other) const

    Non-equality operator.

  inline const std::string &GetName() const

    Return type name.

    This is the same as the C function GDALExtendedDataTypeGetName()

  inline GDALExtendedDataTypeClass GetClass() const

    Return type class.

    This is the same as the C function GDALExtendedDataTypeGetClass()

  inline GDALDataType GetNumericDataType() const

    Return numeric data type (only valid when GetClass() == GEDTC_NUMERIC)

    This is the same as the C function GDALExtendedDataTypeGetNumericDataType()

  inline GDALExtendedDataTypeSubType GetSubType() const

    Return subtype.

    This is the same as the C function GDALExtendedDataTypeGetSubType()

    Since

      3.4

  inline const std::vector<std::unique_ptr<GDALEDTComponent>> &GetComponents() const

    Return the components of the data type (only valid when GetClass() == GEDTC_COMPOUND)

    This is the same as the C function GDALExtendedDataTypeGetComponents()

  inline size_t GetSize() const

    Return data type size in bytes.

    For a string, this will be size of a char* pointer.

    This is the same as the C function GDALExtendedDataTypeGetSize()

  inline size_t GetMaxStringLength() const

    Return the maximum length of a string in bytes.

    0 indicates unknown/unlimited string.

  bool CanConvertTo(const GDALExtendedDataType &other) const

    Return whether this data type can be converted to the other one.

    This is the same as the C function GDALExtendedDataTypeCanConvertTo().

    Parameters

      other – Target data type for the conversion being considered.

  bool NeedsFreeDynamicMemory() const

    Return whether the data type holds dynamically allocated memory, that needs to be freed with FreeDynamicMemory().

  void FreeDynamicMemory(void *pBuffer) const

    Release the dynamic memory (strings typically) from a raw value.

    This is the same as the C function GDALExtendedDataTypeFreeDynamicMemory().

    Parameters

      pBuffer – Raw buffer of a single element of an attribute or array value.

  Public Static Functions

  static GDALExtendedDataType Create(GDALDataType eType)

    Return a new GDALExtendedDataType of class GEDTC_NUMERIC.

    This is the same as the C function GDALExtendedDataTypeCreate()

    Parameters

      eType – Numeric data type.

  static GDALExtendedDataType Create(const std::string &osName, size_t nTotalSize, std::vector<std::unique_ptr<GDALEDTComponent>> &&components)

    Return a new GDALExtendedDataType of class GEDTC_COMPOUND.

    This is the same as the C function GDALExtendedDataTypeCreateCompound()

    Parameters

      - osName – Type name.

      - nTotalSize – Total size of the type in bytes. Should be large enough to store all components.

      - components – Components of the compound type.

  static GDALExtendedDataType CreateString(size_t nMaxStringLength = 0, GDALExtendedDataTypeSubType eSubType = GEDTST_NONE)

    Return a new GDALExtendedDataType of class GEDTC_STRING.

    This is the same as the C function GDALExtendedDataTypeCreateString().

    Parameters

      - nMaxStringLength – maximum length of a string in bytes. 0 if unknown/unlimited

      - eSubType – Subtype.

  static bool CopyValue(const void *pSrc, const GDALExtendedDataType &srcType, void *pDst, const GDALExtendedDataType &dstType)

    Convert a value from a source type to a destination type.

    If dstType is GEDTC_STRING, the written value will be a pointer to a char*, that must be freed with CPLFree().

  static bool CopyValues(const void *pSrc, const GDALExtendedDataType &srcType, GPtrDiff_t nSrcStrideInElts, void *pDst, const GDALExtendedDataType &dstType, GPtrDiff_t nDstStrideInElts, size_t nValues)

    Convert severals value from a source type to a destination type.

    If dstType is GEDTC_STRING, the written value will be a pointer to a char*, that must be freed with CPLFree().

## GDALEDTComponent class

class GDALEDTComponent

  Class for a component of a compound extended data type.

  Since

    GDAL 3.1

  Public Functions

  GDALEDTComponent(const std::string &name, size_t offset, const GDALExtendedDataType &type)

    constructor of a GDALEDTComponent

    This is the same as the C function GDALEDTComponendCreate()

    Parameters

      - name – Component name

      - offset – Offset in byte of the component in the compound data type. In case of nesting of compound data type, this should be the offset to the immediate belonging data type, not to the higher level one.

      - type – Component data type.

  GDALEDTComponent(const GDALEDTComponent&)

    Copy constructor.

  bool operator==(const GDALEDTComponent&) const

    Equality operator.

  inline const std::string &GetName() const

    Return the name.

    This is the same as the C function GDALEDTComponentGetName().

  inline size_t GetOffset() const

    Return the offset (in bytes) of the component in the compound data type.

    This is the same as the C function GDALEDTComponentGetOffset().

  inline const GDALExtendedDataType &GetType() const

    Return the data type of the component.

    This is the same as the C function GDALEDTComponentGetType().