How to use the pybindgen.Module 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
def my_module_gen(out_file):

    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')])
github nyuwireless-unipd / ns3-mmwave / src / config-store / bindings / modulegen__gcc_LP64.py View on Github external
def module_init():
    root_module = Module('ns.config_store', cpp_namespace='::ns3')
    return root_module
github Gabrielcarvfer / NS3 / 3rd-party / pybindgen / examples / callback / modulegen.py View on Github external
def my_module_gen(out_file):

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

    mod.header.writeln("""void _wrap_Visit(int value, void *data);""")
    mod.body.writeln("""
void _wrap_Visit(int value, void *data)
{
    PyObject *callback = (PyObject*) data;
    PyObject_CallFunction(callback, (char*) "i", value);
}
""")

    mod.add_function("visit", None, [Parameter.new("Visitor", "visitor")]
                     # the 'data' parameter is inserted automatically
                     # by the custom callback type handler
                     )
github tkn-tub / ns3-gym / src / antenna / bindings / modulegen__gcc_LP64.py View on Github external
def module_init():
    root_module = Module('ns.antenna', cpp_namespace='::ns3')
    return root_module
github gjcarneiro / 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 gjcarneiro / pybindgen / examples / boost_shared_ptr / modulegen.py View on Github external
def my_module_gen(out_file):

    mod = Module('bsp')

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

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

    Foo.add_constructor([param('std::string', 'datum')])
    Foo.add_constructor([])
    Foo.add_method('get_datum', retval('const std::string'), [])
    Foo.add_method('set_datum', None, [param('const std::string', 'datum')])


    mod.add_function('function_that_takes_foo', None,
                     [param('boost::shared_ptr', 'foo')])

    mod.add_function('function_that_returns_foo', retval('boost::shared_ptr'), [])
github LLNL / shroud / regression / run / tutorial / pybindgen / gen.py View on Github external
def generate(fp):
    mod = pybindgen.Module('tutorial')
    mod.add_include('"tutorial.hpp"')
    namespace = mod.add_cpp_namespace('tutorial')

    namespace.add_enum('Color', ['RED', 'BLUE', 'WHITE'])
#    mod.add_function('AcceptEnum', None, [param('MyEnum_e', 'value')])

    # default arguments
    namespace.add_function(
        'Function5', 'double',
        [param('double', 'arg1', default_value='3.1415'),
         param('bool', 'arg2', default_value='true')])

    # overloaded
    namespace.add_function(
        'Function6', None, 
        [param('const std::string &', 'name')])
github gjcarneiro / pybindgen / examples / e / modulegen.py View on Github external
def my_module_gen(out_file):

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

    E = mod.add_class('E', memory_policy=cppclass.ReferenceCountingMethodsPolicy(decref_method='Unref', incref_method='Ref'))
    if 1:
        E.add_function_as_constructor("E::CreateWithRef", ReturnValue.new("E*", caller_owns_return=True), [])
    else:
        ## alternative:
        E.add_function_as_constructor("E::CreateWithoutRef", ReturnValue.new("E*", caller_owns_return=False), [])
    E.add_method("Do", None, [])


    mod.generate(FileCodeSink(out_file) )
github Gabrielcarvfer / NS3 / 3rd-party / pybindgen / examples / import_from_module / amodulegen.py View on Github external
def my_module_gen(out_file):
    mod = Module('a')
    mod.add_include('"a.h"')

    # Base
    Base = mod.add_class("Base", allow_subclassing = True)
    Base.add_constructor([])
    Base.add_method("do_something", None, [], is_virtual=True)

    mod.generate(FileCodeSink(out_file) )