Esempio n. 1
0
 def _get_exported_var_type(self):
     type_ = declarations.remove_reference(self.declaration.type)
     type_ = declarations.remove_const(type_)
     if python_traits.is_immutable(type_):
         return type_
     else:
         return self.declaration.type
Esempio n. 2
0
 def _get_exported_var_type( self ):
     type_ = declarations.remove_reference( self.declaration.type )
     type_ = declarations.remove_const( type_ )
     if python_traits.is_immutable( type_ ):
         return type_
     else:
         return self.declaration.type
Esempio n. 3
0
    def __call__(self, variable, hint=None):
        if not isinstance(variable, declarations.variable_t):
            return None

        assert hint in ('get', 'set')

        if not declarations.is_reference(variable.decl_type):
            return None

        no_ref = declarations.remove_reference(variable.decl_type)
        base_type = declarations.remove_const(no_ref)
        if python_traits.is_immutable(base_type):
            #the relevant code creator will generate code, that will return this member variable
            #by value
            return decl_wrappers.default_call_policies()

        if not isinstance(base_type, declarations.declarated_t):
            return None

        base_type = declarations.remove_alias(base_type)
        declaration = base_type.declaration

        if declarations.is_class_declaration(declaration):
            return None

        if declaration.is_abstract:
            return None
        if declarations.has_destructor(
                declaration
        ) and not declarations.has_public_destructor(declaration):
            return None
        if not declarations.has_copy_constructor(declaration):
            return None
        if hint == 'get':
            #if we rich this line, it means that we are able to create an obect using
            #copy constructor.
            if declarations.is_const(no_ref):
                return decl_wrappers.return_value_policy(
                    decl_wrappers.copy_const_reference)
            else:
                return decl_wrappers.return_value_policy(
                    decl_wrappers.copy_non_const_reference)
        else:
            return decl_wrappers.default_call_policies()
Esempio n. 4
0
    def __call__(self, calldef, hint=None):
        if not isinstance( calldef, declarations.calldef_t ):
            return None

        if not isinstance( calldef, declarations.member_operator_t ):
            return None
        
        if calldef.symbol != '[]':
            return None
            
        return_type = declarations.remove_cv( calldef.return_type )
        if declarations.is_reference( return_type ): 
            return_type = declarations.remove_reference( return_type )
        if python_traits.is_immutable( return_type ):
            if declarations.is_const( calldef.return_type ):
                return decl_wrappers.return_value_policy( decl_wrappers.copy_const_reference )
            else:
                return decl_wrappers.return_value_policy( decl_wrappers.copy_non_const_reference )
        else:
            return decl_wrappers.return_internal_reference()
    def __call__(self, calldef, hint=None):
        if not isinstance( calldef, declarations.calldef_t ):
            return None

        if not isinstance( calldef, declarations.member_operator_t ):
            return None
        
        if calldef.symbol != '[]':
            return None
            
        return_type = declarations.remove_cv( calldef.return_type )
        if declarations.is_reference( return_type ): 
            return_type = declarations.remove_reference( return_type )
        if python_traits.is_immutable( return_type ):
            if declarations.is_const( calldef.return_type ):
                return decl_wrappers.return_value_policy( decl_wrappers.copy_const_reference )
            else:
                return decl_wrappers.return_value_policy( decl_wrappers.copy_non_const_reference )
        else:
            return decl_wrappers.return_internal_reference()
Esempio n. 6
0
    def _get_has_setter( self ):
        if declarations.is_const( declarations.remove_reference( self.declaration.type ) ):
            return False
        elif python_traits.is_immutable( self._get_exported_var_type() ):
            return True
        else:
            pass

        no_ref = declarations.remove_reference( self.declaration.type )
        no_const = declarations.remove_const( no_ref )
        base_type = declarations.remove_alias( no_const )
        if not isinstance( base_type, declarations.declarated_t ):
            return True #TODO ????
        decl = base_type.declaration
        if decl.is_abstract:
            return False
        if declarations.has_destructor( decl ) and not declarations.has_public_destructor( decl ):
            return False
        if not declarations.has_copy_constructor(decl):
            return False
        return True
    def _get_has_setter( self ):
        if declarations.is_const( declarations.remove_reference( self.declaration.type ) ):
            return False
        elif python_traits.is_immutable( self._get_exported_var_type() ):
            return True
        else:
            pass

        no_ref = declarations.remove_reference( self.declaration.type )
        no_const = declarations.remove_const( no_ref )
        base_type = declarations.remove_alias( no_const )
        if not isinstance( base_type, declarations.declarated_t ):
            return True #TODO ????
        decl = base_type.declaration
        if decl.is_abstract:
            return False
        if declarations.has_destructor( decl ) and not declarations.has_public_destructor( decl ):
            return False
        if not declarations.has_copy_constructor(decl):
            return False
        return True
Esempio n. 8
0
    def __call__( self, variable, hint=None ):
        if not isinstance( variable, declarations.variable_t ):
            return None

        assert hint in ( 'get', 'set' )
        
        if not declarations.is_reference( variable.type ):
            return None
        
        no_ref = declarations.remove_reference( variable.type )
        base_type = declarations.remove_const( no_ref )
        if python_traits.is_immutable( base_type ):
            #the relevant code creator will generate code, that will return this member variable
            #by value
            return decl_wrappers.default_call_policies()
        
        if not isinstance( base_type, declarations.declarated_t ):
            return None
        
        base_type = declarations.remove_alias( base_type )
        decl = base_type.declaration
        
        if declarations.is_class_declaration( decl ):
            return None
        
        if decl.is_abstract:
            return None
        if declarations.has_destructor( decl ) and not declarations.has_public_destructor( decl ): 
            return None
        if not declarations.has_copy_constructor(decl):
            return None
        if hint == 'get':
            #if we rich this line, it means that we are able to create an obect using
            #copy constructor. 
            if declarations.is_const( no_ref ):
                return decl_wrappers.return_value_policy( decl_wrappers.copy_const_reference )
            else:
                return decl_wrappers.return_value_policy( decl_wrappers.copy_non_const_reference )
        else:
            return decl_wrappers.default_call_policies()
Esempio n. 9
0
 def _guess_call_policies(self):
     item_type = declarations.array_item_type( self.array_type )
     if python_traits.is_immutable( item_type ):
         return call_policies.default_call_policies()
     else:
         return call_policies.return_internal_reference()
 def _guess_call_policies(self):
     item_type = declarations.array_item_type( self.array_type )
     if python_traits.is_immutable( item_type ):
         return call_policies.default_call_policies()
     else:
         return call_policies.return_internal_reference()