Skip to content
Snippets Groups Projects
Commit c3037a5e authored by Timo Koch's avatar Timo Koch
Browse files

[python] Add helpers for creating class-like aliases for the code generators

parent 0e0c86a1
No related branches found
No related tags found
1 merge request!2681Feature/python main file
......@@ -4,6 +4,7 @@ add_subdirectory(discretization)
add_subdirectory(material)
add_subdirectory(io)
add_subdirectory(porousmediumflow)
add_subdirectory(wrapping)
add_python_targets(dumux
__init__
......
add_python_targets(wrapping
__init__
)
"""Helper classes and function related Python <-> C++ interaction"""
import functools
from typing import Callable, Type
def cppWrapperCreator(creator: Callable) -> Callable:
"""
Decorator for creator functions that return a C++ type with Python bindings
resulting from C++ code generation and just-in-time compilation
"""
def makeCreator(aliasClass: Type) -> Callable:
@functools.wraps(creator)
def _makeCreator(*args, **kwargs):
return creator(*args, **kwargs)
# make the creator assume the name of the alias class
_makeCreator.__name__ = aliasClass.__name__
return _makeCreator
return makeCreator
def cppWrapperClassAlias(creator: Callable) -> Callable:
"""
Decorator for a class alias corresponding to a creator function
This makes the creator function appear like a class constructor
Args:
creator (Callable): The corresponding creator function the
decorated class is an alias for
Returns:
Callable: The creator function with the alias name
"""
def makeCreator(aliasClass: Type) -> Callable:
return creator(aliasClass)
return makeCreator
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment