本文整理汇总了Python中pybindgen.Parameter.new方法的典型用法代码示例。如果您正苦于以下问题:Python Parameter.new方法的具体用法?Python Parameter.new怎么用?Python Parameter.new使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pybindgen.Parameter
的用法示例。
在下文中一共展示了Parameter.new方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_std_ofstream
# 需要导入模块: from pybindgen import Parameter [as 别名]
# 或者: from pybindgen.Parameter import new [as 别名]
def add_std_ofstream(module):
module.add_include('<fstream>')
ostream = module.add_class('ostream', foreign_cpp_namespace='::std')
ostream.set_cannot_be_constructed("abstract base class")
ofstream = module.add_class('ofstream', foreign_cpp_namespace='::std', parent=ostream)
ofstream.add_enum('openmode', [
('app', 'std::ios_base::app'),
('ate', 'std::ios_base::ate'),
('binary', 'std::ios_base::binary'),
('in', 'std::ios_base::in'),
('out', 'std::ios_base::out'),
('trunc', 'std::ios_base::trunc'),
])
ofstream.add_constructor([Parameter.new("const char *", 'filename'),
Parameter.new("::std::ofstream::openmode", 'mode', default_value="std::ios_base::out")])
ofstream.add_method('close', None, [])
add_std_ios_openmode(module)
示例2: add_std_ofstream
# 需要导入模块: from pybindgen import Parameter [as 别名]
# 或者: from pybindgen.Parameter import new [as 别名]
def add_std_ofstream(module):
module.add_include('<fstream>')
ostream = module.add_class('ostream', foreign_cpp_namespace='::std')
ostream.set_cannot_be_constructed("abstract base class")
ofstream = module.add_class('ofstream', foreign_cpp_namespace='::std', parent=ostream)
ofstream.add_enum('openmode', [
('app', 'std::ios_base::app'),
('ate', 'std::ios_base::ate'),
('binary', 'std::ios_base::binary'),
('in', 'std::ios_base::in'),
('out', 'std::ios_base::out'),
('trunc', 'std::ios_base::trunc'),
])
ofstream.add_constructor([Parameter.new("const char *", 'filename'),
Parameter.new("::std::ofstream::openmode", 'mode', default_value="std::ios_base::out")])
ofstream.add_method('close', None, [])
import pybindgen.typehandlers.base
for alias in "std::_Ios_Openmode", "std::ios::openmode":
pybindgen.typehandlers.base.param_type_matcher.add_type_alias(alias, "int")
for flag in 'in', 'out', 'ate', 'app', 'trunc', 'binary':
module.after_init.write_code('PyModule_AddIntConstant(m, (char *) "STD_IOS_%s", std::ios::%s);'
% (flag.upper(), flag))
示例3: add_std_ofstream
# 需要导入模块: from pybindgen import Parameter [as 别名]
# 或者: from pybindgen.Parameter import new [as 别名]
def add_std_ofstream(module):
module.add_include('<fstream>')
ostream = module.add_class('ostream', foreign_cpp_namespace='::std')
ostream.set_cannot_be_constructed("abstract base class")
ofstream = module.add_class('ofstream', foreign_cpp_namespace='::std', parent=ostream)
ofstream.add_enum('openmode', [
('app', 'std::ios_base::app'),
('ate', 'std::ios_base::ate'),
('binary', 'std::ios_base::binary'),
('in', 'std::ios_base::in'),
('out', 'std::ios_base::out'),
('trunc', 'std::ios_base::trunc'),
])
ofstream.add_constructor([Parameter.new("const char *", 'filename'),
Parameter.new("::std::ofstream::openmode", 'mode', default_value="std::ios_base::out")])
ofstream.add_method('close', None, [])
add_std_ios_openmode(module)
示例4: my_module_gen
# 需要导入模块: from pybindgen import Parameter [as 别名]
# 或者: from pybindgen.Parameter import new [as 别名]
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
)
mod.generate(FileCodeSink(out_file))
示例5: my_module_gen
# 需要导入模块: from pybindgen import Parameter [as 别名]
# 或者: from pybindgen.Parameter import new [as 别名]
def my_module_gen(out_file):
mod = Module('b')
mod.add_include('"b.h"')
B = mod.add_class('B')
B.add_constructor([])
B.add_copy_constructor()
B.add_instance_attribute('b_a', ReturnValue.new('uint32_t'))
B.add_instance_attribute('b_b', ReturnValue.new('uint32_t'))
mod.add_function('BDoA', None, [Parameter.new('B', 'b')])
mod.add_function('BDoB', ReturnValue.new('B'), [])
mod.generate(FileCodeSink(out_file) )
示例6: my_module_gen
# 需要导入模块: from pybindgen import Parameter [as 别名]
# 或者: from pybindgen.Parameter import new [as 别名]
def my_module_gen(out_file):
mod = Module('c')
mod.add_include('"c.h"')
C = mod.add_class('C')
C.add_constructor([])
C.add_constructor([Parameter.new('uint32_t', 'c')])
C.add_method('DoA', None, [], is_static=True)
C.add_method('DoB', None, [])
C.add_method('DoC', None, [Parameter.new('uint32_t', 'c')])
C.add_method('DoD', ReturnValue.new('uint32_t'), [])
C.add_method('DoE', None, [], is_virtual=True)
mod.generate(FileCodeSink(out_file) )
示例7: my_module_gen
# 需要导入模块: from pybindgen import Parameter [as 别名]
# 或者: from pybindgen.Parameter import new [as 别名]
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) )
示例8: my_module_gen
# 需要导入模块: from pybindgen import Parameter [as 别名]
# 或者: from pybindgen.Parameter import new [as 别名]
def my_module_gen(out_file):
mod = Module('a')
mod.add_include('"a.h"')
mod.add_function('ADoA', None, [])
mod.add_function('ADoB', None, [Parameter.new('uint32_t', 'b')])
mod.add_function('ADoC', ReturnValue.new('uint32_t'), [])
mod.generate(FileCodeSink(out_file) )
示例9: Object_customizations
# 需要导入模块: from pybindgen import Parameter [as 别名]
# 或者: from pybindgen.Parameter import new [as 别名]
def Object_customizations(module):
## ---------------------------------------------------------------------
## Here we generate custom constructor code for all classes that
## derive from ns3::Object. The custom constructors are needed in
## order to support kwargs only and to translate kwargs into ns3
## attributes, etc.
## ---------------------------------------------------------------------
try:
Object = module['ns3::Object']
except KeyError:
return
## add a GetTypeId method to all generatd helper classes
def helper_class_hook(helper_class):
decl = """
static ns3::TypeId GetTypeId (void)
{
static ns3::TypeId tid = ns3::TypeId ("%s")
.SetParent< %s > ()
;
return tid;
}""" % (helper_class.name, helper_class.class_.full_name)
helper_class.add_custom_method(decl)
helper_class.add_post_generation_code(
"NS_OBJECT_ENSURE_REGISTERED (%s);" % helper_class.name)
Object.add_helper_class_hook(helper_class_hook)
def ns3_object_instance_creation_function(cpp_class, code_block, lvalue,
parameters, construct_type_name):
assert lvalue
assert not lvalue.startswith('None')
if cpp_class.cannot_be_constructed:
raise CodeGenerationError("%s cannot be constructed (%s)"
% cpp_class.full_name)
if cpp_class.incomplete_type:
raise CodeGenerationError("%s cannot be constructed (incomplete type)"
% cpp_class.full_name)
code_block.write_code("%s = new %s(%s);" % (lvalue, construct_type_name, parameters))
code_block.write_code("%s->Ref ();" % (lvalue))
def ns3_object_post_instance_creation_function(cpp_class, code_block, lvalue,
parameters, construct_type_name):
code_block.write_code("ns3::CompleteConstruct(%s);" % (lvalue, ))
Object.set_instance_creation_function(ns3_object_instance_creation_function)
Object.set_post_instance_creation_function(ns3_object_post_instance_creation_function)