本文整理汇总了Python中pybindgen.cppclass.CppClass方法的典型用法代码示例。如果您正苦于以下问题:Python cppclass.CppClass方法的具体用法?Python cppclass.CppClass怎么用?Python cppclass.CppClass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pybindgen.cppclass
的用法示例。
在下文中一共展示了cppclass.CppClass方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: boost_shared_ptr_instance_creation_function
# 需要导入模块: from pybindgen import cppclass [as 别名]
# 或者: from pybindgen.cppclass import CppClass [as 别名]
def boost_shared_ptr_instance_creation_function(cpp_class, code_block, lvalue,
parameters, construct_type_name):
"""
boost::shared_ptr "instance creation function"; it is called whenever a new
C++ class instance needs to be created
:param cpp_class: the CppClass object whose instance is to be created
:param code_block: CodeBlock object on which the instance creation code should be generated
:param lvalue: lvalue expression that should hold the result in the end
:param parameters: stringified list of parameters
:param construct_type_name: actual name of type to be constructed (it is
not always the class name, sometimes it's
the python helper class)
"""
assert lvalue
assert not lvalue.startswith('None')
if cpp_class.incomplete_type:
raise CodeGenerationError("%s cannot be constructed (incomplete type)"
% cpp_class.full_name)
code_block.write_code(
"%s.reset (new %s(%s));" % (lvalue, construct_type_name, parameters))
示例2: std_shared_ptr_instance_creation_function
# 需要导入模块: from pybindgen import cppclass [as 别名]
# 或者: from pybindgen.cppclass import CppClass [as 别名]
def std_shared_ptr_instance_creation_function(cpp_class, code_block, lvalue,
parameters, construct_type_name):
"""
std::shared_ptr "instance creation function"; it is called whenever a new
C++ class instance needs to be created
:param cpp_class: the CppClass object whose instance is to be created
:param code_block: CodeBlock object on which the instance creation code should be generated
:param lvalue: lvalue expression that should hold the result in the end
:param parameters: stringified list of parameters
:param construct_type_name: actual name of type to be constructed (it is
not always the class name, sometimes it's
the python helper class)
"""
assert lvalue
assert not lvalue.startswith('None')
if cpp_class.incomplete_type:
raise CodeGenerationError("%s cannot be constructed (incomplete type)"
% cpp_class.full_name)
code_block.write_code(
"%s = std::make_shared<%s>(%s);" % (lvalue, construct_type_name, parameters))
示例3: convert_python_to_c
# 需要导入模块: from pybindgen import cppclass [as 别名]
# 或者: from pybindgen.cppclass import CppClass [as 别名]
def convert_python_to_c(self, wrapper):
"parses python args to get C++ value"
assert isinstance(wrapper, ForwardWrapperBase)
assert isinstance(self.cpp_class, CppClass)
self.py_name = wrapper.declarations.declare_variable(
self.cpp_class.pystruct+'*', self.name,
initializer=(self.default_value and 'NULL' or None))
value_ptr = wrapper.declarations.declare_variable(
self.cpp_class.memory_policy.get_pointer_name(self.cpp_class.full_name), "%s_ptr" % self.name)
if self.null_ok:
num = wrapper.parse_params.add_parameter('O', ['&'+self.py_name], self.name, optional=bool(self.default_value))
wrapper.before_call.write_error_check(
"%s && ((PyObject *) %s != Py_None) && !PyObject_IsInstance((PyObject *) %s, (PyObject *) &%s)"
% (self.py_name, self.py_name, self.py_name, self.cpp_class.pytypestruct),
'PyErr_SetString(PyExc_TypeError, "Parameter %i must be of type %s");' % (num, self.cpp_class.name))
wrapper.before_call.write_code("if (%(PYNAME)s) {\n"
" if ((PyObject *) %(PYNAME)s == Py_None)\n"
" %(VALUE)s = NULL;\n"
" else\n"
" %(VALUE)s = %(PYNAME)s->obj;\n"
"} else {\n"
" %(VALUE)s = NULL;\n"
"}" % dict(PYNAME=self.py_name, VALUE=value_ptr))
else:
wrapper.parse_params.add_parameter(
'O!', ['&'+self.cpp_class.pytypestruct, '&'+self.py_name], self.name, optional=bool(self.default_value))
wrapper.before_call.write_code("if (%s) { %s = %s->obj; }" % (self.py_name, value_ptr, self.py_name))
wrapper.call_params.append(value_ptr)
示例4: __init__
# 需要导入模块: from pybindgen import cppclass [as 别名]
# 或者: from pybindgen.cppclass import CppClass [as 别名]
def __init__(self, name, values, values_prefix='', cpp_namespace=None, outer_class=None,
import_from_module=None):
"""
Creates a new enum wrapper, which should be added to a module with module.add_enum().
:param name: C name of the enum type
:param values: a list of strings with all enumeration value names, or list of (name, C-value-expr) tuples.
:param values_prefix: prefix to add to value names, or None
:param cpp_namespace: optional C++ namespace identifier, or None.
Note: this namespace is *in addition to*
whatever namespace of the module the enum
belongs to. Typically this parameter is to
be used when wrapping enums declared inside
C++ classes.
:param import_from_module: if not None, the enum is defined in
another module, this parameter gives the name of the module
"""
assert isinstance(name, string_types)
assert '::' not in name
assert outer_class is None or isinstance(outer_class, CppClass)
self.outer_class = outer_class
for val in values:
if not isinstance(val, string_types + (tuple,)):
raise TypeError
#if not name:
# raise ValueError
self.name = name
self.full_name = None
self.values = list(values)
self.values_prefix = values_prefix
self.cpp_namespace = cpp_namespace
self._module = None
self.ThisEnumParameter = None
self.ThisEnumReturn = None
self.import_from_module = import_from_module