|
|
| Attribute (from_any_tag, std::any val) |
| |
| template<typename U > |
| U | get () const |
| | Retrieve a stored specific Attribute and cast if convertible. More...
|
| |
| template<typename U > |
| std::optional< U > | getOptional () const |
| | Retrieve a stored specific Attribute and cast if convertible. More...
|
| |
| template<typename U > |
| std::variant< U, std::runtime_error > | getOrError () const |
| | Retrieve a stored specific Attribute and cast if convertible. More...
|
| |
| std::variant< Attribute, std::runtime_error > | requireVector () const |
| | Force this attribute into a vector type. More...
|
| |
| std::variant< Attribute, std::runtime_error > | requireScalar () const |
| | Force this attribute into a scalar type. More...
|
| |
|
template<typename U > |
| auto | getOrError () const -> std::variant< U, std::runtime_error > |
| |
|
| Variant (from_basic_type_tag, U) |
| |
|
| Variant (from_any_tag, std::any) |
| |
| | Variant (U u) |
| | Construct a lightweight wrapper around a generic object that indicates the concrete datatype of the specific object stored. More...
|
| |
| U const & | get () const |
| | Retrieve a stored specific object of known datatype with ensured type-safety. More...
|
| |
| variant_t const & | getVariant () const |
| | Retrieve the stored generic object. More...
|
| |
|
std::any const & | getAny () const |
| |
| size_t | index () const |
| | Retrieve the index of the alternative that is currently been held. More...
|
| |
|
|
static constexpr from_any_tag | from_any = from_any_tag{} |
| |
|
static constexpr from_basic_type_tag | from_basic_type |
| |
|
static constexpr from_any_tag | from_any |
| |
◆ get()
template<typename U >
| U openPMD::Attribute::get |
Retrieve a stored specific Attribute and cast if convertible.
- Note
- This performs a static_cast and might introduce precision loss if requested. Check dtype explicitly beforehand if needed.
- Exceptions
-
| std::runtime_error | if stored object is not static castable to U. |
- Template Parameters
-
| U | Type of the object to be casted to. |
- Returns
- Copy of the retrieved object, casted to type U.
◆ getOptional()
template<typename U >
| std::optional< U > openPMD::Attribute::getOptional |
Retrieve a stored specific Attribute and cast if convertible.
Like Attribute::get<>(), but returns an empty std::optional if no conversion is possible instead of throwing an exception.
- Note
- This performs a static_cast and might introduce precision loss if requested. Check dtype explicitly beforehand if needed.
- Template Parameters
-
| U | Type of the object to be casted to. |
- Returns
- Copy of the retrieved object, casted to type U. An empty std::optional if no conversion is possible.
◆ getOrError()
template<typename U >
| std::variant<U, std::runtime_error> openPMD::Attribute::getOrError |
( |
| ) |
const |
Retrieve a stored specific Attribute and cast if convertible.
Like Attribute::get<>(), but returns an exception instead of throwing it if no conversion is possible.
- Note
- This performs a static_cast and might introduce precision loss if requested. Check dtype explicitly beforehand if needed.
- Template Parameters
-
| U | Type of the object to be casted to. |
- Returns
- Copy of the retrieved object, casted to type U. A runtime_error (as return value, no thrown) if no conversion is possible.
◆ requireScalar()
| std::variant< Attribute, std::runtime_error > openPMD::Attribute::requireScalar |
( |
| ) |
const |
Force this attribute into a scalar type.
If it is a vector attribute with a single entry, convert to a scalar.
- Returns
- On success, a new Attribute with underlying scalar type. On failure, an error with a description of what went wrong (e.g. when a vector with size other than 1 was provided).
◆ requireVector()
| std::variant< Attribute, std::runtime_error > openPMD::Attribute::requireVector |
( |
| ) |
const |
Force this attribute into a vector type.
If it is scalar, convert to a vector with a single element. If it is an array, convert it to a vector.
- Returns
- On success, a new Attribute with underlying vector type. On failure, an error with a description of what went wrong (e.g. when the base type is bool).
The documentation for this class was generated from the following files:
- /home/docs/checkouts/readthedocs.org/user_builds/openpmd-api/checkouts/latest/include/openPMD/backend/Attribute.hpp
- /home/docs/checkouts/readthedocs.org/user_builds/openpmd-api/checkouts/latest/src/backend/Attribute.cpp