|
def | __init__ (self, int buffer_size=1, bool clear_buffer_when_advancing=True) |
| Creates an instance of BufferedDict with specified buffer size. More...
|
|
int | GetBufferSize (self) |
| Returns the buffer size of current isntance of buffered data. More...
|
|
None | AdvanceStep (self, recursive=True) |
| Advances the buffered data containers. More...
|
|
bool | HasValue (self, str key, int step_index=0) |
| Checks whether key exists in the given step_index. More...
|
|
Any | GetValue (self, str key, int step_index=0) |
| Get the value given by the key at the specified step_index. More...
|
|
None | SetValue (self, str key, Any value, int step_index=0, bool overwrite=False) |
| Sets a value for specified key at specified step_index. More...
|
|
None | RemoveValue (self, str key, int step_index=0) |
| Remove value at the key in the specified step_index. More...
|
|
'dict[str, Any]' | GetValueItems (self, int step_index=0) |
|
'dict[str, BufferedDict]' | GetSubItems (self) |
|
'dict[str, Any]' | GetMap (self, int step_index=0) |
| Generates (str, Any) pair map with recursively collecting all items in the BufferedDict. More...
|
|
BufferedDict | GetParent (self) |
| Get the parent of the current buffered data. More...
|
|
BufferedDict | GetRoot (self) |
| Get the root parent of the current buffered data. More...
|
|
str | PrintData (self, int step_index=-1, tabbing="") |
| Prints containing data in a json like structure. More...
|
|
Any | __getitem__ (self, str key) |
|
None | __setitem__ (self, str key, Any value) |
|
None | __delitem__ (self, str key) |
|
str | __str__ (self) |
|
Buffered dict container with buffered data ability.
Instances of this can hold (str, Any) data pairs in hierachychal data
structure where each sub item can have their own buffer sizes. Hence,
Different sub structures can have their own buffers and can be advanced
seperately or all together.
Overwriting of the existing data is not allowed because, this is used
as a central place to store data from various objects, hence allowing
overwriting will make difficult to track the changes.
Buffer size setting can only be done at the construction time
of the instance to not to allow re sizing because then it is not
clear how to handle the connected steps.
The buffered data is stored in a cyclic buffer.
'dict[str, Any]' buffered_dict.BufferedDict.GetMap |
( |
|
self, |
|
|
int |
step_index = 0 |
|
) |
| |
Generates (str, Any) pair map with recursively collecting all items in the BufferedDict.
This method recursively collects all items in the buffered data and returns a dict
with (str, Any) pairs. All the sub_items are also added as (str, BufferedDict) pairs.
Args:
step_index (int, optional): Step index the value should be looked at. Defaults to 0.
Returns:
dict[str, Any]: (str, Any) map of all the items.
bool buffered_dict.BufferedDict.HasValue |
( |
|
self, |
|
|
str |
key, |
|
|
int |
step_index = 0 |
|
) |
| |
Checks whether key exists in the given step_index.
The key in here should always be relative to the instance it is called upon.
Hence, this key can have "/" seperations for subitems, then this method
will navigate through the sub items as well to check whether given key is available.
Args:
key (str): Relative path of the key to be checked for.
step_index (int, optional): Step index to be looked for. Defaults to 0.
Returns:
bool: True if the key is found in given step index. False otherwise.
str buffered_dict.BufferedDict.PrintData |
( |
|
self, |
|
|
int |
step_index = -1 , |
|
|
|
tabbing = "" |
|
) |
| |
Prints containing data in a json like structure.
This method prints containing data and sub_item data recursively.
If the step_index == -1 then, it prints all the values on all the steps of the buffer
in current and all the sub_items recursively.
If the step_index > 0 then, it will only print values at that specified buffer index for
current instance as well as all the sub_items.
Args:
step_index (int, optional): Step index to be printed. Defaults to -1.
tabbing (str, optional): Initial tabbing for json output.. Defaults to "".
Returns:
str: String will all the containing values formatted like json.
None buffered_dict.BufferedDict.SetValue |
( |
|
self, |
|
|
str |
key, |
|
|
Any |
value, |
|
|
int |
step_index = 0 , |
|
|
bool |
overwrite = False |
|
) |
| |
Sets a value for specified key at specified step_index.
This method sets the value at the key at the specified step_index.
The key must be the relative path w.r.t. current instance of the BufferedDict.
It can include "/" seperators to set a value which is in sub items. In this case,
it will be set by recursive calls.
Args:
key (str): Relative path to the value.
value (Any): value to be set
step_index (int, optional): Step index the value should be set. Defaults to 0.
overwrite (bool): Overwrites if existing key is found with the new value, otherwise creates a key with the value.
Raises:
RuntimeError: If a value is overwritten.