本文整理汇总了Python中pybindgen.typehandlers.base.CodeGenerationError方法的典型用法代码示例。如果您正苦于以下问题:Python base.CodeGenerationError方法的具体用法?Python base.CodeGenerationError怎么用?Python base.CodeGenerationError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pybindgen.typehandlers.base
的用法示例。
在下文中一共展示了base.CodeGenerationError方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Object_customizations
# 需要导入模块: from pybindgen.typehandlers import base [as 别名]
# 或者: from pybindgen.typehandlers.base import CodeGenerationError [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)
示例2: get_py_method_def
# 需要导入模块: from pybindgen.typehandlers import base [as 别名]
# 或者: from pybindgen.typehandlers.base import CodeGenerationError [as 别名]
def get_py_method_def(self, name):
"""
Returns an array element to use in a PyMethodDef table.
Should only be called after code generation.
name -- python wrapper/method name
"""
if len(self.all_wrappers) == 1 \
and not getattr(self.all_wrappers[0], 'NEEDS_OVERLOADING_INTERFACE', False):
return self.all_wrappers[0].get_py_method_def(name)
else:
self._normalize_py_method_flags()
flags = self.all_wrappers[0].get_py_method_def_flags()
## detect inconsistencies in flags; they must all be the same
if __debug__:
for func in self.all_wrappers:
try:
assert set(func.get_py_method_def_flags()) == set(flags),\
("Expected PyMethodDef flags %r, got %r"
% (flags, func.get_py_method_def_flags()))
except (TypeConfigurationError,
CodeGenerationError,
NotSupportedError):
pass
# check available docstrings for the overloads
docstrings_set = set()
for wrap in self.all_wrappers:
if wrap.docstring is not None:
docstrings_set.add(wrap.docstring)
docstring = None
if len(docstrings_set) is 1:
docstring = docstrings_set.pop()
elif len(docstrings_set) > 1:
raise CodeGenerationError("Overloaded '%s' has conflicting docstrings" % self.wrapper_name)
assert isinstance(self.wrapper_return, string_types)
assert isinstance(self.wrapper_actual_name, string_types)
assert isinstance(self.wrapper_args, list)
return "{(char *) \"%s\", (PyCFunction) %s, %s, %s }," % \
(name, self.wrapper_actual_name, '|'.join(flags),
(docstring is None and "NULL" or ('"'+docstring+'"')))