def __init__(self, c_function_name, return_value, parameters, unblock_threads=None): """ :param c_function_name: name of the C/C++ function; FIXME: for now it is implied that this function returns a pointer to the a class instance with caller_owns_return=True semantics. :param return_value: function return value type :type return_value: L{ReturnValue} :param parameters: the function/constructor parameters :type parameters: list of L{Parameter} """ self.stack_where_defined = traceback.extract_stack() if unblock_threads is None: unblock_threads = settings.unblock_threads parameters = [utils.eval_param(param, self) for param in parameters] super(CppFunctionAsConstructor, self).__init__(parameters) self.c_function_name = c_function_name self.function_return_value = return_value
def __init__(self, parameters, unblock_threads=None, visibility='public', deprecated=False, throw=()): """ :param parameters: the constructor parameters :param deprecated: deprecation state for this API: False=Not deprecated; True=Deprecated; "message"=Deprecated, and deprecation warning contains the given message :param throw: list of C++ exceptions that the constructor may throw :type throw: list of :class:`pybindgen.cppexception.CppException` """ self.stack_where_defined = traceback.extract_stack() if unblock_threads is None: unblock_threads = settings.unblock_threads parameters = [utils.eval_param(param, self) for param in parameters] super(CppConstructor, self).__init__( None, parameters, "return -1;", "return -1;", force_parse=ForwardWrapperBase.PARSE_TUPLE_AND_KEYWORDS, unblock_threads=unblock_threads) self.deprecated = deprecated assert visibility in ['public', 'protected', 'private'] self.visibility = visibility self.wrapper_base_name = None self.wrapper_actual_name = None self._class = None for t in throw: assert isinstance(t, CppException) self.throw = list(throw) self.custodians_and_wards = [] # list of (custodian, ward, postcall) cppclass_typehandlers.scan_custodians_and_wards(self)
def __init__(self, parameters, unblock_threads=None, visibility="public", deprecated=False, throw=()): """ :param parameters: the constructor parameters :param deprecated: deprecation state for this API: False=Not deprecated; True=Deprecated; "message"=Deprecated, and deprecation warning contains the given message :param throw: list of C++ exceptions that the constructor may throw :type throw: list of :class:`pybindgen.cppexception.CppException` """ self.stack_where_defined = traceback.extract_stack() if unblock_threads is None: unblock_threads = settings.unblock_threads parameters = [utils.eval_param(param, self) for param in parameters] super(CppConstructor, self).__init__( None, parameters, "return -1;", "return -1;", force_parse=ForwardWrapperBase.PARSE_TUPLE_AND_KEYWORDS, unblock_threads=unblock_threads, ) self.deprecated = deprecated assert visibility in ["public", "protected", "private"] self.visibility = visibility self.wrapper_base_name = None self.wrapper_actual_name = None self._class = None for t in throw: assert isinstance(t, CppException) self.throw = list(throw) self.custodians_and_wards = [] # list of (custodian, ward, postcall) cppclass_typehandlers.scan_custodians_and_wards(self)
def __init__( self, function_name, return_value, parameters, docstring=None, unblock_threads=None, template_parameters=(), custom_name=None, deprecated=False, foreign_cpp_namespace=None, throw=(), ): """ :param function_name: name of the C function :param return_value: the function return value :type return_value: L{ReturnValue} :param parameters: the function parameters :type parameters: list of L{Parameter} :param custom_name: an alternative name to give to this function at python-side; if omitted, the name of the function in the python module will be the same name as the function in C++ (minus namespace). :param deprecated: deprecation state for this API: - False: Not deprecated - True: Deprecated - "message": Deprecated, and deprecation warning contains the given message :param foreign_cpp_namespace: if set, the function is assumed to belong to the given C++ namespace, regardless of the C++ namespace of the python module it will be added to. :param throw: list of C++ exceptions that the function may throw :type throw: list of L{CppException} """ self.stack_where_defined = traceback.extract_stack() if unblock_threads is None: unblock_threads = settings.unblock_threads ## backward compatibility check if isinstance(return_value, str) and isinstance(function_name, ReturnValue): warnings.warn( "Function has changed API; see the API documentation (but trying to correct...)", DeprecationWarning, stacklevel=2, ) function_name, return_value = return_value, function_name if return_value is None: return_value = ReturnValue.new("void") return_value = utils.eval_retval(return_value, self) parameters = [utils.eval_param(param, self) for param in parameters] super(Function, self).__init__( return_value, parameters, parse_error_return="return NULL;", error_return="return NULL;", unblock_threads=unblock_threads, ) self.deprecated = deprecated self.foreign_cpp_namespace = foreign_cpp_namespace self._module = None function_name = utils.ascii(function_name) self.function_name = function_name self.wrapper_base_name = None self.wrapper_actual_name = None self.docstring = docstring self.self_parameter_pystruct = None self.template_parameters = template_parameters self.custom_name = custom_name self.mangled_name = utils.get_mangled_name(function_name, self.template_parameters) for t in throw: assert isinstance(t, CppException) self.throw = list(throw) self.custodians_and_wards = [] # list of (custodian, ward, postcall) cppclass_typehandlers.scan_custodians_and_wards(self)
def __init__( self, method_name, return_value, parameters, is_static=False, template_parameters=(), is_virtual=None, is_const=False, unblock_threads=None, is_pure_virtual=False, custom_template_method_name=None, visibility="public", custom_name=None, deprecated=False, docstring=None, throw=(), ): """ Create an object the generates code to wrap a C++ class method. :param return_value: the method return value :type return_value: L{ReturnValue} :param method_name: name of the method :param parameters: the method parameters :type parameters: list of :class:`pybindgen.typehandlers.base.Parameter` :param is_static: whether it is a static method :param template_parameters: optional list of template parameters needed to invoke the method :type template_parameters: list of strings, each element a template parameter expression :param is_virtual: whether the method is virtual (pure or not) :param is_const: whether the method has a const modifier on it :param unblock_threads: whether to release the Python GIL around the method call or not. If None or omitted, use global settings. Releasing the GIL has a small performance penalty, but is recommended if the method is expected to take considerable time to complete, because otherwise no other Python thread is allowed to run until the method completes. :param is_pure_virtual: whether the method is defined as "pure virtual", i.e. virtual method with no default implementation in the class being wrapped. :param custom_name: alternate name to give to the method, in python side. :param custom_template_method_name: (deprecated) same as parameter 'custom_name'. :param visibility: visibility of the method within the C++ class :type visibility: a string (allowed values are 'public', 'protected', 'private') :param deprecated: deprecation state for this API: - False: Not deprecated - True: Deprecated - "message": Deprecated, and deprecation warning contains the given message :param throw: list of C++ exceptions that the function may throw :type throw: list of L{CppException} """ self.stack_where_defined = traceback.extract_stack() ## backward compatibility check if isinstance(return_value, str) and isinstance(method_name, ReturnValue): warnings.warn( "CppMethod has changed API; see the API documentation (but trying to correct...)", DeprecationWarning, stacklevel=2, ) method_name, return_value = return_value, method_name # bug 399870 if is_virtual is None: is_virtual = is_pure_virtual if return_value is None: return_value = ReturnValue.new("void") if unblock_threads is None: unblock_threads = settings.unblock_threads assert visibility in ["public", "protected", "private"] self.visibility = visibility self.method_name = method_name self.is_static = is_static self.is_virtual = is_virtual self.is_pure_virtual = is_pure_virtual self.is_const = is_const self.template_parameters = template_parameters self.custom_name = custom_name or custom_template_method_name # self.static_decl = True self._class = None self._helper_class = None self.docstring = docstring self.wrapper_base_name = None self.wrapper_actual_name = None self.return_value = None self.parameters = None return_value = utils.eval_retval(return_value, self) parameters = [utils.eval_param(param, self) for param in parameters] super(CppMethod, self).__init__( return_value, parameters, "return NULL;", "return NULL;", unblock_threads=unblock_threads ) self.deprecated = deprecated for t in throw: assert isinstance(t, CppException) self.throw = list(throw) self.custodians_and_wards = [] # list of (custodian, ward, postcall) cppclass_typehandlers.scan_custodians_and_wards(self)
def __init__(self, function_name, return_value, parameters, docstring=None, unblock_threads=None, template_parameters=(), custom_name=None, deprecated=False, foreign_cpp_namespace=None, throw=()): """ :param function_name: name of the C function :param return_value: the function return value :type return_value: L{ReturnValue} :param parameters: the function parameters :type parameters: list of L{Parameter} :param custom_name: an alternative name to give to this function at python-side; if omitted, the name of the function in the python module will be the same name as the function in C++ (minus namespace). :param deprecated: deprecation state for this API: - False: Not deprecated - True: Deprecated - "message": Deprecated, and deprecation warning contains the given message :param foreign_cpp_namespace: if set, the function is assumed to belong to the given C++ namespace, regardless of the C++ namespace of the python module it will be added to. :param throw: list of C++ exceptions that the function may throw :type throw: list of L{CppException} """ self.stack_where_defined = traceback.extract_stack() if unblock_threads is None: unblock_threads = settings.unblock_threads ## backward compatibility check if isinstance(return_value, str) and isinstance( function_name, ReturnValue): warnings.warn( "Function has changed API; see the API documentation (but trying to correct...)", DeprecationWarning, stacklevel=2) function_name, return_value = return_value, function_name if return_value is None: return_value = ReturnValue.new('void') return_value = utils.eval_retval(return_value, self) parameters = [utils.eval_param(param, self) for param in parameters] super(Function, self).__init__(return_value, parameters, parse_error_return="return NULL;", error_return="return NULL;", unblock_threads=unblock_threads) self.deprecated = deprecated self.foreign_cpp_namespace = foreign_cpp_namespace self._module = None function_name = utils.ascii(function_name) self.function_name = function_name self.wrapper_base_name = None self.wrapper_actual_name = None self.docstring = docstring self.self_parameter_pystruct = None self.template_parameters = template_parameters self.custom_name = custom_name self.mangled_name = utils.get_mangled_name(function_name, self.template_parameters) for t in throw: assert isinstance(t, CppException) self.throw = list(throw) self.custodians_and_wards = [] # list of (custodian, ward, postcall) cppclass_typehandlers.scan_custodians_and_wards(self)
def __init__(self, method_name, return_value, parameters, is_static=False, template_parameters=(), is_virtual=None, is_const=False, unblock_threads=None, is_pure_virtual=False, custom_template_method_name=None, visibility='public', custom_name=None, deprecated=False, docstring=None, throw=()): """ Create an object the generates code to wrap a C++ class method. :param return_value: the method return value :type return_value: L{ReturnValue} :param method_name: name of the method :param parameters: the method parameters :type parameters: list of :class:`pybindgen.typehandlers.base.Parameter` :param is_static: whether it is a static method :param template_parameters: optional list of template parameters needed to invoke the method :type template_parameters: list of strings, each element a template parameter expression :param is_virtual: whether the method is virtual (pure or not) :param is_const: whether the method has a const modifier on it :param unblock_threads: whether to release the Python GIL around the method call or not. If None or omitted, use global settings. Releasing the GIL has a small performance penalty, but is recommended if the method is expected to take considerable time to complete, because otherwise no other Python thread is allowed to run until the method completes. :param is_pure_virtual: whether the method is defined as "pure virtual", i.e. virtual method with no default implementation in the class being wrapped. :param custom_name: alternate name to give to the method, in python side. :param custom_template_method_name: (deprecated) same as parameter 'custom_name'. :param visibility: visibility of the method within the C++ class :type visibility: a string (allowed values are 'public', 'protected', 'private') :param deprecated: deprecation state for this API: - False: Not deprecated - True: Deprecated - "message": Deprecated, and deprecation warning contains the given message :param throw: list of C++ exceptions that the function may throw :type throw: list of L{CppException} """ self.stack_where_defined = traceback.extract_stack() ## backward compatibility check if isinstance(return_value, str) and isinstance( method_name, ReturnValue): warnings.warn( "CppMethod has changed API; see the API documentation (but trying to correct...)", DeprecationWarning, stacklevel=2) method_name, return_value = return_value, method_name # bug 399870 if is_virtual is None: is_virtual = is_pure_virtual if return_value is None: return_value = ReturnValue.new('void') if unblock_threads is None: unblock_threads = settings.unblock_threads assert visibility in ['public', 'protected', 'private'] self.visibility = visibility self.method_name = method_name self.is_static = is_static self.is_virtual = is_virtual self.is_pure_virtual = is_pure_virtual self.is_const = is_const self.template_parameters = template_parameters self.custom_name = (custom_name or custom_template_method_name) #self.static_decl = True self._class = None self._helper_class = None self.docstring = docstring self.wrapper_base_name = None self.wrapper_actual_name = None self.return_value = None self.parameters = None return_value = utils.eval_retval(return_value, self) parameters = [utils.eval_param(param, self) for param in parameters] super(CppMethod, self).__init__(return_value, parameters, "return NULL;", "return NULL;", unblock_threads=unblock_threads) self.deprecated = deprecated for t in throw: assert isinstance(t, CppException) self.throw = list(throw) self.custodians_and_wards = [] # list of (custodian, ward, postcall) cppclass_typehandlers.scan_custodians_and_wards(self)