
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) |
A key-value store with type checking, based on a dict.
Supports only:
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)
| 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.
| data | Optional dictionary of initial key-value pairs. |
| NotSupportedException | An entry in data has an unsupported type. |
| bool __eq__ | ( | self, | |
| Any | other ) |
| str __repr__ | ( | self | ) |
| str __str__ | ( | self | ) |
A string representation of the archive.
|
protected |
|
protected |
Returns whether the value’s type is supported.
| value | A value or a list whose type is validated. |
True if the type supported, False otherwise.| IArchive create_archive | ( | self | ) |
Creates a new, empty archive instance.
Returns the value stored under the specified key.
| key | Key of the value to retrieve. |
| datatype | The expected datatype of the value. If None is given, the type check is not executed. |
| CorruptedException | If the key is not found or the specified datatype is not the type of the stored value. |
| IArchive get_archive | ( | self, | |
| str | key ) |
Returns the archive stored under the given key.
| key | Key of the archive to retrieve. |
| CorruptedException | The key is not found or the specified datatype is not of type IArchive. |
| bool has | ( | self, | |
| str | key ) |
Checks whether a given key exists in the archive.
| key | The key to check. |
| List[str] keys | ( | self | ) |
| None set | ( | self, | |
| str | key, | ||
| AllowedValue | value ) |
Stores a value under the specified key.
| key | The key under which to store the value. |
| value | The value to store (restricted types only). |
| NotSupportedException | The value has an unsupported type. |
|
staticprotected |
|
protected |
|
static |