Package pyplusplus :: Package code_creators :: Module array_1_registrator |

# Source Code for Module pyplusplus.code_creators.array_1_registrator

     1  # Copyright 2004-2008 Roman Yakovenko.
     2  # Distributed under the Boost Software License, Version 1.0. (See
     3  # accompanying file LICENSE_1_0.txt or copy at
     4  # http://www.boost.org/LICENSE_1_0.txt)
     5
     6
     7  import os
     8  import algorithm
     9  import registration_based
    10  from pyplusplus import code_repository
    11  from pyplusplus.decl_wrappers import call_policies
    12  from pyplusplus.decl_wrappers import python_traits
    13  from pygccxml import declarations
    14
    15 -class array_1_registrator_t( registration_based.registration_based_t ):
    16      """
    17      This class creates code that register static sized array
    18      """
    19 -    def __init__( self, array_type ):
    20          registration_based.registration_based_t.__init__( self )
    21          self._array_type = array_type
    22          self._call_policies = self._guess_call_policies()
    23          self.works_on_instance = False
    24
    25 -    def _get_array_type( self ):
    26          return self._array_type
    27 -    def _set_array_type( self, new_array_type ):
    28          self._array_type = new_array_type
    29      array_type = property( _get_array_type, _set_array_type )
    30
    31 -    def _get_call_policies( self ):
    32          return self._call_policies
    33 -    def _set_call_policies( self, new_call_policies ):
    34          self._call_policies = new_call_policies
    35      call_policies = property( _get_call_policies, _set_call_policies )
    36
    37 -    def _create_name( self ):
    38          item_type = declarations.array_item_type(self.array_type)
    39          return "__array_1_%(type)s_%(size)d" \
    40                 % dict( type=algorithm.create_valid_name( item_type.decl_string )
    41                         , size=declarations.array_size(self.array_type) )
    42
    43 -    def _guess_call_policies(self):
    44          item_type = declarations.array_item_type( self.array_type )
    45          if python_traits.is_immutable( item_type ):
    46              return call_policies.default_call_policies()
    47          else:
    48              return call_policies.return_internal_reference()
    49
    50 -    def _create_impl(self):
    51          templates = declarations.templates
    52          call_invocation = declarations.call_invocation
    53          ns_name = code_repository.array_1.namespace
    54          if declarations.is_const( self.array_type ):
    55              fn_name = 'register_const_array_1'
    56          else:
    57              fn_name = 'register_array_1'
    58
    59          fn_def_tmpl_args = [ declarations.array_item_type(self.array_type).decl_string
    60                               , str( declarations.array_size(self.array_type) ) ]
    61          if not self.call_policies.is_default():
    62              fn_def_tmpl_args.append(
    63                  self.call_policies.create(self, call_policies.CREATION_POLICY.AS_TEMPLATE_ARGUMENT ) )
    64
    65          fn_def = templates.join( '::'.join( [ns_name, fn_name] ), fn_def_tmpl_args )
    66          return call_invocation.join( fn_def, [ '"%s"' % self._create_name() ] ) + ';'
    67
    68 -    def _get_system_headers_impl( self ):
    69          return [code_repository.array_1.file_name]
    70