Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
cls_name,
default_container_name='std::vector',
default_compare='std::less'):
cls_name = defaults_eraser.replace_basic_string(cls_name)
c_name, c_args = templates.split(cls_name)
if 3 != len(c_args):
return
dc_no_defaults = defaults_eraser.erase_recursive(c_args[1])
if defaults_eraser.normalize(dc_no_defaults) \
!= defaults_eraser.normalize(
templates.join(default_container_name, [c_args[0]])):
return
dcomp_no_defaults = defaults_eraser.erase_recursive(c_args[2])
if defaults_eraser.normalize(dcomp_no_defaults) \
!= defaults_eraser.normalize(
templates.join(default_compare, [c_args[0]])):
return
value_type = defaults_eraser.erase_recursive(c_args[0])
return templates.join(c_name, [value_type])
def get_partial_name(name):
from . import container_traits # prevent cyclic dependencies
ct = container_traits.find_container_traits(name)
if ct:
return ct.remove_defaults(name)
if templates.is_instantiation(name):
tmpl_name, args = templates.split(name)
for i, arg_name in enumerate(args):
args[i] = get_partial_name(arg_name.strip())
return templates.join(tmpl_name, args)
return name
def erase_container(cls_name, default_container_name='std::deque'):
cls_name = defaults_eraser.replace_basic_string(cls_name)
c_name, c_args = templates.split(cls_name)
if 2 != len(c_args):
return
value_type = c_args[0]
dc_no_defaults = defaults_eraser.erase_recursive(c_args[1])
if defaults_eraser.normalize(dc_no_defaults) \
!= defaults_eraser.normalize(
templates.join(default_container_name, [value_type])):
return
return templates.join(
c_name, [defaults_eraser.erase_recursive(value_type)])
def renameTypesInSTL(self, s):
if s.startswith("std::") and \
pygccxml.declarations.templates.is_instantiation(s):
args = []
for arg in pygccxml.declarations.templates.args(s):
t, d = SwigInputGenerator.typeAndDecorators(arg)
args.append(self.renameTypesInSTL(self.get_alias(t)) + d)
return pygccxml.declarations.templates.join(
pygccxml.declarations.templates.name(s),
args) + SwigInputGenerator.typeAndDecorators(s)[1]
return s
"$allocator< $mapped_type > >")
else:
return
for ns in std_namespaces:
inst = tmpl.substitute(
container=c_name,
key_type=key_type,
mapped_type=mapped_type,
hash=ns + '::' + default_hash,
less=default_less,
equal_to=default_equal_to,
allocator=default_allocator)
if defaults_eraser.normalize(cls_name) == \
defaults_eraser.normalize(inst):
return templates.join(
c_name,
[defaults_eraser.erase_recursive(key_type),
defaults_eraser.erase_recursive(mapped_type)])
def _create_impl(self):
implicitly_convertible = algorithm.create_identifier( self, '::boost::python::implicitly_convertible' )
from_arg = algorithm.create_identifier( self
, self.declaration.arguments[0].type.partial_decl_string)
to_name = declarations.full_name( self.declaration.parent, with_defaults=False )
to_arg = algorithm.create_identifier( self, to_name )
return declarations.templates.join(implicitly_convertible, [from_arg, to_arg ]) \
+ '();'
def _generate_bases(self, base_creators):
bases = []
assert isinstance( self.declaration, declarations.class_t )
for base_desc in self.declaration.bases:
assert isinstance( base_desc, declarations.hierarchy_info_t )
if base_desc.access != declarations.ACCESS_TYPES.PUBLIC:
continue
if base_creators.has_key( id(base_desc.related_class) ):
bases.append( algorithm.create_identifier( self, base_desc.related_class.partial_decl_string ) )
elif base_desc.related_class.already_exposed:
bases.append( base_desc.related_class.partial_decl_string )
if not bases:
return None
bases_identifier = algorithm.create_identifier( self, '::boost::python::bases' )
return declarations.templates.join( bases_identifier, bases )
def _call_type_constructor( self, type ):
x = declarations.remove_reference( type )
x = declarations.remove_cv( x )
other = algorithm.create_identifier( self, '::boost::python::other' )
type_ = algorithm.create_identifier( self, x.partial_decl_string )
return declarations.templates.join( other, [ type_ ] ) + '()'