Help us improve by taking our short survey: https://www.hdfgroup.org/website-survey/

| HDF5 Last Updated on 2026-03-23 The HDF5 Field Guide

Loading...
Searching...
No Matches
DataSpace Class Reference

`#include <c++/src/H5DataSpace.h>`

## Detailed Description

Class DataSpace inherits from IdComponent and provides wrappers for the HDF5's dataspaces.

Inheritance diagram for DataSpace:

## Public Member Functions
virtual void | close () override
| Closes this dataspace.
void | copy (const DataSpace &like_space)
| Makes a copy of an existing dataspace.
| DataSpace (const DataSpace &original)
| Copy constructor: same HDF5 object as original.
| DataSpace (const hid_t space_id)
| Creates a DataSpace object using the id of an existing dataspace.
| DataSpace (H5S_class_t type=H5S_SCALAR)
| Creates a new dataspace given a dataspace type.
| DataSpace (int rank, const hsize_t *dims, const hsize_t *maxdims=NULL)
| Creates a new simple dataspace.
void | extentCopy (const DataSpace &dest_space) const
| Copies the extent of a dataspace.
virtual std::string | fromClass () const override
| Returns this class name.
virtual hid_t | getId () const override
| Get the id of this dataspace.
void | getSelectBounds (hsize_t *start, hsize_t *end) const
| Gets the bounding box containing the current selection.
hssize_t | getSelectElemNpoints () const
| Returns the number of element points in the current selection.
void | getSelectElemPointlist (hsize_t startpoint, hsize_t numpoints, hsize_t *buf) const
| Gets the list of element points currently selected.
void | getSelectHyperBlocklist (hsize_t startblock, hsize_t numblocks, hsize_t *buf) const
| Gets the list of hyperslab blocks currently selected.
hssize_t | getSelectHyperNblocks () const
| Returns number of hyperslab blocks.
hssize_t | getSelectNpoints () const
| Returns the number of elements in a dataspace selection.
int | getSimpleExtentDims (hsize_t *dims, hsize_t *maxdims=NULL) const
| Retrieves dataspace dimension size and maximum size.
int | getSimpleExtentNdims () const
| Returns the dimensionality of a dataspace.
hssize_t | getSimpleExtentNpoints () const
| Returns the number of elements in a dataspace.
H5S_class_t | getSimpleExtentType () const
| Returns the current class of a dataspace.
bool | isSimple () const
| Determines whether this dataspace is a simple dataspace.
void | offsetSimple (const hssize_t *offset) const
| Sets the offset of this simple dataspace.
DataSpace & | operator= (const DataSpace &rhs)
| Assignment operator.
void | selectAll () const
| Selects the entire dataspace.
void | selectElements (H5S_seloper_t op, const size_t num_elements, const hsize_t *coord) const
| Selects array elements to be included in the selection for this dataspace.
void | selectHyperslab (H5S_seloper_t op, const hsize_t *count, const hsize_t *start, const hsize_t *stride=NULL, const hsize_t *block=NULL) const
| Selects a hyperslab region to add to the current selected region.
void | selectNone () const
| Resets the selection region to include no elements.
bool | selectValid () const
| Verifies that the selection is within the extent of the dataspace.
void | setExtentNone () const
| Removes the extent from a dataspace.
void | setExtentSimple (int rank, const hsize_t *current_size, const hsize_t *maximum_size=NULL) const
| Sets or resets the size of an existing dataspace.
virtual | ~DataSpace () override
| Properly terminates access to this dataspace.
Public Member Functions inherited from IdComponent
void | decRefCount () const
| Decrement reference counter for the id of this object.
void | decRefCount (const hid_t obj_id) const
| Decrement reference counter for a given id.
int | getCounter () const
| Returns the reference counter for the id of this object.
int | getCounter (const hid_t obj_id) const
| Returns the reference counter for a given id.
H5I_type_t | getHDFObjType () const
| Returns the type of the object. It is an overloaded function of the above function.
void | incRefCount () const
| Increment reference counter for the id of this object.
void | incRefCount (const hid_t obj_id) const
| Increment reference counter for a given id.
std::string | inMemFunc (const char *func_name) const
| Makes and returns string "<class-name>::<func_name>".
IdComponent & | operator= (const IdComponent &rhs)
| Assignment operator.
void | setId (const hid_t new_id)
| Sets the identifier of this object to a new value.
virtual | ~IdComponent ()=default

## Static Public Member Functions
static void | deleteConstants ()
Static Public Member Functions inherited from IdComponent
static H5I_type_t | getHDFObjType (const hid_t obj_id)
| Given an id, returns the type of the object.
static hsize_t | getNumMembers (H5I_type_t type)
| Returns the number of members of the given type.
static bool | isValid (hid_t an_id)
| Checks if the given ID is valid.
static bool | typeExists (H5I_type_t type)
| Queries if a given type is currently registered with the library.

## Static Public Attributes
static const DataSpace & | ALL = *getConstant()
| Default DataSpace objects.

## Protected Member Functions
virtual void | p_setId (const hid_t new_id) override
| Sets the identifier of this object to a new value.
Protected Member Functions inherited from IdComponent
| IdComponent ()
| Default constructor.
std::string | p_get_file_name () const

## Friends
void | f_DataSpace_setId (DataSpace *dspace, hid_t new_id)

## Additional Inherited Members
Static Protected Member Functions inherited from IdComponent
static bool | p_valid_id (const hid_t obj_id)
Static Protected Attributes inherited from IdComponent
static bool | H5dontAtexit_called = false

## Constructor & Destructor Documentation

## ◆ DataSpace() [1/4]

DataSpace | ( | H5S_class_t | type = H5S_SCALAR | ) |

Creates a new dataspace given a dataspace type.

Parameters

  type | - IN: Type of the dataspace to be created, which currently can be either `H5S_SCALAR` or `H5S_SIMPLE`; default to `H5S_SCALAR`.

Exceptions

  H5::DataSpaceIException |

## ◆ DataSpace() [2/4]

DataSpace | ( | int | rank,
|  | const hsize_t * | dims,
|  | const hsize_t * | maxdims = NULL )

Creates a new simple dataspace.

Parameters

  rank | - IN: Number of dimensions of dataspace.
  dims | - IN: An array of the size of each dimension.
  maxdims | - IN: An array of the maximum size of each dimension.

Exceptions

  H5::DataSpaceIException |

## ◆ DataSpace() [3/4]

DataSpace | ( | const hid_t | existing_id | ) |

Creates a DataSpace object using the id of an existing dataspace.

Parameters

  existing_id | - IN: Id of an existing dataspace

Exceptions

  H5::DataSpaceIException |

## ◆ DataSpace() [4/4]

DataSpace | ( | const DataSpace & | original | ) |

Copy constructor: same HDF5 object as original.

Parameters

  original | - IN: DataSpace object to copy

## ◆ ~DataSpace()

~DataSpace | ( |  | ) |
| override virtual

Properly terminates access to this dataspace.

## Member Function Documentation

## ◆ close()

void close | ( |  | ) |
| override virtual

Closes this dataspace.

Exceptions

  H5::DataSpaceIException |

Implements IdComponent.

## ◆ copy()

void copy | ( | const DataSpace & | like_space | ) |

Makes a copy of an existing dataspace.

Parameters

  like_space | - IN: Dataspace to be copied

Exceptions

  H5::DataSpaceIException |

## ◆ deleteConstants()

void deleteConstants | ( |  | ) |
| static

## ◆ extentCopy()

void extentCopy | ( | const DataSpace & | dest_space | ) | const

Copies the extent of a dataspace.

Parameters

  dest_space | - IN: Dataspace to copy from

Exceptions

  H5::DataSpaceIException |

## ◆ fromClass()

virtual std::string fromClass | ( |  | ) | const
| override virtual

Returns this class name.

Reimplemented from IdComponent.

## ◆ getId()

hid_t getId | ( |  | ) | const
| override virtual

Get the id of this dataspace.

Returns
  Dataspace identifier

Implements IdComponent.

## ◆ getSelectBounds()

void getSelectBounds | ( | hsize_t * | start,
|  | hsize_t * | end ) const

Gets the bounding box containing the current selection.

Parameters

  start | - IN: Starting coordinates of the bounding box
  end | - IN: Ending coordinates of the bounding box, i.e., the coordinates of the diagonally opposite corner

Exceptions

  H5::DataSpaceIException |

Description
  For information, please refer to the H5Sget_select_bounds API in the HDF5 C Reference Manual.

## ◆ getSelectElemNpoints()

hssize_t getSelectElemNpoints | ( |  | ) | const

Returns the number of element points in the current selection.

Returns
  Number of element points

Exceptions

  H5::DataSpaceIException |

## ◆ getSelectElemPointlist()

void getSelectElemPointlist | ( | hsize_t | startpoint,
|  | hsize_t | numpoints,
|  | hsize_t * | buf ) const

Gets the list of element points currently selected.

Parameters

  startpoint | - IN: Element point to start with
  numpoints | - IN: Number of element points to get
  buf | - IN: List of element points selected

Exceptions

  H5::DataSpaceIException |

Description
  For information, please refer to the C API H5Sget_select_elem_pointlist in the HDF5 C Reference Manual.

## ◆ getSelectHyperBlocklist()

void getSelectHyperBlocklist | ( | hsize_t | startblock,
|  | hsize_t | numblocks,
|  | hsize_t * | buf ) const

Gets the list of hyperslab blocks currently selected.

Parameters

  startblock | - IN: Hyperslab block to start with
  numblocks | - IN: Number of hyperslab blocks to get
  buf | - IN: List of hyperslab blocks selected

Exceptions

  H5::DataSpaceIException |

## ◆ getSelectHyperNblocks()

hssize_t getSelectHyperNblocks | ( |  | ) | const

Returns number of hyperslab blocks.

Returns
  Number of hyperslab blocks

Exceptions

  H5::DataSpaceIException |

## ◆ getSelectNpoints()

hssize_t getSelectNpoints | ( |  | ) | const

Returns the number of elements in a dataspace selection.

Returns
  Number of elements

Exceptions

  H5::DataSpaceIException |

## ◆ getSimpleExtentDims()

int getSimpleExtentDims | ( | hsize_t * | dims,
|  | hsize_t * | maxdims = NULL ) const

Retrieves dataspace dimension size and maximum size.

Parameters

  dims | - IN: Name of the new member
  maxdims | - IN: Pointer to the value of the new member

Returns
  Number of dimensions, the same value as returned by `DataSpace::getSimpleExtentNdims()`

Exceptions

  H5::DataSpaceIException |

## ◆ getSimpleExtentNdims()

int getSimpleExtentNdims | ( |  | ) | const

Returns the dimensionality of a dataspace.

Returns
  Number of dimensions

Exceptions

  H5::DataSpaceIException |

## ◆ getSimpleExtentNpoints()

hssize_t getSimpleExtentNpoints | ( |  | ) | const

Returns the number of elements in a dataspace.

Returns
  Number of elements

Exceptions

  H5::DataSpaceIException |

## ◆ getSimpleExtentType()

H5S_class_t getSimpleExtentType | ( |  | ) | const

Returns the current class of a dataspace.

Returns
  Class of the dataspace

Exceptions

  H5::DataSpaceIException |

## ◆ isSimple()

bool isSimple | ( |  | ) | const

Determines whether this dataspace is a simple dataspace.

Returns
  `true` if the dataspace is a simple dataspace, and `false`, otherwise

Exceptions

  H5::DataSpaceIException |

## ◆ offsetSimple()

void offsetSimple | ( | const hssize_t * | offset | ) | const

Sets the offset of this simple dataspace.

Parameters

  offset | - IN: Offset to position the selection at

Exceptions

  H5::DataSpaceIException |

Description
  This function creates an offset for the selection within an extent, allowing the same shaped selection to be moved to different locations within a dataspace without requiring it to be re-defined.

## ◆ operator=()

DataSpace & operator= | ( | const DataSpace & | rhs | ) |

Assignment operator.

Parameters

  rhs | - IN: Reference to the existing dataspace

Returns
  Reference to DataSpace instance

Exceptions

  H5::DataSpaceIException |

## ◆ p_setId()

void p_setId | ( | const hid_t | new_id | ) |
| override protected virtual

Sets the identifier of this object to a new value.

Exceptions

  H5::IdComponentException | when the attempt to close the HDF5 object fails

Implements IdComponent.

## ◆ selectAll()

void selectAll | ( |  | ) | const

Selects the entire dataspace.

Exceptions

  H5::DataSpaceIException |

## ◆ selectElements()

void selectElements | ( | H5S_seloper_t | op,
|  | const size_t | num_elements,
|  | const hsize_t * | coord ) const

Selects array elements to be included in the selection for this dataspace.

Parameters

  op | - IN: Operator specifying how the new selection is to be combined with the existing selection for the dataspace
  num_elements | - IN: Number of elements to be selected
  coord | - IN: A 2-dimensional array of 0-based values specifying the coordinates of the elements being selected

Exceptions

  H5::DataSpaceIException |

Description
  For information, please refer to the H5Sselect_elements API in the HDF5 C Reference Manual.

## ◆ selectHyperslab()

void selectHyperslab | ( | H5S_seloper_t | op,
|  | const hsize_t * | count,
|  | const hsize_t * | start,
|  | const hsize_t * | stride = NULL,
|  | const hsize_t * | block = NULL ) const

Selects a hyperslab region to add to the current selected region.

Parameters

  op | - IN: Operation to perform on current selection
  count | - IN: Number of blocks included in the hyperslab
  start | - IN: Offset of the start of hyperslab
  stride | - IN: Hyperslab stride - default to `NULL`
  block | - IN: Size of block in the hyperslab - default to `NULL`

Exceptions

  H5::DataSpaceIException |

Description
  For information, please refer to the H5Sselect_hyperslab API in the HDF5 C Reference Manual.

## ◆ selectNone()

void selectNone | ( |  | ) | const

Resets the selection region to include no elements.

Exceptions

  H5::DataSpaceIException |

## ◆ selectValid()

bool selectValid | ( |  | ) | const

Verifies that the selection is within the extent of the dataspace.

Returns
  `true` if the selection is within the extent of the dataspace, and `false`, otherwise

Exceptions

  H5::DataSpaceIException |

## ◆ setExtentNone()

void setExtentNone | ( |  | ) | const

Removes the extent from a dataspace.

Exceptions

  H5::DataSpaceIException |

## ◆ setExtentSimple()

void setExtentSimple | ( | int | rank,
|  | const hsize_t * | current_size,
|  | const hsize_t * | maximum_size = NULL ) const

Sets or resets the size of an existing dataspace.

Parameters

  rank | - IN: Rank of the dataspace
  current_size | - IN: Array containing current size of dataspace
  maximum_size | - IN: Array containing maximum size of dataspace

Exceptions

  H5::DataSpaceIException |

## Friends And Related Symbol Documentation

## ◆ f_DataSpace_setId

void f_DataSpace_setId | ( | DataSpace * | dspace,
|  | hid_t | new_id )
| friend

## Field Documentation

## ◆ ALL

const DataSpace & ALL = *getConstant()
| static

Default DataSpace objects.

The documentation for this class was generated from the following files:

- c++/src/H5DataSpace.h
- c++/src/H5DataSpace.cpp