Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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')])
def module_init():
root_module = Module('ns.config_store', cpp_namespace='::ns3')
return root_module
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
)
def module_init():
root_module = Module('ns.antenna', cpp_namespace='::ns3')
return root_module
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) )
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'), [])
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')])
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) )
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) )