pyplusplus.decl_wrappers.indexing_suite1

Package pyplusplus :: Package decl_wrappers :: Module indexing_suite1 |

# Source Code for Module pyplusplus.decl_wrappers.indexing_suite1

     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 interface for exposing STD containers, using current version of indexing suite"""
     7
     8  from pygccxml import declarations
     9  import python_traits
    10  #NoProxy
    11  #By default indexed elements have Python reference semantics and are returned by
    12  #proxy. This can be disabled by supplying true in the NoProxy template parameter.
    13  #We want to disable NoProxy when we deal with immutable objects.
    14
    15  containers = {
    16      'vector' : "boost/python/suite/indexing/vector_indexing_suite.hpp"
    17      , 'map' : "boost/python/suite/indexing/map_indexing_suite.hpp"
    18  }
    19
    20
    21 -class indexing_suite1_t( object ):
    22      """
    23      This class helps user to export STD containers, using built-in Boost.Python
    24      indexing suite.
    25      """
    26
    27 -    def __init__( self, container_class, no_proxy=None, derived_policies=None ):
    28          object.__init__( self )
    29          self.__no_proxy = no_proxy
    30          self.__derived_policies = derived_policies
    31          self.__container_class = container_class
    32          self.__include_files = None
    33          self.__element_type = None
    34
    35      @property
    36 -    def container_class( self ):
    37          """reference to the parent( STD container ) class"""
    38          return self.__container_class
    39
    40      @property
    41 -    def element_type(self):
    42          """reference to container value_type( mapped_type ) type"""
    43          if self.__element_type is None:
    44              self.__element_type = self.container_class.container_traits.element_type( self.container_class )
    45          return self.__element_type
    46
    47      @property
    48 -    def container_traits( self ):
    49          "reference to container traits. See pygccxml documentation for more information."
    50          return self.container_class.container_traits
    51
    52 -    def _get_no_proxy( self ):
    53          if self.__no_proxy is None:
    54              self.__no_proxy = python_traits.is_immutable( self.element_type )
    55          return self.__no_proxy
    56
    57 -    def _set_no_proxy( self, no_proxy ):
    58          self.__no_proxy = no_proxy
    59      no_proxy = property( _get_no_proxy, _set_no_proxy
    60                           , doc="NoProxy value, the initial value depends on container"
    61                                +" element_type( mapped_type ) type. In most cases, "
    62                                +"Py++ is able to guess this value, right. If you are not "
    63                                +"lucky, you will have to set the property value.")
    64
    65 -    def _get_derived_policies( self ):
    66          return self.__derived_policies
    67 -    def _set_derived_policies( self, derived_policies ):
    68          self.__derived_policies = derived_policies
    69      derived_policies = property( _get_derived_policies, _set_derived_policies
    70                                   , doc="This proprty contains DerivedPolicies string. "
    71                                        +"It will be added as is to the generated code.")
    72
    73      @property
    74 -    def include_files( self ):
    75          """Return list of header files to be included in generated code"""
    76          if self.__include_files is None:
    77              name = self.container_class.name.split( '<' )[0]
    78              if name not in containers:
    79                  self.__include_files = [] #not supported
    80              else:
    81                  self.__include_files = [containers[ name ]]
    82          return self.__include_files
    83