Namespace hdf5::datatype

Classes

Datatype

class Datatype

base class for all data types

Subclassed by hdf5::datatype::Array, hdf5::datatype::Compound, hdf5::datatype::Enum, hdf5::datatype::Float, hdf5::datatype::Integer, hdf5::datatype::String, hdf5::datatype::VLengthArray

Public Functions

virtual ~Datatype()

destructor

Must be virtual for inheritance.

Datatype() = default

default constructor

Use default compiler implementation here. This will leave datatype as an invalid HDF5 object. For a default constructed datatype the class is NONE.

See also

is_valid()

Datatype(ObjectHandle &&handle)

constructor

Construct a datatype from an HDF5 object handle.

Throws

std::runtime_error – in case of a failure

Parameters

handle – rvalue reference to the original handle

Datatype(Datatype &&type) = default

move constructor

Use default implementation here.

Datatype(const Datatype &type)

copy constructor

Use default compiler implementation.

Datatype &operator=(const Datatype &type)

copy assignment

Use default compiler implementation here.

Datatype &operator=(Datatype &&type) = default

move assignment

Use default compiler implementation here.

Class get_class() const

returns the datatypes class

Throws

std::runtime_error – in case of a failure

Datatype super() const

get the base type

For an array type this will return the base type of the elements of the array. For an enumeration type it will return the underlying integer type.

Throws

std::runtime_error – in case of a failure

Datatype native_type(Direction dir = Direction::Ascend) const

get native type

Returns the native type associated with a particular data type.

Throws

std::runtime_error – in case of a failure

bool has_class(Class type_class) const

search for a type class

Checks if a type contains a particular type class.

virtual size_t size() const

get size of type in bytes

Throws

std::runtime_error – in case of a failure

virtual void size(size_t size) const

set the size of a type in bytes

Throws

std::runtime_error – in case of a failure

bool is_valid() const

check status of the object

Returns true if the instance is a valid HDF5 object, otherwise it returns false. This can be used to check whether or not an instance has been default constructed (in which case flase will be returned).

bool hdf5::datatype::operator==(const Datatype &lhs, const Datatype &rhs)

equality check for datatypes

Returns if two datatypes are equal. Datatypes are considered equal if they represent the same type.

Parameters
  • lhs – reference to the left handside Datatype instance

  • rhs – reference to the right handside Datatype instance

Returns

true if instances are considered equal, false otherwise

bool hdf5::datatype::operator!=(const Datatype &lhs, const Datatype &rhs)

inequality check for datatypes

Returns true if both datatypes do not represent the same types.

Parameters
  • lhs – reference to the left hand-side Datatype instance

  • rhs – reference to the right hand-side Datatype instance

Returns

true if datatypes are not equal, false otherwise

Array

class Array : public hdf5::datatype::Datatype

array datatype

This datatype allows storing multidimensional data as a single element in an dataspace layout. Typical applications would be to use this for tensors and vectors. This is a fixed size data type. All instances (elements) of this type stored in an attribute or dataset are of equal size.

Public Functions

Array(ObjectHandle &&handle)

construct from handle

Array(const Datatype &type)

cosntruct from generic datatype

Dimensions dimensions() const

get dimensions

Returns an instance of Dimensions with the number of elements along each dimension.

Throws

std::runtime_error – in case of a failure

size_t rank() const

get rank

Returns the number of dimensions for an array data type

Throws

std::runtime_error – in case of a failure

Public Static Functions

static Array create(const Datatype &base_type, const Dimensions &dims)

named constructor

VLengthArray

class VLengthArray : public hdf5::datatype::Datatype

variable length array type

Array datatype allowing each element stored in a dataspace having a different size. This type is restricted to a single dimensions. This limitation makes sense as it does not make to much sense to think about multidimensional objects of different size stored in an attribute or dataset.

Public Functions

VLengthArray() = default

default constructor

This constructor is required for compatibility purposes with STL containers.

VLengthArray(ObjectHandle &&handle)

construct from handle

VLengthArray(const Datatype &type)

cosntruct from generic datatype

Public Static Functions

static VLengthArray create(const Datatype &base_type)

constructor

Parameters

base_type – the base type for the variable length type

Compound

class Compound : public hdf5::datatype::Datatype

compound data type

A compound data type which can be used for data elements of heterogeneous type like C-structures or a C++ class.

Public Functions

Compound() = default

default constructor

Compound(ObjectHandle &&handle)

construct from handle

Compound(const Datatype &type)

construct from generic datatype

Datatype operator[](size_t index) const

return the datatype for index element

Datatype operator[](const std::string &name) const

return the datatype for element name

size_t field_index(const std::string &name) const

return the index of a type element

size_t number_of_fields() const

return the total number of elements of the type

Public Static Functions

static Compound create(size_t size)

constructor

String

class String : public hdf5::datatype::Datatype

string datatype

This type can be used to represent fixed length or variable length strings.

Public Functions

String() = default

default constructor

We need this for STL containers but can rely on the default compiler implementation for now.

String(ObjectHandle &&handle)

construct from handle

String(const Datatype &type)

construct from generic datatype instance

Throws

std::runtime_error – if the datatype is not a string type

bool is_variable_length() const

return true if type is a variable length string

Throws

std::runtime_error – in case of a failure

CharacterEncoding encoding() const

get current character encoding for the string

Throws

std::runtime_error – in case of a failure

void encoding(CharacterEncoding cset)

set current character encoding

Throws

std::runtime_error – in case of a failure

StringPad padding() const

get the current string padding

Throws

std::runtime_error – in case of a failure

void padding(StringPad strpad)

set the string padding for the type

Throws

std::runtime_error – in case of a failure

virtual size_t size() const override

get current size of the string type

Throws

std::runtime_error – in case of a failure

virtual void size(size_t size) const override

set the string size (number of characters)

There are two conditions which must be met in order for this function to succeed:

  • the String instance must not be a variable length type

  • the size must not be 0

Throws

std::runtime_error – in case of a failure

Parameters

size – the new size for the fixed length string type

Public Static Functions

static String variable()

construct variable-length string

static String fixed(size_t size)

construct fixed-length string

Return an instance of String for a fixed length string. The size of the string must not be 0 as this would not make any sense at all.

Throws

std::runtime_error – in the case of a failure

Parameters

size – the size of the new string type

Enum

class Enum : public hdf5::datatype::Datatype

compound data type

An enum data type which can be used to save enum values along with metadata describing their meaning.

Public Functions

Enum() = default

default constructor

explicit Enum(ObjectHandle &&handle)

construct from handle

explicit Enum(const Datatype &type)

construct from generic datatype

template<typename T>
void insert(const std::string &name, const T &data) const

insert enum value definition (with underlying type deduction)

size_t number_of_values() const

return the total number of enum values

std::string name(size_t index) const

get value name

template<typename T>
T value(size_t index) const

get value at index (with underlying type deduction)

template<typename T>
T value(const std::string &name) const

get value by name (with underlying type deduction)

template<typename T>
void insert_underlying(const std::string &name, const T &data) const

insert enum value definition

template<typename T>
void underlying_value(size_t index, T &data) const

get value at index

template<typename T>
void underlying_value(const std::string &name, T &data) const

get value by name

Public Static Functions

template<typename T>
static Enum create(const T&)

named constructor (with underlying type deduction)

static Enum create_underlying(const Datatype &base_type)

named constructor from underlying datatype

Integer

class Integer : public hdf5::datatype::Datatype

HDF5 integer datatype.

Public Functions

Integer() = default

Default constructor.

We need this for compatability with STL containers. However, we can use the compiler provided default version.

Integer(ObjectHandle &&handle)

Construct from object handle.

Construct a type from an object handle. The datatype takes full ownership of the handle whose lifetime is thus bound to the lifetime of the type.

Parameters

handle – rvalue reference to a new object handle.

Integer(const Datatype &datatype)

Copy construction from a Datatype instance.

This copy constructor creates an integer type from an instance of Datatype. The datatype has to satisfy two conditions

  • it must be a valid object (is_valid() shoudld return true)

  • it must reference an integer datatype.

Failure to satify one of the above conditions will cause an exception.

Throws

std::runtime_error – in case of any failure

Parameters

datatype – reference to a Datatype instance

virtual bool is_signed() const

Retrieves the sign type for an integer type.

Throws

std::runtime_error – in case of a failure

virtual void make_signed(bool sign) const

Sets the sign property for an integer type.

Throws

std::runtime_error – in case of a failure

virtual size_t precision() const

get the precision of type, i.e. the number of significant bits

Throws

std::runtime_error – in case of a failure

virtual void precision(size_t precision) const

set the precision of a type, i.e. the number of significant bits

Throws

std::runtime_error – in case of a failure

virtual size_t offset() const

get the bit offset of the first significant bit

Throws

std::runtime_error – in case of a failure

virtual void offset(size_t offset) const

set the bit offset of the first significant bit

Throws

std::runtime_error – in case of a failure

virtual Order order() const

get the order of datatype

Throws

std::runtime_error – in case of a failure

virtual void order(Order offset) const

set the order of datatype

Throws

std::runtime_error – in case of a failure

virtual const std::vector<Pad> pad() const

get the pads of datatype

Throws

std::runtime_error – in case of a failure

Returns

least and most significant bits

virtual void pad(Pad lsb, Pad msb) const

set the pads of datatype

Parameters
  • lsb – padding type for least-significant bits

  • msb – padding type for most-significant bits

Throws

std::runtime_error – in case of a failure

Float

class Float : public hdf5::datatype::Datatype

Public Functions

Float() = default

default constructor

Need this for compliance with STL containers but we can use the default implementation of the compiler.

Float(ObjectHandle &&handle)

constructor

Parameters

handle – rvalue reference to an HDF5 object handle

explicit Float(const Datatype &datatype)

constructor

Conversion constructor which allows creation of a Float type from a generic Datatype instance. If datatype does not reference a float datatype an exception is thrown.

Throws

std::runtime_error – in case of a failure

Parameters

datatype – reference to a generic datatype instance

virtual size_t precision() const

get the precision of type, i.e. the number of significant bits

Throws

std::runtime_error – in case of a failure

virtual void precision(size_t precision) const

set the precision of a type, i.e. the number of significant bits

Throws

std::runtime_error – in case of a failure

virtual size_t offset() const

get the bit offset of the first significant bit

Throws

std::runtime_error – in case of a failure

virtual void offset(size_t offset) const

set the bit offset of the first significant bit

Throws

std::runtime_error – in case of a failure

virtual Order order() const

get the order of datatype

Throws

std::runtime_error – in case of a failure

virtual void order(Order order) const

set the order of datatype

Throws

std::runtime_error – in case of a failure

virtual const std::vector<Pad> pad() const

get the pads of datatype

Throws

std::runtime_error – in case of a failure

Returns

least and most significant bits

virtual void pad(Pad lsb, Pad msb) const

set the pads of datatype

Parameters
  • lsb – padding type for least-significant bits

  • msb – padding type for most-significant bits

Throws

std::runtime_error – in case of a failure

virtual const std::vector<size_t> fields() const

get the floating point datatype bit field information

Throws

std::runtime_error – in case of a failure

Returns

floating point datatype bit field information, i.e. floating-point sign bit, exponent bit-position, size of exponent in bits mantissa bit-position, size of mantissa in bits

virtual void fields(size_t spos, size_t epos, size_t esize, size_t mpos, size_t msize) const

set the floating point datatype bit field information

Parameters
  • spos – floating-point sign bit

  • epos – exponent bit-position

  • esize – size of exponent in bits

  • mpos – mantissa bit-position

  • msize – size of mantissa in bits

Throws

std::runtime_error – in case of a failure

virtual size_t ebias() const

get the exponent bias of a floating-point type

Throws

std::runtime_error – in case of a failure

virtual void ebias(size_t ebias) const

set the exponent bias of a floating-point type

Throws

std::runtime_error – in case of a failure

virtual Norm norm() const

get the mantissa normalization of a floating-point datatype

Throws

std::runtime_error – in case of a failure

virtual void norm(Norm norm) const

set the mantissa normalization of a floating-point datatype

Throws

std::runtime_error – in case of a failure

virtual Pad inpad() const

get the internal padding type for unused bits in floating-point datatypes

Throws

std::runtime_error – in case of a failure

virtual void inpad(Pad inpad) const

set the internal padding type for unused bits in floating-point datatypes

Throws

std::runtime_error – in case of a failure

float16_t

class float16_t

Public Functions

inline float16_t()

default constructor

inline float16_t(uint16_t v)

conversion constructor

inline operator uint16_t() const

conversion operator

DatatypeHolder

class DatatypeHolder

data type object holder

Public Functions

template<typename T>
const Datatype &get(const T &v = T{})

factory holder method for getting reference of data types

Returns data type reference for static data type object if available. Otherwise it creates a new data type object and returns its reference.

Parameters

v – provided datatype data

Returns

data type reference for data type object

Type traits

TypeTrait

template<typename T>
class TypeTrait

trait to create HDF5 datatypes

This trait provides a static function which creates a new HDF5 data type for a particular C++ type.

Specializations for this template exist for the following native types

  • char, unsigned char, singed char

  • double

Template Parameters

T – type for which to create a new HDF5 data type

Public Types

using TypeClass = Datatype

subtype of Datatype which will be used

Public Static Functions

static TypeClass create(const T& = T())

create the new type instance

static const TypeClass &get(const T& = T())

reference to const static type instance

Enumerations

EBool

enum hdf5::datatype::EBool

enumeration bool type

Values:

enumerator False

indicates a false value

enumerator True

indicates a true value

bool hdf5::datatype::is_bool(const Enum &etype)

check if Enum is EBool

Parameters

etype – object

Returns

if Enum is EBool flag

Order

enum class hdf5::datatype::Order : std::underlying_type<H5T_order_t>::type

enumeration type for byte order

Values:

enumerator LE

littlen endian type

enumerator BE

big endian type

enumerator Vax
enumerator None
std::ostream &hdf5::datatype::operator<<(std::ostream &stream, const Order &o)

output stream operator for the Order enumeration

Parameters
  • stream – reference to the output stream

  • o – reference to an Order enumeration instance

Returns

modified output stream

Sign

enum class hdf5::datatype::Sign : std::underlying_type<H5T_sign_t>::type

enumeration for sign

Values:

enumerator TwosComplement

indicates a signed type

enumerator Unsigned

indicates an unsigned type

std::ostream &hdf5::datatype::operator<<(std::ostream &stream, const Sign &s)

output stream for Sign enumeration

Parameters
  • stream – reference to the output stream

  • s – reference to the Sign enumeration

Returns

modified output stream

Norm

enum class hdf5::datatype::Norm : std::underlying_type<H5T_norm_t>::type

enumeration describes mantissa norm

Values:

enumerator Implied
enumerator MSBSet
enumerator None
std::ostream &hdf5::datatype::operator<<(std::ostream &stream, const Norm &n)

stream output operator for the Norm enumeration

Parameters
  • stream – reference to the output stream

  • n – refernece to a Norm enumeration instance

Returns

modified ouput stream

Pad

enum class hdf5::datatype::Pad : std::underlying_type<H5T_pad_t>::type

enumeration for floating point padding

Values:

enumerator Zero
enumerator One
enumerator Background
std::ostream &hdf5::datatype::operator<<(std::ostream &stream, const Pad &p)

stream output operator for Pad enumerations

Parameters
  • stream – reference to the output stream

  • p – reference to a Pad enumeratino instance

Returns

modified output stream

StringPad

enum class hdf5::datatype::StringPad : std::underlying_type<H5T_str_t>::type

enumeration determining string padding

Values:

enumerator NullTerm

indicates a null terminated string type

enumerator NullPad

indicates a null padded string type

enumerator SpacePad

indicates a space padded string type

std::ostream &hdf5::datatype::operator<<(std::ostream &stream, const StringPad &pad)

stream output operator for StringPad enumerations

Parameters
  • stream – reference to an output stream

  • pad – reference to a StringPad enumeration instance

Returns

modified output stream

Direction

enum class hdf5::datatype::Direction : std::underlying_type<H5T_direction_t>::type

Values:

enumerator Ascend
enumerator Descend
std::ostream &hdf5::datatype::operator<<(std::ostream &stream, const Direction &d)

stream output operator for Direction enumerations

Parameters
  • stream – reference to an output stream

  • d – reference to a Direction enumeration instance

Returns

modified output stream

CharacterEncoding

enum class hdf5::datatype::CharacterEncoding : std::underlying_type<H5T_cset_t>::type

character set encoding

Enumeration type determining the character encoding used by string types and links.

Values:

enumerator ASCII

ASCII.

enumerator UTF8

UTF8.

std::ostream &hdf5::datatype::operator<<(std::ostream &stream, const CharacterEncoding &enc)

stream output operator for CharacterEncoding enumerations

Parameters
  • stream – reference to an output stream

  • enc – reference to a CharacterEncoding enumeration instance

Returns

modified output stream

Class

enum class hdf5::datatype::Class : std::underlying_type<H5T_class_t>::type

data type class

Enumeration type describing the class a particular data type belongs to.

Values:

enumerator None

indicates a non-type

enumerator Integer

indicates an integer type

enumerator Float

indicates a float type

enumerator Time

indicates a time type

enumerator String

indicates a string type

enumerator BitField

indicates a bitfield type

enumerator Opaque

indicates an opaque type

enumerator Compound

indicates a compound type

enumerator Reference

indicates a reference type

enumerator Enum

indicates an enumeration type

enumerator VarLength

indicates a variable length type

enumerator Array

indicates an array type

std::ostream &hdf5::datatype::operator<<(std::ostream &stream, const Class &c)

stream output operator for the Class enumeration

Parameters
  • stream – reference to the output stream

  • c – reference to the class enumeration

Returns

modified output stream