fgen_runtime.base#
Base class for wrapped derived types
INVALID_INSTANCE_INDEX#
FinalizableWrapperBase#
- class FinalizableWrapperBase(instance_index=-1)[source]#
Bases:
ABCBase class for model wrappers
- abstract finalize()[source]#
Finalise the Fortran instance and set self back to being uninitialised
This method resets
self.instance_indexback to_UNINITIALISED_instance_indexShould be decorated with
check_initialised()- Return type:
- abstract classmethod from_new_connection()[source]#
Initialise by establishing a new connection with the Fortran module
This requests a new model index from the Fortran module and then initialises a class instance
- Returns:
fgen_runtime.base.FinalizableWrapperBase– New class instance
FinalizableWrapperBaseContext#
- class FinalizableWrapperBaseContext(model)[source]#
Bases:
AbstractContextManagerContext manager for a wrapper
-
model:
fgen_runtime.base.FinalizableWrapperBase# model instance to be managed
-
model:
check_initialised#
- check_initialised(method)[source]#
Check that initialisation is called before execution
- Parameters:
method (
typing.TypeVar(FuncT, bound=typing.Callable[...,typing.Any])) – Method to wrap- Returns:
typing.TypeVar(FuncT, bound=typing.Callable[...,typing.Any]) – * Wrapped method. Before the method is called, initialisation will first be * checked. If the model wrapper hasn’t been initialised before the method is * called, anInitialisationErrorwill be raised.
execute_finalize_on_fail#
- execute_finalize_on_fail(inst, func_to_try, *args, **kwargs)[source]#
Execute a function, finalising the instance before raising if any error occurs
This function is most useful in factory functions where it provides a clean way of ensuring that any Fortran is freed up in the event of an initialisation failure for any reason
- Parameters:
inst (
fgen_runtime.base.FinalizableWrapperBase) – Instance whose model index we will use when executing the functinfunc_to_try (
typing.Callable[[typing.Concatenate[int,typing.ParamSpec(P)]],typing.TypeVar(T)]) – Function to try executing, must takeinst’s model index as its first argument*args (
typing.ParamSpecArgs) – Passed tofunc_to_try**kwargs (
typing.ParamSpecKwargs) – Passed tofunc_to_try
- Returns:
typing.TypeVar(T) – Result of callingfunc_to_try(inst.instance_index, \*args, \*\*kwargs)- Raises:
Exception – Any exception which occurs when calling
func_to_try. Before the exception is raised, ``inst.finalize()is called.