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

path to a node object More...

#include <path.hpp>

Public Types

using value_type = std::string
 
using iterator = std::list< value_type >::iterator
 
using const_iterator = std::list< value_type >::const_iterator
 
using reverse_iterator = std::list< value_type >::reverse_iterator
 
using const_reverse_iterator = std::list< value_type >::const_reverse_iterator
 

Public Member Functions

 Path ()
 default constructor More...
 
 Path (const std::string &str)
 constructor More...
 
 Path (const char *str)
 
 Path (const_iterator first_element, const_iterator last_element)
 constructor from iterators More...
 
 operator std::string () const
 
size_t size () const noexcept
 return number of path elements More...
 
const_iterator begin () const
 get forward iterators More...
 
const_iterator end () const
 
const_reverse_iterator rbegin () const
 get reverse iterator More...
 
const_reverse_iterator rend () const
 
bool absolute () const noexcept
 returns true if a path is absolute More...
 
void absolute (bool value) noexcept
 set a path to be absolute More...
 
bool is_root () const
 true if the path refers to the root group More...
 
bool is_name () const
 true if the path is a valid child name More...
 
std::string name () const
 get object name from a path More...
 
Path parent () const
 get parent path More...
 
void append (const Path &p)
 append a path to this instance More...
 
Path relative_to (const Path &base) const
 
Pathoperator+= (const Path &other)
 

Detailed Description

Every object within an HDF5 file can be addressed via a path. Such a path is a list of link names separated by a slash /. While HDF5s C-API uses a simple string to represent a path, the C++ wrapper provides a class for this purpose.

Though an HDF5 path look quit similar to an Unix filesystem path there is one major difference: .. has no special meaning. On a Unix filesystem .. would reference to the directory above the current one. In HDF5 .. simply means nothing. It would be even allowed to use .. as a name for a group, dataset or committed datatype.

Member Typedef Documentation

◆ const_iterator

◆ const_reverse_iterator

◆ iterator

◆ reverse_iterator

◆ value_type

using hdf5::Path::value_type = std::string

Constructor & Destructor Documentation

◆ Path() [1/4]

hdf5::Path::Path ( )

After default construction is list of path elements is empty and the absolute path flag is set to false.

◆ Path() [2/4]

hdf5::Path::Path ( const std::string &  str)

Construct a path from a string. We use an explicit constructor here to avoid accidental conversions.

◆ Path() [3/4]

hdf5::Path::Path ( const char *  str)

◆ Path() [4/4]

hdf5::Path::Path ( const_iterator  first_element,
const_iterator  last_element 
)
Warning
Should not be used, as there is no automatic sanitation. May not conform to hdf5 requirements for node names.

Member Function Documentation

◆ absolute() [1/2]

bool hdf5::Path::absolute ( ) const
noexcept

A path is considered absolute if its first element references the root node. This is indicated by a leading / of the path string.

hdf5::Path p("/log/data");
if(p.absolute())
{
std::cout<<"got absolute path"<<std::endl;
}
path to a node object
Definition: path.hpp:54
Returns
true if path is absolute, false otherwise

◆ absolute() [2/2]

void hdf5::Path::absolute ( bool  value)
noexcept

Use this flag to set or unset the absolut flag.

Path p("data/modules");
std::cout<<p<<std::endl; // output: data/modules
p.absolute(true);
std::cout<<p<<std::endl; // output: /data/modules
p.absolute(false);
std::cout<<p<<std::endl; // output: data/modules
Path()
default constructor
Parameters
valueboolean value deciding whether a path is absolute or not

◆ append()

void hdf5::Path::append ( const Path p)

Adding path p to this instance. Basically this

hdf5::Path base_path("/entry/instrument");
hdf5::Path detector_transforms("detector/transformations");
hdf5::Path p = base_path.append(detector_transforms);
std::cout<<p<<std::endl;
//output: /entry/instrument/detector/transformations
void append(const Path &p)
append a path to this instance

◆ begin()

const_iterator hdf5::Path::begin ( ) const

Get the iterators to the beginning or the end+1 element of the path in forward direction.

Path p("/run/sensors/temperature");
std::for_each(p.begin(),p.end(),
[](const std::string &name) { std::cout<<name<<" "; });
//output: run sensors temperature
std::string name() const
get object name from a path

◆ end()

const_iterator hdf5::Path::end ( ) const

◆ is_name()

bool hdf5::Path::is_name ( ) const

A path is considered to be a valid child name if list of elements equals one and the absolute path flag is not set.

Returns
true if the path is a valid child name, otherwise false

◆ is_root()

bool hdf5::Path::is_root ( ) const

A path is considered to reference the root group if the list of elements is empty but the absolute path flag is set.

You can construct a root path with

Path root_path("/");

or

Path root_path();
root_path.absolute(true);

though the former idiom shoud be prefered.

Returns
true if the path references the root group, false otherwise

◆ name()

std::string hdf5::Path::name ( ) const

The object name is the last element of a path. If the path references the root group the return value is ".".

Path p("/run/sensors/temperature");
std::cout<<p.name()<<std::endl; //output: temperature
Returns
last element of the path

◆ operator std::string()

hdf5::Path::operator std::string ( ) const
inlineexplicit

◆ operator+=()

Path& hdf5::Path::operator+= ( const Path other)

◆ parent()

Path hdf5::Path::parent ( ) const

This is basically the path with the last component stripped of. In the case that the path references the root group the parent is the root group again.

Path p("/run/sensors/temperature");
std::cout<<p.parent()<<std::endl; //output: /run/sensors

but

Path root_group("/");
std::cout<<root_group.parent()<<std::endl; //output: /
Returns
new Path instance referencing the parent path of this instance

◆ rbegin()

const_reverse_iterator hdf5::Path::rbegin ( ) const

rbegin() and rend() return the pair of reverse iterators for the path.

Path p("/run/sensors/temperature");
std::for_each(p.rbegin(),p.rend(),
[](const std::string &name) { std::cout<<name<<" "; });
//output: temperature sensors run
Returns
instance of a const reverse iterator

◆ relative_to()

Path hdf5::Path::relative_to ( const Path base) const

◆ rend()

const_reverse_iterator hdf5::Path::rend ( ) const

◆ size()

size_t hdf5::Path::size ( ) const
noexcept

Returns the number of elements in the path. In the case that the path references the root group this method will return 0.


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