IDS peak ICV v1.5.0
Loading...
Searching...
No Matches
Metadata Class Reference

Public Member Functions

None __init__ (self)
 Initialize an empty metadata container.
 
None set_value_by_name (self, str key, AllowedTypes value)
 Store a value using a string-based key.
 
None remove_entry_by_name (self, str key)
 Removes the entry using a string-based name.
 
bool has_entry_by_name (self, str key)
 Check if a string key is present in the metadata.
 
Any try_get_value_by_name (self, str key)
 Retrieve a value by string key, returning None if not found.
 
T get_value_by_name (self, Type[T] expected_type, str key)
 Retrieve the value for a key and validate that it is of the expected type.
 
None set_value_by_key (self, MetadataKey key, Any value)
 Store a value using a strongly typed metadata key.
 
bool has_entry_by_key (self, MetadataKey key)
 Check if a strongly typed metadata key is present and matches the expected type.
 
Any get_value_by_key (self, MetadataKey key)
 Retrieve the value of a strongly typed metadata key.
 
List[str] get_key_names (self)
 Returns a list of metadata key names.
 
bool __eq__ (self, Any other)
 Check if two metadata are equal.
 
bool __ne__ (self, Any other)
 Check if two metadata are not equal.
 
str __str__ (self)
 Return a human-readable string of metadata keys and values.
 
str __repr__ (self)
 Return an unambiguous string of the Metadata object.
 

Static Public Attributes

 AllowedTypes
 

Protected Attributes

dict _data = {}
 

Detailed Description

A type-safe container for metadata key-value pairs.

This class provides a flexible mechanism for storing and retrieving metadata:

  • Arbitrary runtime keys (string string_values).
  • Strongly typed keys defined in a schema.

Values are stored in a Python dictionary but accessed with additional safety checks to ensure type correctness.

Example usage::

metadata = Metadata()
metadata.set_value_by_key(MetadataKey.DEVICE_FRAME_ID, 1)
print(metadata.get_value_by_key(MetadataKey.DEVICE_FRAME_ID)) # outputs: 1
print(metadata.has_entry_by_key(MetadataKey.DEVICE_FRAME_ID)) # outputs: True

Constructor & Destructor Documentation

◆ __init__()

None __init__ ( self)

Initialize an empty metadata container.

Member Function Documentation

◆ __eq__()

bool __eq__ ( self,
Any other )

Check if two metadata are equal.

Parameters
otherAnother Metadata object
Returns
True if metadata are equal, False otherwise

◆ __ne__()

bool __ne__ ( self,
Any other )

Check if two metadata are not equal.

Parameters
otherAnother metadata object
Returns
True if metadata are not equal, False otherwise

◆ __repr__()

str __repr__ ( self)

Return an unambiguous string of the Metadata object.

◆ __str__()

str __str__ ( self)

Return a human-readable string of metadata keys and values.

Example: { "DeviceFrameID": 42, "DeviceTimestamp": 1695472000, "custom_data": "xyz" }

◆ get_key_names()

List[str] get_key_names ( self)

Returns a list of metadata key names.

Returns
A list of metadata key names

◆ get_value_by_key()

Any get_value_by_key ( self,
MetadataKey key )

Retrieve the value of a strongly typed metadata key.

Parameters
keyA MetadataKey object.
Exceptions
OutOfRangeExceptionIf the key does not exist.
InvalidCastExceptionIf the type does not match.
Returns
The stored value.

◆ get_value_by_name()

T get_value_by_name ( self,
Type[T] expected_type,
str key )

Retrieve the value for a key and validate that it is of the expected type.

Parameters
expected_typeThe expected type of the stored value.
keyThe metadata key.
Exceptions
OutOfRangeExceptionIf the key does not exist.
InvalidCastExceptionIf the stored type does not match.
Returns
The stored value cast to the expected type.

◆ has_entry_by_key()

bool has_entry_by_key ( self,
MetadataKey key )

Check if a strongly typed metadata key is present and matches the expected type.

Parameters
keyA MetadataKey object.
Returns
True if the key exists and type matches, False otherwise.

◆ has_entry_by_name()

bool has_entry_by_name ( self,
str key )

Check if a string key is present in the metadata.

Parameters
keyThe metadata key.
Returns
True if the key exists, False otherwise.

◆ remove_entry_by_name()

None remove_entry_by_name ( self,
str key )

Removes the entry using a string-based name.

If the key does not exist, nothing happens.

Parameters
keyThe metadata key to be removed.

◆ set_value_by_key()

None set_value_by_key ( self,
MetadataKey key,
Any value )

Store a value using a strongly typed metadata key.

Note that passing an empty list may result in a loss of information when the metadata object is passed to an image.

Parameters
keyA MetadataKey object containing key name and expected type.
valueThe value to store.
Exceptions
InvalidCastExceptionIf the value type does not match the trait type.

◆ set_value_by_name()

None set_value_by_name ( self,
str key,
AllowedTypes value )

Store a value using a string-based key.

Note that ignoring the allowed types for parameter value or passing an empty list may result in a loss of information when the metadata object is passed to an image.

Parameters
keyThe key under which the value is stored.
valueValue to store.

◆ try_get_value_by_name()

Any try_get_value_by_name ( self,
str key )

Retrieve a value by string key, returning None if not found.

Parameters
keyThe metadata key.
Returns
The stored value if found, otherwise None.

Field Documentation

◆ _data

dict _data = {}
protected

◆ AllowedTypes

AllowedTypes
static
Initial value:
= Union[
int, list[int],
float, list[float],
str, list[str],
bool, list[bool]]