Package pyplusplus :: Package code_creators :: Module compound |

# Source Code for Module pyplusplus.code_creators.compound

     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 code_creator
     8
     9 -class compound_t(code_creator.code_creator_t):
    10 -    def __init__(self ):
    11          """Constructor.
    12
    13          @param parent: Parent code creator.
    14          @type parent: L{code_creator_t}
    15          """
    16          code_creator.code_creator_t.__init__( self )
    17          self._creators = []
    18
    19 -    def _get_creators(self):
    20          return self._creators
    21      creators = property(_get_creators,
    22                          doc="""A list of children nodes.
    23                          @type: list of L{code_creator_t}""")
    24
    25 -    def adopt_creator( self, creator, index=None):
    26          """Add a creator to the list of children creators.
    27
    28          @param creator: Creator object
    29          @type creator: L{code_creator_t}
    30          @param index: Desired position of the creator or None to append it to the end of the list
    31          @type index: int
    32          """
    33          creator.parent = self
    34          if index or index == 0:
    35              self._creators.insert( index, creator )
    36          else:
    37              self._creators.append( creator )
    38
    39 -    def adopt_creators( self, creators, index=None):
    40          """Add a creators to the list of children creators.
    41
    42          @param creators: list of creators object
    43          @type creator: L{code_creator_t}
    44          @param index: Desired position of the creator or None to append it to the end of the list
    45          @type index: int
    46          """
    47          for pos, creator in enumerate( creators ):
    48              if index or index == 0:
    49                  self.adopt_creator( creator, index + pos )
    50              else:
    51                  self.adopt_creator( creator )
    52
    53 -    def remove_creator( self, creator ):
    54          """Remove a children code creator object.
    55
    56          @precondition: creator must be a children of self
    57          @param creator: The creator node to remove
    58          @type creator: L{code_creator_t}
    59          """
    60          creator.parent = None
    61          del self._creators[ self._creators.index( creator ) ]
    62
    63      @staticmethod
    64 -    def create_internal_code( creators ):
    65          """Concatenate the code from a list of code creators.
    66
    67          @param creators: A list with code creators
    68          @type creators: list of L{code_creator_t}
    69          @rtype: str
    70          """
    71          internals = map( lambda expr: expr.create(), creators )
    72          internals = filter(None, internals )
    73          internals = map( lambda code: code_creator.code_creator_t.indent( code )
    74                           , internals )
    75          for index in range( len( internals ) - 1):
    76              internals[index] = internals[index] + os.linesep
    77          return os.linesep.join( internals )
    78
    79 -    def get_system_headers( self, recursive=False, unique=False ):
    80          files = [ "boost/python.hpp" ]
    81          files.extend( self._get_system_headers_impl() )
    82          if recursive:
    83              for creator in self._creators:
    84                  files.extend( creator.get_system_headers(recursive, unique=False) )
    85          files = filter( None, files )
    86          if unique:
    87              files = self.unique_headers( files )
    88          return files
    89