Skip to content

output_handler_factory

Factory for output handlers (simplified version).

This provides a simple factory for instantiating output handlers.

OutputHandlerFactory

Simple factory for output handlers.

Source code in src/mada_tools/simulation/simutils/samples/output/output_handler_factory.py
class OutputHandlerFactory:
    """
    Simple factory for output handlers.
    """

    _handlers = {
        "csv": CSVOutputHandler,
        "folder": FolderOutputHandler,
        "directory": FolderOutputHandler,
        "dir": FolderOutputHandler,
    }

    @classmethod
    def create(cls, handler_type: str) -> BaseOutputHandler:
        """
        Create an output handler by type.

        Args:
            handler_type: Type of handler ("csv", "folder", "directory", "dir")

        Returns:
            Instance of the requested handler

        Raises:
            ValueError: If handler type is not supported
        """
        if handler_type not in cls._handlers:
            raise ValueError(f"Unknown handler type: {handler_type}")

        return cls._handlers[handler_type]()

create(handler_type) classmethod

Create an output handler by type.

Parameters:

Name Type Description Default
handler_type str

Type of handler ("csv", "folder", "directory", "dir")

required

Returns:

Type Description
BaseOutputHandler

Instance of the requested handler

Raises:

Type Description
ValueError

If handler type is not supported

Source code in src/mada_tools/simulation/simutils/samples/output/output_handler_factory.py
@classmethod
def create(cls, handler_type: str) -> BaseOutputHandler:
    """
    Create an output handler by type.

    Args:
        handler_type: Type of handler ("csv", "folder", "directory", "dir")

    Returns:
        Instance of the requested handler

    Raises:
        ValueError: If handler type is not supported
    """
    if handler_type not in cls._handlers:
        raise ValueError(f"Unknown handler type: {handler_type}")

    return cls._handlers[handler_type]()