Skip to content

example_fgen_basic.error_v#

Definition of an error value

Modules:

Name Description
creation

Wrappers of m_error_v_creation

error_v

Python equivalent of the Fortran ErrorV class.

passing

Wrappers of m_error_v_passing.

Classes:

Name Description
ErrorV

Error value

ErrorV #

Error value

Methods:

Name Description
build_fortran_instance

Build an instance equivalent to self on the Fortran side

from_instance_index

Initialise from an instance index received from Fortran

Attributes:

Name Type Description
code int

Error code

message str

Error message

Source code in src/example_fgen_basic/error_v/error_v.py
@define
class ErrorV:
    """
    Error value
    """

    code: int = 1
    """Error code"""

    message: str = ""
    """Error message"""

    @classmethod
    def from_instance_index(cls, instance_index: int) -> ErrorV:
        """
        Initialise from an instance index received from Fortran

        Parameters
        ----------
        instance_index
            Instance index received from Fortran

        Returns
        -------
        :
            Initialised index
        """
        # Different wrapping strategies are needed

        # Integer is very simple
        code = m_error_v_w.get_code(instance_index)

        # String requires decode
        message = m_error_v_w.get_message(instance_index).decode()

        res = cls(code=code, message=message)

        return res

    def build_fortran_instance(self) -> int:
        """
        Build an instance equivalent to `self` on the Fortran side

        Intended for use mainly by wrapping functions.
        Most users should not need to use this method directly.

        Returns
        -------
        :
            Instance index of the object which has been created on the Fortran side
        """
        instance_index: int = m_error_v_w.build_instance(
            code=self.code, message=self.message
        )

        return instance_index

code class-attribute instance-attribute #

code: int = 1

Error code

message class-attribute instance-attribute #

message: str = ''

Error message

build_fortran_instance #

build_fortran_instance() -> int

Build an instance equivalent to self on the Fortran side

Intended for use mainly by wrapping functions. Most users should not need to use this method directly.

Returns:

Type Description
int

Instance index of the object which has been created on the Fortran side

Source code in src/example_fgen_basic/error_v/error_v.py
def build_fortran_instance(self) -> int:
    """
    Build an instance equivalent to `self` on the Fortran side

    Intended for use mainly by wrapping functions.
    Most users should not need to use this method directly.

    Returns
    -------
    :
        Instance index of the object which has been created on the Fortran side
    """
    instance_index: int = m_error_v_w.build_instance(
        code=self.code, message=self.message
    )

    return instance_index

from_instance_index classmethod #

from_instance_index(instance_index: int) -> ErrorV

Initialise from an instance index received from Fortran

Parameters:

Name Type Description Default
instance_index int

Instance index received from Fortran

required

Returns:

Type Description
ErrorV

Initialised index

Source code in src/example_fgen_basic/error_v/error_v.py
@classmethod
def from_instance_index(cls, instance_index: int) -> ErrorV:
    """
    Initialise from an instance index received from Fortran

    Parameters
    ----------
    instance_index
        Instance index received from Fortran

    Returns
    -------
    :
        Initialised index
    """
    # Different wrapping strategies are needed

    # Integer is very simple
    code = m_error_v_w.get_code(instance_index)

    # String requires decode
    message = m_error_v_w.get_message(instance_index).decode()

    res = cls(code=code, message=message)

    return res