How to use the pybindgen.typehandlers.base.ForwardWrapperBase function in PyBindGen

To help you get started, we’ve selected a few PyBindGen examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gjcarneiro / pybindgen / pybindgen / container.py View on Github external
def convert_python_to_c(self, wrapper):
        "parses python args to get C++ value"
        assert isinstance(wrapper, ForwardWrapperBase)
        assert isinstance(self.container_type, Container)

        assert self.default_value is None, "default value not implemented for containers"

        #self.py_name = wrapper.declarations.declare_variable('PyObject*', self.name)
        container_tmp_var = wrapper.declarations.declare_variable(
            self.container_type.full_name, self.name + '_value')
        wrapper.parse_params.add_parameter('O&', [self.container_type.python_to_c_converter, '&'+container_tmp_var], self.name)
        wrapper.call_params.append(container_tmp_var)
github nyuwireless-unipd / ns3-mmwave / bindings / python / ns3modulegen_core_customizations.py View on Github external
def convert_python_to_c(self, wrapper):
        assert isinstance(wrapper, ForwardWrapperBase)
        name = wrapper.declarations.declare_variable("std::ios::openmode", self.name, self.default_value)
        wrapper.parse_params.add_parameter('i', ['&'+name], self.name, optional=bool(self.default_value))
        wrapper.call_params.append(name)
github Gabrielcarvfer / NS3 / 3rd-party / pybindgen / pybindgen / cppclass_container.py View on Github external
"""
Add container iteration powers to wrapped C++ classes
"""

from pybindgen.typehandlers.base import ForwardWrapperBase
from pybindgen.typehandlers import codesink
from pybindgen.pytypeobject import PyTypeObject
from pybindgen import utils


class IterNextWrapper(ForwardWrapperBase):
    '''
    tp_iternext wrapper
    '''

    HAVE_RETURN_VALUE = True

    def __init__(self, container):
        """
        value_type -- a ReturnValue object handling the value type;
        container -- the L{Container}
        """
        super(IterNextWrapper, self).__init__(
            None, [], "return NULL;", "return NULL;", no_c_retval=True)
        assert isinstance(container, CppClassContainerTraits)
        self.container = container
        self.c_function_name = "_wrap_%s__tp_iternext" % (self.container.iter_pystruct)
github gjcarneiro / pybindgen / pybindgen / typehandlers / inttype.py View on Github external
def convert_python_to_c(self, wrapper):
        assert isinstance(wrapper, ForwardWrapperBase)
        name = wrapper.declarations.declare_variable("int", self.name, self.default_value)
        wrapper.parse_params.add_parameter('i', ['&'+name], self.name, optional=bool(self.default_value))
        wrapper.before_call.write_error_check('%s > 0x7fff' % name,
                                              'PyErr_SetString(PyExc_ValueError, "Out of range");')
        wrapper.call_params.append(name)
github fetchai / ledger / to-sort / python / pybindgen / cppmethod.py View on Github external
raise TypeError("this is a DummyParameter")


class CppDummyMethod(CppMethod):
    """
    A 'dummy' method; cannot be generated due to incomple or incorrect
    parameters, but is added to the class to model the missing method.
    """

    def __init__(self, method_name, return_value, parameters, *args, **kwargs):
        return_value = DummyReturnValue(return_value)
        parameters = [DummyParameter(p) for p in parameters]
        super(CppDummyMethod, self).__init__(method_name, return_value, parameters, *args, **kwargs)


class CppConstructor(ForwardWrapperBase):
    """
    Class that generates a wrapper to a C++ class constructor.  Such
    wrapper is used as the python class __init__ method.
    """

    def __init__(self, parameters, unblock_threads=None, visibility='public', deprecated=False, throw=(), injector = None):
        """

        :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
github Gabrielcarvfer / NS3 / 3rd-party / pybindgen / pybindgen / cppattribute.py View on Github external
import sys

PY3 = (sys.version_info[0] >= 3)
if PY3:
    string_types = str,
else:
    string_types = basestring,


from pybindgen.typehandlers.base import ForwardWrapperBase, ReverseWrapperBase
from pybindgen.typehandlers import codesink
from pybindgen import settings
from pybindgen import utils


class PyGetter(ForwardWrapperBase):
    """generates a getter, for use in a PyGetSetDef table"""
    def generate(self, code_sink):
        """Generate the code of the getter to the given code sink"""
        raise NotImplementedError
    def generate_call(self):
        """(not actually called)"""
        raise AssertionError

class PySetter(ReverseWrapperBase):
    """generates a setter, for use in a PyGetSetDef table"""
    NO_GIL_LOCKING = True
    def generate(self, code_sink):
        """Generate the code of the setter to the given code sink"""
        raise NotImplementedError
    def generate_python_call(self):
        """(not actually called)"""
github fetchai / ledger / to-sort / python / pybindgen / cppmethod.py View on Github external
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.injector = injector

        self.custodians_and_wards = [] # list of (custodian, ward, postcall)
        from . import cppclass
github gjcarneiro / pybindgen / pybindgen / overloading.py View on Github external
def add(self, wrapper):
        """
        Add a wrapper to the overloaded wrapper
        wrapper -- a Wrapper object
        """
        assert isinstance(wrapper, ForwardWrapperBase)
        self.wrappers.append(wrapper)
        return wrapper
github fetchai / ledger / to-sort / python / pybindgen / cppmethod.py View on Github external
import warnings
import traceback
from copy import copy

from pybindgen.typehandlers.base import ForwardWrapperBase, ReverseWrapperBase, \
    join_ctype_and_name, CodeGenerationError
from pybindgen.typehandlers.base import ReturnValue, Parameter
from pybindgen.typehandlers import codesink
from pybindgen import overloading
from pybindgen import settings
from pybindgen import utils
from pybindgen.cppexception import CppException


class CppMethod(ForwardWrapperBase):
    """
    Class that generates a wrapper to a C++ class method
    """

    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=(),
                 injector = None):
        """
        Create an object the generates code to wrap a C++ class method.

        :param return_value: the method return value
        :type  return_value: L{ReturnValue}
github gjcarneiro / pybindgen / pybindgen / function.py View on Github external
from copy import copy

from pybindgen.typehandlers.base import ForwardWrapperBase, ReturnValue
from pybindgen.typehandlers import codesink
from pybindgen.cppexception import CppException

from pybindgen import overloading
from pybindgen import settings
from pybindgen import utils

import warnings
import traceback

class Function(ForwardWrapperBase):
    """
    Class that generates a wrapper to a C function.
    """

    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