IDS peak ICV v1.3.0
Loading...
Searching...
No Matches
Archive Class Reference
Inheritance diagram for Archive:

Public Member Functions

None __init__ (self, Dict[str, Archive.AllowedValue]|None data=None)
 Initializes the archive with optional initial data.
 
None set (self, str key, AllowedValue value)
 Stores a value under the specified key.
 
T get (self, str key, Type[T]|None datatype)
 Returns the value stored under the specified key.
 
IArchive get_archive (self, str key)
 Returns the archive stored under the given key.
 
bool has (self, str key)
 Checks whether a given key exists in the archive.
 
List[str] keys (self)
 Returns all keys currently stored in the archive.
 
IArchive create_archive (self)
 Creates a new, empty archive instance.
 
str __str__ (self)
 A string representation of the archive.
 
str __repr__ (self)
 
bool __eq__ (self, Any other)
 

Static Public Attributes

 AllowedValue = IArchive.AllowedValue | IArchive
 

Protected Member Functions

bool _compare_values (self, Any lhs, Any rhs)
 
bool _is_supported_type (self, Any value)
 Returns whether the value’s type is supported.
 

Protected Attributes

Dict _storage = data
 

Static Protected Attributes

tuple _ALLOWED_SCALARS = (bool, int, float, str, IArchive)
 

Detailed Description

A key-value store with type checking, based on a dict.

Supports only:

  • bool, int, float, str
  • IArchive
  • Lists of the above (with homogeneous element types)

Example

from ids_peak_icv.serialization import Archive

archive = Archive()

archive.set("A", 1)
archive.set("B", "Text")
archive.set("C", [1, 2, 3])

sub_archive = Archive()
sub_archive.set("a", 1.2)
sub_archive.set("b", True)
archive.set("D", sub_archive)
Since
ids_peak_icv 1.0

Definition at line 11 of file archive.py.

Constructor & Destructor Documentation

◆ __init__()

None __init__ ( self,
Dict[str, Archive.AllowedValue] | None data = None )

Initializes the archive with optional initial data.

If data is provided, all entries are validated for supported types before the dict is stored by reference. If data is None, the archive is initially empty.

Parameters
dataOptional dictionary of initial key-value pairs.
Exceptions
NotSupportedExceptionAn entry in data has an unsupported type.
Since
ids_peak_icv 1.0

Definition at line 42 of file archive.py.

Member Function Documentation

◆ __eq__()

bool __eq__ ( self,
Any other )
Since
ids_peak_icv 1.0

Definition at line 187 of file archive.py.

◆ __repr__()

str __repr__ ( self)
Since
ids_peak_icv 1.0

Definition at line 180 of file archive.py.

◆ __str__()

str __str__ ( self)

A string representation of the archive.

Since
ids_peak_icv 1.0

Definition at line 171 of file archive.py.

◆ _compare_values()

bool _compare_values ( self,
Any lhs,
Any rhs )
protected
Since
ids_peak_icv 1.0

Definition at line 204 of file archive.py.

◆ _is_supported_type()

bool _is_supported_type ( self,
Any value )
protected

Returns whether the value’s type is supported.

Parameters
valueA value or a list whose type is validated.
Returns
True if the type supported, False otherwise.
Since
ids_peak_icv 1.0

Definition at line 221 of file archive.py.

◆ create_archive()

IArchive create_archive ( self)

Creates a new, empty archive instance.

Since
ids_peak_icv 1.0

Definition at line 162 of file archive.py.

◆ get()

T get ( self,
str key,
Type[T] | None datatype )

Returns the value stored under the specified key.

Parameters
keyKey of the value to retrieve.
datatypeThe expected datatype of the value. If None is given, the type check is not executed.
Returns
The stored value.
Exceptions
CorruptedExceptionIf the key is not found or the specified datatype is not the type of the stored value.
Since
ids_peak_icv 1.0

Definition at line 89 of file archive.py.

◆ get_archive()

IArchive get_archive ( self,
str key )

Returns the archive stored under the given key.

Parameters
keyKey of the archive to retrieve.
Returns
The stored archive.
Exceptions
CorruptedExceptionThe key is not found or the specified datatype is not of type IArchive.
Since
ids_peak_icv 1.0

Definition at line 115 of file archive.py.

◆ has()

bool has ( self,
str key )

Checks whether a given key exists in the archive.

Parameters
keyThe key to check.
Returns
True if the key exists, False otherwise.
Since
ids_peak_icv 1.0

Definition at line 138 of file archive.py.

◆ keys()

List[str] keys ( self)

Returns all keys currently stored in the archive.

Returns
List of keys.
Since
ids_peak_icv 1.0

Definition at line 151 of file archive.py.

◆ set()

None set ( self,
str key,
AllowedValue value )

Stores a value under the specified key.

Parameters
keyThe key under which to store the value.
valueThe value to store (restricted types only).
Exceptions
NotSupportedExceptionThe value has an unsupported type.
Since
ids_peak_icv 1.0

Definition at line 70 of file archive.py.

Field Documentation

◆ _ALLOWED_SCALARS

_ALLOWED_SCALARS = (bool, int, float, str, IArchive)
staticprotected

Definition at line 219 of file archive.py.

◆ _storage

Dict _storage = data
protected

Definition at line 68 of file archive.py.

◆ AllowedValue

AllowedValue = IArchive.AllowedValue | IArchive
static

Definition at line 40 of file archive.py.