h5cpp  0.5.2
A modern C++ wrapper for the HDF5 C library
hdf5::attribute::Attribute Class Reference

#include <attribute.hpp>

Public Member Functions

 Attribute (ObjectHandle &&handle, const node::Link &parent_link)
 constructor More...
 
 Attribute ()=default
 default constructor More...
 
datatype::Datatype datatype () const
 return the data type of the attribute More...
 
dataspace::Dataspace dataspace () const
 return the dataspace of the attribute More...
 
std::string name () const
 return the name of the attribute More...
 
bool is_valid () const
 check if object is valid More...
 
void close ()
 close the attribute More...
 
 operator hid_t () const
 conversion operator to hid_t More...
 
const node::Linkparent_link () const noexcept
 get the parent ndoe More...
 
template<typename T >
void write (const T &data) const
 write data to attribute More...
 
void write (const char *data) const
 write string literal to disk More...
 
template<typename T >
void write (const std::initializer_list< T > &list) const
 write from initializer list More...
 
template<typename T >
void write (const T &data, const datatype::Datatype &mem_type) const
 write data to disk More...
 
void write (const char *data, const datatype::Datatype &mem_type) const
 
template<typename T >
void read (T &data) const
 
template<typename T >
void read (T &data, const datatype::Datatype &mem_type) const
 

Constructor & Destructor Documentation

◆ Attribute() [1/2]

hdf5::attribute::Attribute::Attribute ( ObjectHandle &&  handle,
const node::Link parent_link 
)
Parameters
handlervalue reference to the attributes handle
parent_linklike to the parent object

◆ Attribute() [2/2]

hdf5::attribute::Attribute::Attribute ( )
default

Uses default compiler implementation.

Member Function Documentation

◆ close()

void hdf5::attribute::Attribute::close ( )

This method will close the attribute and leave it in an invalid state. A subsequent call to is_valid should return false. The parent link remains valid though.

◆ dataspace()

dataspace::Dataspace hdf5::attribute::Attribute::dataspace ( ) const

Returns the dataspace used to create the attribute.

◆ datatype()

datatype::Datatype hdf5::attribute::Attribute::datatype ( ) const

Returns a copy of the datatype used to create the attribute.

◆ is_valid()

bool hdf5::attribute::Attribute::is_valid ( ) const

◆ name()

std::string hdf5::attribute::Attribute::name ( ) const

◆ operator hid_t()

hdf5::attribute::Attribute::operator hid_t ( ) const
inline

◆ parent_link()

const node::Link& hdf5::attribute::Attribute::parent_link ( ) const
noexcept

Return a reference to the node to which the attribute is attached.

◆ read() [1/2]

template<typename T >
void hdf5::attribute::Attribute::read ( T &  data) const

◆ read() [2/2]

template<typename T >
void hdf5::attribute::Attribute::read ( T &  data,
const datatype::Datatype mem_type 
) const

◆ write() [1/5]

void hdf5::attribute::Attribute::write ( const char *  data) const

This is used whenever a string literal must be written to disk.

attribute::Attribute a = dataset.attributes.create<std::string>("note");
a.write("a short text");

You should be aware that this currently only works if the string type used for the attribute is a variable length string.

Exceptions
std::runtime_errorin case of a failure

◆ write() [2/5]

void hdf5::attribute::Attribute::write ( const char *  data,
const datatype::Datatype mem_type 
) const

◆ write() [3/5]

template<typename T >
void hdf5::attribute::Attribute::write ( const std::initializer_list< T > &  list) const
inline

This method is used if the data to write is provided via an initializer list.

Attribute a = dataset.attributes.create<int>("index_list",{4});
a.write({56,23,4,12});
Attribute()=default
default constructor

Internaly this method stores the content of the list to an instance of std::vector<T> which is then written to the attribute.

Template Parameters
Ttype of the list elements
Parameters
listreference to the initializer list

◆ write() [4/5]

template<typename T >
void hdf5::attribute::Attribute::write ( const T &  data) const

Write data to disk. This is the simplest form of writting datat to disk. Its only argument is a reference to the object holding the data which should be written.

Exceptions
std::runtime_errorin case of a failure
Template Parameters
Tdata type to write to disk
Parameters
datareference to the datas instance

◆ write() [5/5]

template<typename T >
void hdf5::attribute::Attribute::write ( const T &  data,
const datatype::Datatype mem_type 
) const

Write data to disk however we can pass a custom memory type to this method. This is particularly useful in the case of string types where the HDF5 datatype cannot be determined uniquely from a C++ type.

String fixed_type = String::fixed(20);
Attribute a = dataset.attributes.create("note",fixed_type,Scalar());
//we have to pass the type here explicitely otherwise the library
//would take std::string as a variable length string and HDF5
//considers variable and fixed length strings as incompatible.
std::string data = "hello";
a.write(data,fixed_type);
@ String
indicates a string type
Exceptions
std::runtime_errorin case of an error
Template Parameters
Ttype of input data
Parameters
datarefernce to input data
mem_typeHDF5 memory type of the input data

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