How to use the pybindgen.ReturnValue.new 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 / tests / boost / barmodulegen.py View on Github external
mod = Module('bar')

    mod.add_include ('"bar.h"')

    Foo = mod.add_class('Foo', automatic_type_narrowing=True,
                        memory_policy=BoostSharedPtr('::Foo'))

    Foo.add_static_attribute('instance_count', ReturnValue.new('int'))
    Foo.add_constructor([Parameter.new('std::string', 'datum')])
    Foo.add_constructor([])
    Foo.add_method('get_datum', ReturnValue.new('const std::string'), [])
    Foo.add_method('is_initialized', ReturnValue.new('bool'), [], is_const=True)
    Foo.add_output_stream_operator()


    mod.add_function('function_that_takes_foo', ReturnValue.new('void'),
                               [param('boost::shared_ptr', 'foo')])
    mod.add_function('function_that_returns_foo', retval('boost::shared_ptr'), [])
    
    cls = mod.add_class('ClassThatTakesFoo', allow_subclassing=True)
    cls.add_constructor([Parameter.new('boost::shared_ptr', 'foo')])
    cls.add_method('get_foo', ReturnValue.new('boost::shared_ptr'), [])
    cls.add_method('get_modified_foo', retval('boost::shared_ptr'),
                   [param('boost::shared_ptr', 'foo')],
                   is_virtual=True, is_const=True)


    
    #### --- error handler ---
    class MyErrorHandler(pybindgen.settings.ErrorHandler):
        def __init__(self):
            super(MyErrorHandler, self).__init__()
github gjcarneiro / pybindgen / tests / foomodulegen.py View on Github external
[Parameter.new('Foo&', 'foo', direction=Parameter.DIRECTION_IN)])
    SomeObject.add_method('get_foo_by_ref', ReturnValue.new('void'),
                          [Parameter.new('Foo&', 'foo', direction=Parameter.DIRECTION_OUT)])

    ## custodian/ward tests
    SomeObject.add_method('get_foobar_with_self_as_custodian',
                          ReturnValue.new('Foobar*', custodian=0, reference_existing_object=True), [])
    SomeObject.add_method('get_foobar_with_other_as_custodian',
                          ReturnValue.new('Foobar*', custodian=1, reference_existing_object=True),
                          [Parameter.new('SomeObject*', 'other', transfer_ownership=False)])
    SomeObject.add_method('set_foobar_with_self_as_custodian', ReturnValue.new('void'),
                          [Parameter.new('Foobar*', 'foobar',
                                         transfer_ownership=True, custodian=0)])

    mod.add_function('get_foobar_with_other_as_custodian',
                     ReturnValue.new('Foobar*', custodian=1, reference_existing_object=True),
                     [Parameter.new('SomeObject*', 'other', transfer_ownership=False)])

    mod.add_function('create_new_foobar', ReturnValue.new('Foobar*', caller_owns_return=True), [])

    mod.add_function('set_foobar_with_other_as_custodian', ReturnValue.new('void'),
                     [Parameter.new('Foobar*', 'foobar', transfer_ownership=True, custodian=2),
                      Parameter.new('SomeObject*', 'other', transfer_ownership=False)])

    mod.add_function('set_foobar_with_return_as_custodian',
                     ReturnValue.new('SomeObject*', caller_owns_return=True),
                     [Parameter.new('Foobar*', 'foobar',
                                    transfer_ownership=True, custodian=-1)])


    ## get/set recfcounted object Zbr
    SomeObject.add_method('get_zbr', ReturnValue.new('Zbr*', caller_owns_return=True), [])
github gjcarneiro / pybindgen / tests / foomodulegen.py View on Github external
cls.add_method('get_value', ReturnValue.new('CannotBeConstructed'),
                             [], is_static=True)
    cls.add_method('get_ptr', ReturnValue.new('CannotBeConstructed*', caller_owns_return=True),
                   [], is_static=True)
    mod.add_function('get_cannot_be_constructed_value',
                     ReturnValue.new('CannotBeConstructed'),
                     [])
    mod.add_function('get_cannot_be_constructed_ptr',
                     ReturnValue.new('CannotBeConstructed*', caller_owns_return=True),
                     [])


    ## A nested class
    #NestedClass = mod.add_class('NestedClass', automatic_type_narrowing=True, outer_class=SomeObject)
    NestedClass = SomeObject.add_class('NestedClass', automatic_type_narrowing=True)
    NestedClass.add_static_attribute('instance_count', ReturnValue.new('int'))
    NestedClass.add_constructor([Parameter.new('std::string', 'datum')])
    NestedClass.add_constructor([])
    NestedClass.add_method('get_datum', ReturnValue.new('std::string'), [])

    ## A nested enum..
    #mod.add_enum('NestedEnum', ['FOO_TYPE_AAA', 'FOO_TYPE_BBB', 'FOO_TYPE_CCC'], outer_class=SomeObject)
    SomeObject.add_enum('NestedEnum', ['FOO_TYPE_AAA', 'FOO_TYPE_BBB', 'FOO_TYPE_CCC'])

    ## anonymous enum
    SomeObject.add_enum('', ['CONSTANT_A', 'CONSTANT_B', 'CONSTANT_C'])


    AbstractBaseClass2 = mod.add_class('AbstractBaseClass2', allow_subclassing=True)

    AbstractBaseClass2.add_method('invoke_private_virtual', ReturnValue.new('int'),
                                  [Parameter.new('int', 'x')], is_const=True)
github gjcarneiro / pybindgen / tests / foomodulegen.py View on Github external
mod.add_container('SimpleStructList', ReturnValue.new('simple_struct_t'), 'list')
    mod.add_function('get_simple_list', ReturnValue.new('SimpleStructList'), [])
    mod.add_function('set_simple_list', 'int', [Parameter.new('SimpleStructList', 'list')])

    mod.add_container('std::set', 'float', 'set')

    TestContainer = mod.add_class('TestContainer', allow_subclassing=True)
    TestContainer.add_constructor([])
    TestContainer.add_instance_attribute('m_floatSet', 'std::set')
    TestContainer.add_method('get_simple_list', ReturnValue.new('SimpleStructList'), [], is_virtual=True)
    TestContainer.add_method('set_simple_list', 'int', [Parameter.new('SimpleStructList', 'list')], is_virtual=True)
    TestContainer.add_method('set_simple_list_by_ref', 'int', [Parameter.new('SimpleStructList&', 'inout_list',
                                                                             direction=Parameter.DIRECTION_INOUT)],
                             is_virtual=True)

    mod.add_container('std::vector', ReturnValue.new('simple_struct_t'), 'vector')
    TestContainer.add_method('get_simple_vec', ReturnValue.new('std::vector'), [], is_virtual=True)
    TestContainer.add_method('set_simple_vec', 'int', [Parameter.new('std::vector', 'vec')], is_virtual=True)

    mod.add_container('std::vector', 'std::string', 'vector')
    TestContainer.add_method('get_vec', 'void', [Parameter.new('std::vector &', 'outVec',
                                                               direction=Parameter.DIRECTION_OUT)])

    TestContainer.add_method('set_vec_ptr', 'void', [Parameter.new('std::vector*', 'inVec',
                                                                   direction=Parameter.DIRECTION_IN, transfer_ownership=True)])
    TestContainer.add_method('get_vec_ptr', 'void', [Parameter.new('std::vector*', 'outVec',
                                                                   direction=Parameter.DIRECTION_OUT)])


    mod.add_container('std::map',
                      (ReturnValue.new('std::string'), ReturnValue.new('simple_struct_t')),
                      'map')
github gjcarneiro / pybindgen / tests / foomodulegen.py View on Github external
cls.add_method('GetInstance', ReturnValue.new('SingletonClass*', caller_owns_return=True),
                   [], is_static=True)


    ## A class that has no public default constructor...
    cls = mod.add_class('InterfaceId', is_singleton=True)
    ## A function that returns such a class...
    mod.add_function('make_interface_id', ReturnValue.new('InterfaceId'), [])


    ## A class the cannot be constructed; this will cause late CodeGenerationError's
    cls = mod.add_class('CannotBeConstructed')
    cls.set_cannot_be_constructed("no reason")
    cls.add_method('get_value', ReturnValue.new('CannotBeConstructed'),
                             [], is_static=True)
    cls.add_method('get_ptr', ReturnValue.new('CannotBeConstructed*', caller_owns_return=True),
                   [], is_static=True)
    mod.add_function('get_cannot_be_constructed_value',
                     ReturnValue.new('CannotBeConstructed'),
                     [])
    mod.add_function('get_cannot_be_constructed_ptr',
                     ReturnValue.new('CannotBeConstructed*', caller_owns_return=True),
                     [])


    ## A nested class
    #NestedClass = mod.add_class('NestedClass', automatic_type_narrowing=True, outer_class=SomeObject)
    NestedClass = SomeObject.add_class('NestedClass', automatic_type_narrowing=True)
    NestedClass.add_static_attribute('instance_count', ReturnValue.new('int'))
    NestedClass.add_constructor([Parameter.new('std::string', 'datum')])
    NestedClass.add_constructor([])
    NestedClass.add_method('get_datum', ReturnValue.new('std::string'), [])
github gergo- / pylibjit / libjit-python / modulegen.py View on Github external
def register_Jit_writeelf_methods(root_module, cls):
    cls.add_function_as_constructor("jit_writeelf_create",
                                    ReturnValue.new('jit_writeelf_t', caller_owns_return=True),
                                    [param('const char *', 'library_name')])

    cls.add_function_as_method('jit_writeelf_write', 
                               'bool', 
                               [param('jit_writeelf_t', 'self', transfer_ownership=False),
                                param('const char *', 'filename')],
                               custom_name='write')

    cls.add_function_as_method('jit_writeelf_add_function', 
                               'bool', 
                               [param('jit_writeelf_t', 'self', transfer_ownership=False),
                                param('jit_function_t', 'function'),
                                param('const char *', 'name')],
                               custom_name='add_function')

    cls.add_function_as_method('jit_writeelf_add_needed',
github Gabrielcarvfer / NS3 / bindings / python / ns3modulegen_core_customizations.py View on Github external
if (other != NULL)
            return (other->m_callback == m_callback);
        else
            return false;
    }

''' % (class_name, ', '.join(template_parameters), class_name, class_name, class_name, class_name))
        sink.indent()
        callback_return = template_parameters[0]
        return_ctype = ctypeparser.parse_type(callback_return)
        if ('const' in return_ctype.remove_modifiers()):
            kwargs = {'is_const': True}
        else:
            kwargs = {}
        try:
            return_type = ReturnValue.new(str(return_ctype), **kwargs)
        except (typehandlers.TypeLookupError, typehandlers.TypeConfigurationError) as ex:
            warnings.warn("***** Unable to register callback; Return value '%s' error (used in %s): %r"
                          % (callback_return, cls_name, ex),
                          Warning)
            continue

        arguments = []
        ok = True
        callback_parameters = [arg for arg in template_parameters[1:] if arg != 'ns3::empty']
        for arg_num, arg_type in enumerate(callback_parameters):
            arg_name = 'arg%i' % (arg_num+1)

            param_ctype = ctypeparser.parse_type(arg_type)
            if ('const' in param_ctype.remove_modifiers()):
                kwargs = {'is_const': True}
            else:
github Gabrielcarvfer / NS3 / 3rd-party / pybindgen / examples / d / modulegen.py View on Github external
def my_module_gen(out_file):

    mod = Module('d')
    mod.add_include('"d.h"')

    D = mod.add_class('D', memory_policy=cppclass.FreeFunctionPolicy('DDestroy'))
    D.add_instance_attribute('d', ReturnValue.new('bool'))
    D.add_function_as_constructor("DCreate", ReturnValue.new("D*", caller_owns_return=True), [])
    mod.add_function('DDoA', None, [Parameter.new('D*', 'd', transfer_ownership=False)])
    mod.add_function('DDoB', None, [Parameter.new('D&', 'd', direction=Parameter.DIRECTION_IN)])
    mod.add_function('DDoC', None, [Parameter.new('const D&', 'd',
                                                  direction=Parameter.DIRECTION_IN)])


    mod.generate(FileCodeSink(out_file) )
github gergo- / pylibjit / libjit-python / modulegen.py View on Github external
def register_Jit_context_methods(root_module, cls):
    cls.add_constructor([])

    cls.add_instance_attribute('debugger', 
                               ReturnValue.new('jit_debugger_t',
                                               reference_existing_object=True), 
                               is_const=True,
                               getter='debugger')

    cls.add_instance_attribute('functions', 
                               retval('jit_function_t *'),
                               is_const=True)

    cls.add_method('build_start', 
                   'void', 
                   [])

    cls.add_method('build_end', 
                   'void', 
                   [])
github tkn-tub / ns3-gym / bindings / python / ns3modulegen_core_customizations.py View on Github external
if (other != NULL)
            return (other->m_callback == m_callback);
        else
            return false;
    }

''' % (class_name, ', '.join(template_parameters), class_name, class_name, class_name, class_name))
        sink.indent()
        callback_return = template_parameters[0]
        return_ctype = ctypeparser.parse_type(callback_return)
        if ('const' in return_ctype.remove_modifiers()):
            kwargs = {'is_const': True}
        else:
            kwargs = {}
        try:
            return_type = ReturnValue.new(str(return_ctype), **kwargs)
        except (typehandlers.TypeLookupError, typehandlers.TypeConfigurationError) as ex:
            warnings.warn("***** Unable to register callback; Return value '%s' error (used in %s): %r"
                          % (callback_return, cls_name, ex),
                          Warning)
            continue

        arguments = []
        ok = True
        callback_parameters = [arg for arg in template_parameters[1:] if arg != 'ns3::empty']
        for arg_num, arg_type in enumerate(callback_parameters):
            arg_name = 'arg%i' % (arg_num+1)

            param_ctype = ctypeparser.parse_type(arg_type)
            if ('const' in param_ctype.remove_modifiers()):
                kwargs = {'is_const': True}
            else: