Namespace hdf5::attribute
¶
Classes¶
Attribute
¶
-
class hdf5::attribute::Attribute¶
Public Functions
-
Attribute(ObjectHandle &&handle, const node::Link &parent_link)¶
constructor
- Parameters
handle – rvalue reference to the attributes handle
parent_link – like to the parent object
-
Attribute() = default¶
default constructor
Uses default compiler implementation.
-
datatype::Datatype datatype() const¶
return the data type of the attribute
Returns a copy of the datatype used to create the attribute.
-
dataspace::Dataspace dataspace() const¶
return the dataspace of the attribute
Returns the dataspace used to create the attribute.
-
std::string name() const¶
return the name of the attribute
-
bool is_valid() const¶
check if object is valid
-
void close()¶
close the attribute
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.
-
inline operator hid_t() const¶
conversion operator to hid_t
-
const node::Link &parent_link() const noexcept¶
get the parent ndoe
Return a reference to the node to which the attribute is attached.
-
template<typename T>
void write(const T &data) const¶ write data to attribute
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.
- Throws
std::runtime_error – in case of a failure
- Template Parameters
T – data type to write to disk
- Parameters
data – reference to the datas instance
-
void write(const char *data) const¶
write string literal to disk
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.
- Throws
std::runtime_error – in case of a failure
-
template<typename T>
inline void write(const std::initializer_list<T> &list) const¶ write from initializer list
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});
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
T – type of the list elements
- Parameters
list – reference to the initializer list
-
template<typename T>
void write(const T &data, const datatype::Datatype &mem_type) const¶ write data to disk
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);
- Throws
std::runtime_error – in case of an error
- Template Parameters
T – type of input data
- Parameters
data – refernce to input data
mem_type – HDF5 memory type of the input data
-
Attribute(ObjectHandle &&handle, const node::Link &parent_link)¶
AttributeManager
¶
-
class hdf5::attribute::AttributeManager¶
provides STL interface for attributes
The AttributeManager class provides an STL compliant interface to access attribute attached to a Node.
Public Functions
-
AttributeManager(node::Node &node)¶
constructor
Creates a new instance of AttributeManager which must be attached to a Node instance.
- Throws
std::runtime_error – in case of a failure
- Parameters
node – reference to the parent node of the manager
-
AttributeManager(const AttributeManager &manager) = default¶
copy constructor
Use the compiler provided default implementation here.
-
size_t size() const¶
get number of attributes
-
void remove(const std::string &name) const¶
remove attribute by name
-
void remove(size_t index) const¶
remove attribute by index
- Throws
std::runtime_error – in case of a failure
- Pre
index
must be < size()
-
bool exists(const std::string &name) const¶
check existence
Returns true if an attribute of given name exists. Otherwise false is returned.
-
void rename(const std::string &old_name, const std::string &new_name) const¶
rename an attribute
- Throws
std::runtime_error – in case of a failure
- Parameters
old_name – old name of the attribute
new_name – new name of the attribute
-
Attribute create(const std::string &name, const datatype::Datatype &datatype, const dataspace::Dataspace &dataspace, const property::AttributeCreationList &acpl = property::AttributeCreationList()) const¶
create an attribute
This is the most generic method to create attributes. See the template method below for more simple construction.
-
template<typename T>
Attribute create(const std::string &name, const property::AttributeCreationList &acpl = property::AttributeCreationList()) const¶ create scalar attribute
Create a scalar attribute of given name. The datatype is determined from the templat parameter.
- Throws
std::runtime_error – in case of an error
- Template Parameters
T – element data type of the attribute
- Parameters
name – the name of the attribute
acpl – attribute creation property list
- Returns
instance of the newly created attribute
-
template<typename T>
Attribute create(const std::string &name, const Dimensions &shape, const property::AttributeCreationList &acpl = property::AttributeCreationList()) const¶ create a multidimensional attribute
Create a multidimensional attribute of given name and shape. The datatype is derived from the template parameter.
- Throws
std::runtime_error – in case of a failure
- Template Parameters
T – element data type
- Parameters
name – the name for the attribute
shape – the number of elements along each dimension
acpl – attribute creation property list
- Returns
instance of the newly created attribute
-
template<typename T>
Attribute create_from(const std::string &name, const T &value)¶ create a new attribute of a given value
This is a convenience method to create a new attribute with a given value. Technically this is a create() including a subsequent call to write.
Node n = ....; n.attributes.create_from("date","12-03-2017");
- Throws
std::runtime_error – in case of a failure
- Parameters
name – the name of the attribute
value – reference to the new value
- Returns
new instance of Attribute
-
IteratorConfig &iterator_config() noexcept¶
get iterator configuration
Use this method to get a reference to the iterator configuration for the attributes of a node.
- Returns
reference to iterator configuration
-
const node::Node &node() const noexcept¶
get parent node
Return a reference to the parent node of the manager instance.
-
AttributeIterator begin() const¶
get iterator to first attribute
-
AttributeIterator end() const¶
get iterator to last+1 attribute
-
AttributeManager(node::Node &node)¶