TRIQS/h5 1.3.0
C++ interface to HDF5
Loading...
Searching...
No Matches
std::string, const char* and char_buf

Detailed Description

Specialized functions to read/write std::string, const char * and a generic character buffer (h5::char_buf) from/to HDF5.

The following code writes a string to an HDF5 file, reads the same string and outputs it to stdout:

#include <h5/h5.hpp>
#include <iostream>
#include <string>
int main() {
// create file in read/write mode
h5::file file("string.h5", 'w');
// write string
h5::write(file, "mystring", "Hello world!");
// read into string
std::string str;
h5::read(file, "mystring", str);
// output string
std::cout << str << std::endl;
}
A handle to an HDF5 file.
Definition file.hpp:43
T read(group g, std::string const &key)
Generic implementation for reading from an HDF5 dataset/subgroup.
Definition generic.hpp:73
void write(group g, std::string const &key, T const &x, auto const &...args)
Generic implementation for writing a variable to an HDF5 dataset/subgroup.
Definition generic.hpp:105
Includes all relevant h5 headers.

Output:

Hello world!

Contents of string.h5:

HDF5 "string.h5" {
GROUP "/" {
DATASET "mystring" {
DATATYPE H5T_STRING {
STRSIZE H5T_VARIABLE;
STRPAD H5T_STR_NULLTERM;
CSET H5T_CSET_UTF8;
CTYPE H5T_C_S1;
}
DATASPACE SCALAR
DATA {
(0): "Hello world!"
}
}
}
}

Classes

struct  h5::char_buf
 Stores an arbitrary number of strings in a 1-dimensional std::vector<char>. More...
 
struct  h5::hdf5_format_impl< std::string >
 Specialization of h5::hdf5_format_impl for std::string. More...
 

Functions

void h5::h5_read (group g, std::string const &name, char *s)=delete
 Read a string from an HDF5 dataset into a char*.
 
void h5::h5_read (group g, std::string const &name, char_buf &cb)
 Read an h5::char_buf from an HDF5 dataset.
 
void h5::h5_read (group g, std::string const &name, std::string &s)
 Read a string from an HDF5 dataset into a std::string.
 
void h5::h5_read_attribute (object obj, std::string const &name, char *s)=delete
 Read a string from an HDF5 attribute into a char*.
 
void h5::h5_read_attribute (object obj, std::string const &name, char_buf &cb)
 Read an h5::char_buf from an HDF5 attribute.
 
void h5::h5_read_attribute (object obj, std::string const &name, std::string &s)
 Read a string from an HDF5 attribute into a std::string.
 
void h5::h5_read_attribute_from_key (group g, std::string const &key, std::string const &name, std::string &s)
 Read a string from an HDF5 attribute into a std::string.
 
void h5::h5_write (group g, std::string const &name, char_buf const &cb)
 Write an h5::char_buf to an HDF5 dataset.
 
void h5::h5_write (group g, std::string const &name, const char *s)
 Write a const char* to an HDF5 dataset.
 
void h5::h5_write (group g, std::string const &name, std::string const &s)
 Write a std::string to an HDF5 dataset.
 
void h5::h5_write_attribute (object obj, std::string const &name, char_buf const &cb)
 Write an h5::char_buf to an HDF5 attribute.
 
void h5::h5_write_attribute (object obj, std::string const &name, const char *s)
 Write a const char* to an HDF5 attribute.
 
void h5::h5_write_attribute (object obj, std::string const &name, std::string const &s)
 Write a std::string to an HDF5 attribute.
 
void h5::h5_write_attribute_to_key (group g, std::string const &key, std::string const &name, const char *s)
 Write a const char* to an HDF5 attribute.
 
void h5::h5_write_attribute_to_key (group g, std::string const &key, std::string const &name, std::string const &s)
 Write a std::string to an HDF5 attribute.
 

Function Documentation

◆ h5_read() [1/3]

void h5::h5_read ( group g,
std::string const & name,
char * s )
inlinedelete

#include <h5/stl/string.hpp>

Read a string from an HDF5 dataset into a char*.

Warning
Reading into a char* is not allowed. Use h5::h5_read(group, std::string const &, std::string &) instead.

◆ h5_read() [2/3]

void h5::h5_read ( group g,
std::string const & name,
char_buf & cb )

#include <h5/stl/string.cpp>

Read an h5::char_buf from an HDF5 dataset.

Parameters
gh5::group containing the dataset.
nameName of the dataset.
cbh5::char_buf to read into.

Definition at line 215 of file string.cpp.

◆ h5_read() [3/3]

void h5::h5_read ( group g,
std::string const & name,
std::string & s )

#include <h5/stl/string.cpp>

Read a string from an HDF5 dataset into a std::string.

Parameters
gh5::group containing the dataset.
nameName of the dataset.
sstd::string to read into.

Definition at line 67 of file string.cpp.

◆ h5_read_attribute() [1/3]

void h5::h5_read_attribute ( object obj,
std::string const & name,
char * s )
inlinedelete

#include <h5/stl/string.hpp>

Read a string from an HDF5 attribute into a char*.

Warning
Reading into a char* is not allowed. Use h5::h5_read_attribute(object, std::string const &, std::string &) instead.

◆ h5_read_attribute() [2/3]

void h5::h5_read_attribute ( object obj,
std::string const & name,
char_buf & cb )

#include <h5/stl/string.cpp>

Read an h5::char_buf from an HDF5 attribute.

Parameters
objh5::object to which the attribute is attached.
nameName of the attribute.
cbh5::char_buf to read into.

Definition at line 257 of file string.cpp.

◆ h5_read_attribute() [3/3]

void h5::h5_read_attribute ( object obj,
std::string const & name,
std::string & s )

#include <h5/stl/string.cpp>

Read a string from an HDF5 attribute into a std::string.

If the attribute does not exist, an empty string is returned.

Parameters
objh5::object to which the attribute is attached.
nameName of the attribute.
sstd::string to read into.

Definition at line 114 of file string.cpp.

◆ h5_read_attribute_from_key()

void h5::h5_read_attribute_from_key ( group g,
std::string const & key,
std::string const & name,
std::string & s )

#include <h5/stl/string.cpp>

Read a string from an HDF5 attribute into a std::string.

If the attribute does not exist, an empty string is returned.

Parameters
gh5::group containing the HDF5 object to which the attribute is attached.
keyName of the object.
nameName of the attribute.
sstd::string to read into.

Definition at line 161 of file string.cpp.

◆ h5_write() [1/3]

void h5::h5_write ( group g,
std::string const & name,
char_buf const & cb )

#include <h5/stl/string.cpp>

Write an h5::char_buf to an HDF5 dataset.

Parameters
gh5::group in which the dataset is created.
nameName of the dataset.
cbh5::char_buf to be written.

Definition at line 204 of file string.cpp.

◆ h5_write() [2/3]

void h5::h5_write ( group g,
std::string const & name,
const char * s )
inline

#include <h5/stl/string.hpp>

Write a const char* to an HDF5 dataset.

Parameters
gh5::group in which the dataset is created.
nameName of the dataset.
sconst char* to be written.

Definition at line 63 of file string.hpp.

◆ h5_write() [3/3]

void h5::h5_write ( group g,
std::string const & name,
std::string const & s )

#include <h5/stl/string.cpp>

Write a std::string to an HDF5 dataset.

Parameters
gh5::group in which the dataset is created.
nameName of the dataset.
sstd::string to be written.

Definition at line 55 of file string.cpp.

◆ h5_write_attribute() [1/3]

void h5::h5_write_attribute ( object obj,
std::string const & name,
char_buf const & cb )

#include <h5/stl/string.cpp>

Write an h5::char_buf to an HDF5 attribute.

Parameters
objh5::object to which the attribute is attached.
nameName of the attribute.
cbh5::char_buf to be written.

Definition at line 243 of file string.cpp.

◆ h5_write_attribute() [2/3]

void h5::h5_write_attribute ( object obj,
std::string const & name,
const char * s )
inline

#include <h5/stl/string.hpp>

Write a const char* to an HDF5 attribute.

Parameters
objh5::object to which the attribute is attached.
nameName of the attribute.
s'const char*' to be written.

Definition at line 96 of file string.hpp.

◆ h5_write_attribute() [3/3]

void h5::h5_write_attribute ( object obj,
std::string const & name,
std::string const & s )

#include <h5/stl/string.cpp>

Write a std::string to an HDF5 attribute.

Parameters
objh5::object to which the attribute is attached.
nameName of the attribute.
sstd::string to be written.

Definition at line 99 of file string.cpp.

◆ h5_write_attribute_to_key() [1/2]

void h5::h5_write_attribute_to_key ( group g,
std::string const & key,
std::string const & name,
const char * s )
inline

#include <h5/stl/string.hpp>

Write a const char* to an HDF5 attribute.

Parameters
gh5::group containing the HDF5 object to which the attribute is attached.
keyName of the object.
nameName of the attribute.
sconst char* to be written.

Definition at line 133 of file string.hpp.

◆ h5_write_attribute_to_key() [2/2]

void h5::h5_write_attribute_to_key ( group g,
std::string const & key,
std::string const & name,
std::string const & s )

#include <h5/stl/string.cpp>

Write a std::string to an HDF5 attribute.

Parameters
gh5::group containing the HDF5 object to which the attribute is attached.
keyName of the object.
nameName of the attribute.
sstd::string to be written.

Definition at line 147 of file string.cpp.