pyplusplus.code_creators.exception_translator

Package pyplusplus :: Package code_creators :: Module exception_translator |

# Source Code for Module pyplusplus.code_creators.exception_translator

     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  import os
     7  import types
     8  import algorithm
     9  import code_creator
    10  import declaration_based
    11  import registration_based
    12  from pygccxml import declarations
    13
    14 -class exception_translator_t( code_creator.code_creator_t
    15                                , declaration_based.declaration_based_t ):
    16 -    def __init__(self, exception_class ):
    17          code_creator.code_creator_t.__init__( self )
    18          declaration_based.declaration_based_t.__init__( self, declaration=exception_class  )
    19
    20      @property
    21 -    def translator_name( self ):
    22          return 'translate_%(alias)s' % { 'alias' : self.declaration.alias }
    23
    24 -    def _create_impl(self):
    25          if self.declaration.already_exposed:
    26              return ''
    27          return os.linesep.join([
    28                "void translate_%(alias)s( const %(cls_name)s& %(arg_name)s ){" \
    29              , self.indent( self.declaration.exception_translation_code )
    30              , "}"]) \
    31              % { 'alias' : self.declaration.alias
    32                   , 'cls_name' : self.decl_identifier
    33                   , 'arg_name' : self.declaration.exception_argument_name }
    34
    35 -    def _get_system_headers_impl( self ):
    36          return []
    37
    38
    39 -class exception_translator_register_t( registration_based.registration_based_t
    40                                         , declaration_based.declaration_based_t ):
    41 -    def __init__(self, exception_class, exception_translator):
    42          registration_based.registration_based_t.__init__( self )
    43          declaration_based.declaration_based_t.__init__( self, declaration=exception_class )
    44          self.works_on_instance = False
    45          self.translator = exception_translator
    46
    47 -    def _create_impl( self ):
    48          if self.declaration.already_exposed:
    49              return ''
    50
    51          return '%(register_exception_translator)s< %(cls)s >( &%(translator)s );' \
    52                 % { 'register_exception_translator' : algorithm.create_identifier( self, 'boost::python::register_exception_translator' )
    53                     , 'cls'  : self.decl_identifier
    54                     , 'translator' : self.translator.translator_name }
    55
    56 -    def _get_system_headers_impl( self ):
    57          return []
    58