IDS peak ICV v1.1.0
Loading...
Searching...
No Matches
iarchive.py
Go to the documentation of this file.
1from __future__ import annotations
2
3from abc import ABC, abstractmethod
4from typing import List, Union, TypeVar, Type
5
6
7class IArchive(ABC):
8 """!
9 @brief
10 Simplified interface for a hierarchical key-value archive system.
11
12 Provides dict-like access with restricted value types:
13 - bool, int, float, str
14 - IArchive (nested)
15 - Lists of the above
16
17 @ingroup ids_peak_common_python_serialization
18
19 @since ids_peak_common 1.1
20 """
21
22 AllowedValue = Union[
23 bool, int, float, str,
24 List[bool], List[int], List[float], List[str], List["IArchive"]
25 ]
26
27 T = TypeVar("T", bound=AllowedValue)
28
29 @abstractmethod
30 def set(self, key: str, value: AllowedValue | IArchive) -> None:
31 """!
32 @brief
33 Stores a value under the given key.
34
35 @param key: Key to store the value under.
36 @param value: The value to store (restricted types only).
37
38 @since ids_peak_common 1.1
39 """
40 pass
41
42 @abstractmethod
43 def get(self, key: str, datatype: Type[T]) -> T:
44 """!
45 @brief
46 Retrieves the value stored under the given key.
47
48 @param key: Key of the value to retrieve.
49 @param datatype: The expected datatype of the value.
50 @return The stored value.
51
52 @since ids_peak_common 1.1
53 """
54 pass
55
56 @abstractmethod
57 def get_archive(self, key: str) -> IArchive:
58 """!
59 @brief
60 Retrieves the archive stored under the given key.
61
62 @param key: Key of the archive to retrieve.
63 @return The stored archive.
64
65 @since ids_peak_common 1.1
66 """
67 pass
68
69 @abstractmethod
70 def has(self, key: str) -> bool:
71 """!
72 @brief
73 Checks whether a given key exists in the archive.
74
75 @param key: The key to check.
76 @return True if the key exists, False otherwise.
77
78 @since ids_peak_common 1.1
79 """
80 pass
81
82 @abstractmethod
83 def keys(self) -> List[str]:
84 """!
85 @brief
86 Returns all keys currently stored in the archive.
87
88 @return List of keys.
89
90 @since ids_peak_common 1.1
91 """
92 pass
93
94 @abstractmethod
95 def create_archive(self) -> IArchive:
96 """!
97 @brief
98 Creates a new, empty archive instance.
99
100 @since ids_peak_common 1.1
101 """
102 pass
Simplified interface for a hierarchical key-value archive system.
Definition iarchive.py:7
IArchive create_archive(self)
Creates a new, empty archive instance.
Definition iarchive.py:95
IArchive get_archive(self, str key)
Retrieves the archive stored under the given key.
Definition iarchive.py:57
List[str] keys(self)
Returns all keys currently stored in the archive.
Definition iarchive.py:83
T get(self, str key, Type[T] datatype)
Retrieves the value stored under the given key.
Definition iarchive.py:43
None set(self, str key, AllowedValue|IArchive value)
Stores a value under the given key.
Definition iarchive.py:30
bool has(self, str key)
Checks whether a given key exists in the archive.
Definition iarchive.py:70