libICEpost.src.base.BaseClass

@author: F. Ramognino <federico.ramognino@polimi.it> Last update: 12/06/2023

Attributes

Class

BaseClassType

Classes

SelectionTable

Table for storing classes for run-time selection.

BaseClass

Class wrapping useful methods for base virtual classes (e.g. run-time selector)

Functions

_add_TypeName(cls)

Function used to add the TypeName a class.

Module Contents

libICEpost.src.base.BaseClass.Class
libICEpost.src.base.BaseClass.BaseClassType
libICEpost.src.base.BaseClass._add_TypeName(cls: type)[source]

Function used to add the TypeName a class.

class libICEpost.src.base.BaseClass.SelectionTable(cls: BaseClassType)[source]

Bases: libICEpost.src.base.Utilities.Utilities

Table for storing classes for run-time selection.

__type: BaseClassType

The base class to which the selection table is linked.

__db: dict[str, type]

Database of available sub-classes in the selection table. Classes are stored through [str->type] map.

property type: BaseClassType

The base class to which the selection table is linked.

property db: dict[str, BaseClassType]

Database of available sub-classes in the selection table. Classes are stored through [str->type] map.

__str__()[source]

Printing selection table

__repr__()[source]

Representation of selection table

__contains__(typeName: str) bool[source]
typeName: str

Name of the class to look-up

Check if the selection table contains a selectable class called ‘typeName’.

__getitem__(typeName: str) BaseClassType[source]

Get class from selection table.

Parameters:

typeName (str) – Name of the class to get

add(cls: type, overwrite: bool = True) None[source]

Add class to selection table

Parameters:
  • cls (type) – Class to add to the selection table

  • overwrite (bool, optional) – Overwrite if present? Defaults to True.

Raises:

TypeError – If the class is not derived from the base class of the selection table

check(typeName: str) bool[source]

Checks if a class name is in the selection table.

Parameters:

typeName (str) – Name of the class to check

Returns:

True if the class is in the selection table

Return type:

bool

Raises:

ValueError – If the class is not in the selection table

class libICEpost.src.base.BaseClass.BaseClass[source]

Bases: libICEpost.src.base.Utilities.Utilities

Class wrapping useful methods for base virtual classes (e.g. run-time selector)

classmethod selectionTable() SelectionTable[source]

The run-time selection table associated to this class.

classmethod selector(typeName: str, dictionary: dict) BaseClassType[source]

Construct an instance of a subclass of this that was added to the selection table.

Parameters:
  • typeName (str) – Name of the subclass to instantiate

  • dictionary (dict) – Dictionary containing the data to construct the class.

Returns:

Instance of the specific class.

Return type:

BaseClassType

classmethod hasSelectionTable() bool[source]

Check if selection table was defined for this class.

classmethod fromDictionary(dictionary: dict) BaseClassType[source]
Abstractmethod:

Construct an instance of this class from a dictionary. To be overwritten by derived class.

Parameters:

dictionary (dict) – Dictionary containing the data to construct the class.

Returns:

Instance of the specific class.

Return type:

BaseClassType

classmethod addToRuntimeSelectionTable(childClass: BaseClassType, *, overwrite: bool = True) None[source]

Add the subclass to the database of available subclasses for runtime selection.

Parameters:
  • childClass (BaseClassType) – Subclass to add to the selection table

  • overwrite (bool, optional) – Overwrite if present? Defaults to True.

classmethod createRuntimeSelectionTable() None[source]

Create the runtime selection table, initializing the property ‘selectionTable’ of the class.

classmethod showRuntimeSelectionTable() None[source]

Prints a list of the available classes in the selection table and if they are instantiable.

Example

Available classes in selection table:

ClassA (Abstract class) ClassB ClassC