當前位置: 首頁>>代碼示例>>Python>>正文


Python cppclass.CppClass方法代碼示例

本文整理匯總了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)) 
開發者ID:KTH,項目名稱:royal-chaos,代碼行數:23,代碼來源:smart_ptr.py

示例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)) 
開發者ID:KTH,項目名稱:royal-chaos,代碼行數:23,代碼來源:smart_ptr.py

示例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) 
開發者ID:KTH,項目名稱:royal-chaos,代碼行數:40,代碼來源:smart_ptr.py

示例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 
開發者ID:KTH,項目名稱:royal-chaos,代碼行數:38,代碼來源:enum.py


注:本文中的pybindgen.cppclass.CppClass方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。