IDS peak IPL v1.17.1
Loading...
Searching...
No Matches
peak::common::Metadata Class Reference

Type-safe container for image acquisition metadata. More...

#include <peak_common/types/peak_common_metadata.hpp>

Public Member Functions

template<typename T>
void SetValueByName (const std::string &key, T &&value)
 Stores a value using a string-based key.
template<MetadataKey metadataKey, typename T>
void SetValueByKey (T &&value)
 Stores a value using a strongly typed metadata key.
PEAK_COMMON_NO_DISCARD bool HasEntryByName (const std::string &name) const
 Checks if a given string key is stored in the metadata.
template<MetadataKey metadataKey>
PEAK_COMMON_NO_DISCARD bool HasEntryByKey () const
 Checks if a known key is stored in the metadata.
PEAK_COMMON_NO_DISCARD Any TryGetValueByName (const std::string &key) const
 Retrieves a value by string key as a type-erased object.
template<typename T>
PEAK_COMMON_NO_DISCARD T GetValueByName (const std::string &key) const
 Retrieves and casts the value associated with a string key.
template<MetadataKey metadataKey>
PEAK_COMMON_NO_DISCARD detail::MetadataKeyTraits< metadataKey >::type GetValueByKey () const
 Retrieves the value of a strongly typed metadata key.
PEAK_COMMON_NO_DISCARD std::string ToString () const
 Returns a string representation of the metadata.
PEAK_COMMON_NO_DISCARD std::vector< std::string > GetKeyNames () const
 Returns a vector of key names.

Friends

std::ostream & operator<< (std::ostream &os, const Metadata &metadata)
 Outputs the metadata keys in human-readable form.

Detailed Description

Type-safe container for image acquisition metadata.

The Metadata class is a flexible container for storing key-value pairs.

It supports both:

  • Arbitrary runtime keys using string identifiers (*ByName functions).
  • Strongly typed compile-time keys via metadata traits (*ByKey functions).

Values are stored using a type-erased mechanism (peak::common::Any) and can be retrieved either by casting or by trait-based access.

Since
ids_peak_common 1.0

Member Function Documentation

◆ GetKeyNames()

PEAK_COMMON_NO_DISCARD std::vector< std::string > peak::common::Metadata::GetKeyNames ( ) const
inline

Returns a vector of key names.

Returns
A vector of key names
Since
ids_peak_common 1.1

◆ GetValueByKey()

template<MetadataKey metadataKey>
PEAK_COMMON_NO_DISCARD detail::MetadataKeyTraits< metadataKey >::type peak::common::Metadata::GetValueByKey ( ) const
inline

Retrieves the value of a strongly typed metadata key.

Provides type-safe access to known metadata keys, defined in peak::common::MetadataKey.

Template Parameters
metadataKeyThe strongly typed metadata key.
Exceptions
peak::common::InvalidCastExceptionif the stored type does not match the trait definition.
peak::common::OutOfRangeExceptionif the key is not found.
Returns
The stored value of type MetadataKeyTraits<metadataKey>::type.
Since
ids_peak_common 1.0

◆ GetValueByName()

template<typename T>
PEAK_COMMON_NO_DISCARD T peak::common::Metadata::GetValueByName ( const std::string & key) const
inline

Retrieves and casts the value associated with a string key.

Template Parameters
TThe expected type of the stored value.
Parameters
keyThe name of the metadata entry.
Exceptions
peak::common::InvalidCastExceptionif the stored type does not match T.
peak::common::OutOfRangeExceptionif the key does not exist.
Returns
The value cast to the requested type.
Since
ids_peak_common 1.0

◆ HasEntryByKey()

template<MetadataKey metadataKey>
PEAK_COMMON_NO_DISCARD bool peak::common::Metadata::HasEntryByKey ( ) const
inline

Checks if a known key is stored in the metadata.

Verifies that the key exists and that the stored type matches the expected trait type.

Template Parameters
metadataKeyThe strongly typed metadata key.
Returns
True if the key exists and the type matches, false otherwise.
Since
ids_peak_common 1.0

◆ HasEntryByName()

PEAK_COMMON_NO_DISCARD bool peak::common::Metadata::HasEntryByName ( const std::string & name) const
inline

Checks if a given string key is stored in the metadata.

Parameters
nameThe key to check for.
Returns
True if the key exists, false otherwise.
Since
ids_peak_common 1.0

◆ SetValueByKey()

template<MetadataKey metadataKey, typename T>
void peak::common::Metadata::SetValueByKey ( T && value)
inline

Stores a value using a strongly typed metadata key.

Ensures compile-time type safety using known metadata traits.

Known metadata keys are defined in the enum peak::common::MetadataKey.

Template Parameters
metadataKeyA known metadata key (e.g. MetadataKey::DeviceTimestamp).
TType of the value. Must match detail::MetadataKeyTraits<metadataKey>::type.
Parameters
valueThe value to store.
Since
ids_peak_common 1.0

◆ SetValueByName()

template<typename T>
void peak::common::Metadata::SetValueByName ( const std::string & key,
T && value )
inline

Stores a value using a string-based key.

Template Parameters
TType of the value to store.
Parameters
keyA runtime string identifier.
valueThe value to store.
Since
ids_peak_common 1.0

◆ ToString()

PEAK_COMMON_NO_DISCARD std::string peak::common::Metadata::ToString ( ) const
inline

Returns a string representation of the metadata.

Equivalent to writing the object to a stream with operator<<.

Returns
A formatted string listing the metadata keys.
Since
ids_peak_common 1.0

◆ TryGetValueByName()

PEAK_COMMON_NO_DISCARD Any peak::common::Metadata::TryGetValueByName ( const std::string & key) const
inline

Retrieves a value by string key as a type-erased object.

Parameters
keyThe name of the metadata entry.
Returns
A peak::common::Any object containing the value, or empty if not found.
Since
ids_peak_common 1.0

◆ operator<<

std::ostream & operator<< ( std::ostream & os,
const Metadata & metadata )
friend

Outputs the metadata keys in human-readable form.

Values are not printed since their types are unknown at runtime.

Parameters
osThe output stream.
metadataThe metadata to print.
Returns
Reference to the stream.
Since
ids_peak_common 1.0

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