Package pyplusplus :: Package decl_wrappers :: Module enumeration_wrapper

# Source Code for Module pyplusplus.decl_wrappers.enumeration_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 class that configure enumeration declaration exposing"""
     7
     8  import decl_wrapper
     9  from pyplusplus import messages
    10  from pygccxml import declarations
    11
    12 -class enumeration_t(decl_wrapper.decl_wrapper_t, declarations.enumeration_t):
    13      """defines a set of properties, that will instruct Py++ how to expose the enumeration
    14
    15      By default, Py++ will export all enumeration values.
    16      """
    17 -    def __init__(self, *arguments, **keywords):
    18          declarations.enumeration_t.__init__(self, *arguments, **keywords )
    19          decl_wrapper.decl_wrapper_t.__init__( self )
    20
    21          # A dict with new names for particular enumeration values
    22          # Key: Original name as it appears in the C++ source file
    23          # Value: New name as it should appear in the Python bindings
    24          self._value_aliases = {}
    25
    26          # A list of enumeration names (C++ names, not aliases!) that should be
    27          # exported.
    28          # By default, export all values
    29          self._export_values = None
    30
    31 -    def _get_value_aliases(self):
    32          return self._value_aliases
    33 -    def _set_value_aliases(self, value_aliases):
    34          self._value_aliases = value_aliases
    35      value_aliases = property( _get_value_aliases, _set_value_aliases, doc=
    36                                """A translation table from C++ enumeration value names to desired Python names.
    37                                @type: dict""")
    38
    39 -    def _get_export_values(self):
    40          if self._export_values is None:
    41              return map(lambda x: x[0], self.values)
    42          else:
    43              return self._export_values
    44 -    def _set_export_values(self, export_values):
    45          self._export_values = export_values
    46      export_values = property( _get_export_values, _set_export_values, doc=
    47                                """A list of (C++) enumeration names that should be exported.
    48                                @type: list""")
    49
    50 -    def _get_no_export_values(self):
    51          all_values = map(lambda x: x[0], self.values)
    52          export_values = self.export_values
    53          res = []
    54          for name in all_values:
    55              if name not in export_values:
    56                  res.append(name)
    57          return res
    58
    59 -    def _set_no_export_values(self, no_export_values):
    60          all_values = map(lambda x: x[0], self.values)
    61          export_values = []
    62          for name in all_values:
    63              if name not in no_export_values:
    64                  export_values.append(name)
    65          self.export_values = export_values
    66
    67      no_export_values = property( _get_no_export_values, _set_export_values, doc=
    68                                """A list of (C++) enumeration names that should not be exported.
    69                                @type: list""")
    70
    71 -    def _readme_impl( self ):
    72          msgs = []
    73          if self.name:
    74              name2value = self.get_name2value_dict()
    75              if len( set( name2value.keys() ) ) != len( set( name2value.values() ) ):
    76                  msgs.append( messages.W1032 )
    77          return msgs
    78
    79 -    def _exportable_impl( self ):
    80          if not self.parent.name:
    81              return messages.W1057 % str( self )
    82          return ''
    83