HighFive 2.10.0
HighFive - Header-only C++ HDF5 interface
Loading...
Searching...
No Matches
HighFive::Attribute Class Reference

Class representing an Attribute of a DataSet or Group. More...

#include <H5Attribute.hpp>

Inheritance diagram for HighFive::Attribute:
Collaboration diagram for HighFive::Attribute:

Public Member Functions

std::string getName () const
 Get the name of the current Attribute.
 
size_t getStorageSize () const
 The number of bytes required to store the attribute in the HDF5 file.
 
DataType getDataType () const
 Get the DataType of the Attribute.
 
DataSpace getSpace () const
 Get the DataSpace of the current Attribute.
 
DataSpace getMemSpace () const
 Get the DataSpace of the current Attribute.
 
template<typename T >
read () const
 Get the value of the Attribute.
 
template<typename T >
void read (T &array) const
 Get the value of the Attribute in a buffer.
 
template<typename T >
void read (T *array, const DataType &mem_datatype) const
 Read the attribute into a pre-allocated buffer.
 
template<typename T >
void read (T *array) const
 Read the attribute into a buffer.
 
template<typename T >
void read_raw (T *array, const DataType &mem_datatype) const
 Read the attribute into a pre-allocated buffer.
 
template<typename T >
void read_raw (T *array) const
 Read the attribute into a buffer. Behaves like Attribute::read(T*, const DataType&) const but additionally this overload deduces the memory datatype from T.
 
template<typename T >
void write (const T &value)
 Write the value into the Attribute.
 
template<typename T >
void write_raw (const T *buffer, const DataType &mem_datatype)
 Write from a raw pointer.
 
template<typename T >
void write_raw (const T *buffer)
 Write from a raw pointer.
 
AttributeCreateProps getCreatePropertyList () const
 The create property list used for this attribute.
 
 Attribute ()=delete
 
- Public Member Functions inherited from HighFive::Object
 Object (Object &&other) noexcept
 
 ~Object ()
 
bool isValid () const noexcept
 isValid
 
hid_t getId () const noexcept
 getId
 
ObjectInfo getInfo () const
 Retrieve several infos about the current object (address, dates, etc)
 
ObjectType getType () const
 Gets the fundamental type of the object (dataset, group, etc)
 
bool operator== (const Object &other) const noexcept
 
- Public Member Functions inherited from HighFive::PathTraits< Attribute >
 PathTraits ()
 
std::string getPath () const
 return the path to the current object
 
FilegetFile () const noexcept
 Return a reference to the File object this object belongs.
 

Static Public Attributes

static const ObjectType type = ObjectType::Attribute
 

Protected Member Functions

 Object (Object &&other) noexcept
 
 Object ()
 
 Object (const Object &other)
 
 Object (hid_t)
 
- Protected Member Functions inherited from HighFive::Object
 Object ()
 
 Object (const Object &other)
 
 Object (hid_t)
 
Objectoperator= (const Object &other)
 

Additional Inherited Members

- Protected Attributes inherited from HighFive::Object
hid_t _hid
 
- Protected Attributes inherited from HighFive::PathTraits< Attribute >
std::shared_ptr< File_file_obj
 

Detailed Description

Constructor & Destructor Documentation

◆ Attribute()

HighFive::Attribute::Attribute ( )
delete

Member Function Documentation

◆ getCreatePropertyList()

AttributeCreateProps HighFive::Attribute::getCreatePropertyList ( ) const
inline

The create property list used for this attribute.

Some of HDF5 properties/setting of an attribute are defined by a create property list. This method returns a copy of the create property list used during creation of the attribute.

auto acpl = attr.getCreatePropertyList();
// For example to create another attribute with the same properties.
file.createAttribute("foo", 42, acpl);
Since
2.5.0

◆ getDataType()

DataType HighFive::Attribute::getDataType ( ) const
inline

Get the DataType of the Attribute.

Attribute attr = dset.createAttribute<int>("foo", DataSpace(1, 2));
auto dtype = attr.getDataType(); // Will be an hdf5 type deduced from int
Class representing an Attribute of a DataSet or Group.
Definition H5Attribute.hpp:46
DataType getDataType() const
Get the DataType of the Attribute.
Definition H5Attribute_misc.hpp:37
Since
1.0

◆ getMemSpace()

DataSpace HighFive::Attribute::getMemSpace ( ) const
inline

Get the DataSpace of the current Attribute.

Note
This is an alias of getSpace().
Since
1.0

◆ getName()

std::string HighFive::Attribute::getName ( ) const
inline

Get the name of the current Attribute.

auto attr = dset.createAttribute<std::string>("my_attribute", DataSpace::From(string_list));
std::cout << attr.getName() << std::endl; // Will print "my_attribute"
static DataSpace From(const T &value)
Automatically deduce the DataSpace from a container/value.
Definition H5Dataspace_misc.hpp:128
Since
2.2.2

◆ getSpace()

DataSpace HighFive::Attribute::getSpace ( ) const
inline

Get the DataSpace of the current Attribute.

Attribute attr = dset.createAttribute<int>("foo", DataSpace(1, 2));
auto dspace = attr.getSpace(); // This will be a DataSpace of dimension 1 * 2
DataSpace getSpace() const
Get the DataSpace of the current Attribute.
Definition H5Attribute_misc.hpp:43
Since
1.0

◆ getStorageSize()

size_t HighFive::Attribute::getStorageSize ( ) const
inline

The number of bytes required to store the attribute in the HDF5 file.

size_t size = dset.createAttribute<int>("foo", DataSpace(1, 2)).getStorageSize();
size_t getStorageSize() const
The number of bytes required to store the attribute in the HDF5 file.
Definition H5Attribute_misc.hpp:33
Since
1.0

◆ Object() [1/4]

HighFive::Object::Object ( )
inlineprotected

◆ Object() [2/4]

HighFive::Object::Object ( const Object & other)
inlineprotected

◆ Object() [3/4]

HighFive::Object::Object ( hid_t hid)
inlineexplicitprotected

◆ Object() [4/4]

HighFive::Object::Object ( Object && other)
inlineprotectednoexcept

◆ read() [1/4]

template<typename T >
T HighFive::Attribute::read ( ) const
inline

Get the value of the Attribute.

Attribute attr = dset.getAttribute("foo");
// The value will contains what have been written in the attribute
std::vector<int> value = attr.read<std::vector<int>>();
T read() const
Get the value of the Attribute.
Definition H5Attribute_misc.hpp:54
Since
2.5.0

◆ read() [2/4]

template<typename T >
void HighFive::Attribute::read ( T & array) const
inline

Get the value of the Attribute in a buffer.

Read the attribute into an existing object. Only available for supported types T. If array has preallocated the correct amount of memory, then this routine should not trigger reallocation. Otherwise, if supported, the object will be resized.

An exception is raised if the numbers of dimension of the buffer and of the attribute are different.

// Will read into `value` avoiding memory allocation if the dimensions
// match, i.e. if the attribute `"foo"` has three element.
std::vector<int> value(3);
file.getAttribute("foo").read(value);
Since
1.0

◆ read() [3/4]

template<typename T >
void HighFive::Attribute::read ( T * array) const
inline

Read the attribute into a buffer.

Deprecated
use read(T& or read_raw.

◆ read() [4/4]

template<typename T >
void HighFive::Attribute::read ( T * array,
const DataType & mem_datatype ) const
inline

Read the attribute into a pre-allocated buffer.

Deprecated
use read(T& or read_raw.

◆ read_raw() [1/2]

template<typename T >
void HighFive::Attribute::read_raw ( T * array) const
inline

Read the attribute into a buffer. Behaves like Attribute::read(T*, const DataType&) const but additionally this overload deduces the memory datatype from T.

Parameters
arrayPointer to the first byte of pre-allocated memory.
Note
If possible prefer either Attribute::read() const or Attribute::read(T&) const.
auto attr = file.getAttribute("foo");
// Simulate custom allocation by the application.
size_t n_elements = attr.getSpace().getElementCount();
int * ptr = (int*) malloc(n_elements*sizeof(int));
// Read into the pre-allocated memory.
attr.read(ptr);
Since
2.2.2

◆ read_raw() [2/2]

template<typename T >
void HighFive::Attribute::read_raw ( T * array,
const DataType & mem_datatype ) const
inline

Read the attribute into a pre-allocated buffer.

Parameters
arrayA pointer to the first byte of sufficient pre-allocated memory.
mem_datatypeThe DataType of the array.
Note
This is the shallowest wrapper around H5Aread. If possible prefer either Attribute::read() const or Attribute::read(T&) const.
auto attr = file.getAttribute("foo");
// Simulate custom allocation by the application.
size_t n_elements = attr.getSpace().getElementCount();
int * ptr = (int*) malloc(n_elements*sizeof(int));
// Read into the pre-allocated memory.
attr.read(ptr, mem_datatype);
Since
2.2.2

◆ write()

template<typename T >
void HighFive::Attribute::write ( const T & value)
inline

Write the value into the Attribute.

Write the value to the attribute. For supported types T, this overload will write the value to the attribute. The datatype and dataspace are deduced automatically. However, since the attribute has already been created, the dimensions of value must match those of the attribute.

// Prefer the fused version if creating and writing the attribute
// at the same time.
dset.createAttribute("foo", std::vector<int>{1, 2, 3});
// To overwrite the value:
std::vector<int> value{4, 5, 6};
dset.getAttribute<int>("foo").write(value);
void write(const T &value)
Write the value into the Attribute.
Definition H5Attribute_misc.hpp:131
Since
1.0

◆ write_raw() [1/2]

template<typename T >
void HighFive::Attribute::write_raw ( const T * buffer)
inline

Write from a raw pointer.

Much like Attribute::write_raw(const T*, const DataType&). Additionally, this overload attempts to automatically deduce the datatype of the buffer. Note, that the file datatype is already set.

Parameters
bufferPointer to the first byte.
Note
If possible prefer Attribute::write.
// Simulate the application creating `value` and only exposing access
// to the raw pointer `ptr`.
std::vector<std::array<int, 3>> value{{1, 2, 3}, {4, 5, 6}};
int * ptr = (int*) value.data();
// Simply write the bytes to disk.
attr.write(ptr);
Since
2.2.2

◆ write_raw() [2/2]

template<typename T >
void HighFive::Attribute::write_raw ( const T * buffer,
const DataType & mem_datatype )
inline

Write from a raw pointer.

Values that have been correctly arranged memory, can be written directly by passing a raw pointer.

Parameters
bufferPointer to the first byte of the value.
mem_datatypeThe DataType of the buffer.
Note
This is the shallowest wrapper around H5Awrite. It's useful if you need full control. If possible prefer Attribute::write.
Attribute attr = dset.createAttribute<int>("foo", DataSpace(2, 3));
// Simulate the application creating `value` and only exposing access
// to the raw pointer `ptr`.
std::vector<std::array<int, 3>> value{{1, 2, 3}, {4, 5, 6}};
int * ptr = (int*) value.data();
// Simply write the bytes to disk.
attr.write(ptr, AtomicType<int>());
Since
2.2.2

Member Data Documentation

◆ type

const ObjectType HighFive::Attribute::type = ObjectType::Attribute
static

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