Package pyplusplus :: Package decl_wrappers :: Module decl_wrapper

Source Code for Module pyplusplus.decl_wrappers.decl_wrapper

  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  """defines base class for all code generator configuration classes""" 
  7  
 
  8  import algorithm 
  9  from pyplusplus import _logging_ 
 10  from pygccxml import declarations 
 11  from pyplusplus import messages 
12 13 -class decl_wrapper_t(object):
14 """code generator declaration configuration base class 15 16 This class contains configuration that could be applied to all declarations. 17 """ 18 19 SPECIAL_TYPEDEF_PICK_ANY = True 20
21 - def __init__(self):
22 object.__init__(self) 23 self._alias = None 24 self._ignore = False 25 self._already_exposed = False 26 self._exportable = None 27 self._exportable_reason = None 28 self._documentation = None 29 self.__msgs_to_ignore = set() 30 self._include_files = []
31 32 @property
33 - def logger( self ):
34 """reference to L{_logging_.loggers.declarations}""" 35 return _logging_.loggers.declarations
36
37 - def _get_documentation( self ):
38 return self._documentation
39 - def _set_documentation( self, value ):
40 self._documentation = value
41 documentation = property( _get_documentation, _set_documentation 42 , doc="exposed declaration Python documentation string" ) 43
44 - def _generate_valid_name(self, name=None):
45 if name == None: 46 name = self.name 47 return algorithm.create_valid_name( name )
48
49 - def __select_alias_directives( self, be_smart ):
50 if not isinstance( self, declarations.class_types ): 51 return [] 52 typedefs = list( set( filter( lambda typedef: typedef.is_directive, self.aliases ) ) ) 53 if decl_wrapper_t.SPECIAL_TYPEDEF_PICK_ANY: 54 if typedefs and be_smart: 55 longest_name_len = 0 56 longest_typedef = None 57 for typedef in typedefs: 58 typedef_name_len = len( typedef.name ) 59 if longest_name_len < typedef_name_len: 60 longest_name_len = typedef_name_len 61 longest_typedef = typedef 62 return [longest_typedef] 63 else: 64 return typedefs 65 else: 66 return typedefs
67
68 - def _get_alias(self):
69 if not self._alias: 70 directives = self.__select_alias_directives(be_smart=True) 71 if 1 == len( directives ): 72 self._alias = directives[0].name 73 else: 74 if declarations.templates.is_instantiation( self.name ): 75 container_aliases = [ 'value_type', 'key_type', 'mapped_type' ] 76 if isinstance( self, declarations.class_t ) \ 77 and 1 == len( set( map( lambda typedef: typedef.name, self.aliases ) ) ) \ 78 and self.aliases[0].name not in container_aliases: 79 self._alias = self.aliases[0].name 80 else: 81 self._alias = algorithm.create_valid_name( self.partial_name ) 82 else: 83 if declarations.is_class( self ) or declarations.is_class_declaration( self ): 84 self._alias = algorithm.create_valid_name( self.partial_name ) 85 else: 86 self._alias = self.partial_name 87 return self._alias
88 - def _set_alias(self, alias):
89 self._alias = alias
90 alias = property( _get_alias, _set_alias 91 , doc="the name under which, Python will know the declaration" ) 92
93 - def rename( self, new_name ):
94 """give new name to the declaration, under which Python will know the declaration""" 95 self.alias = new_name
96
97 - def _get_ignore( self ):
98 return self._ignore
99 - def _set_ignore( self, value ):
100 self._ignore = value
101 ignore = property( _get_ignore, _set_ignore 102 , doc="boolean flag, which says whether to export declaration to Python or not" ) 103
104 - def get_already_exposed( self ):
105 return self._already_exposed
106 - def set_already_exposed( self, value ):