Example #1
0
 def ApplyCommonRules(self, mb):
     # Common function added for getting the "PyObject" of an entity
     mb.member_functions('GetPySelf').exclude()
     
     ihandleentity = mb.class_('IHandleEntity')
     
     # All return values derived from IHandleEntity entity will be returned by value.
     # This ensures the converter is called
     testinherit = MatcherTestInheritClass(ihandleentity)
     decls = mb.calldefs(matchers.custom_matcher_t(testinherit))
     decls.call_policies = call_policies.return_value_policy(call_policies.return_by_value)
     
     # All CBaseEntity related classes should have a custom call trait
     self.baseentcls = mb.class_('CBaseEntity' if self.isserver else 'C_BaseEntity')
     def ent_call_trait(type_):
         return '%(arg)s ? %(arg)s->GetPyHandle() : boost::python::object()'
     entclasses = mb.classes(self.TestCBaseEntity)
     for entcls in entclasses:
         entcls.custom_call_trait = ent_call_trait
         
     # All functions receiving an IHandleEntity argument should be converted
     def ihandleentity_call_trait(type_):
         return 'PyEntityFromEntityHandle( %(arg)s )'
     ihandleentity.custom_call_trait = ihandleentity_call_trait
     
     # Anything returning KeyValues should be returned by value so it calls the converter
     keyvalues = mb.class_('KeyValues')
     mb.calldefs(calldef_matcher_t(return_type=pointer_t(declarated_t(keyvalues))), allow_empty=True).call_policies = call_policies.return_value_policy(call_policies.return_by_value) 
     mb.calldefs(calldef_matcher_t(return_type=pointer_t(const_t(declarated_t(keyvalues)))), allow_empty=True).call_policies = call_policies.return_value_policy(call_policies.return_by_value) 
     
     # Anything returning a void pointer is excluded by default
     mb.calldefs(calldef_matcher_t(return_type=pointer_t(declarated_t(void_t()))), allow_empty=True).exclude()
     mb.calldefs(calldef_matcher_t(return_type=pointer_t(const_t(declarated_t(void_t())))), allow_empty=True).exclude()
Example #2
0
    def __call__( self, calldef, hint=None ):
        if not isinstance( calldef, declarations.calldef_t ):
            return None

        if isinstance( calldef, declarations.constructor_t ):
            return None
        return_type = declarations.remove_alias( calldef.return_type )
        void_ptr = declarations.pointer_t( declarations.void_t() )
        const_void_ptr = declarations.pointer_t( declarations.const_t( declarations.void_t() ) )
        if declarations.is_same( return_type, void_ptr ) \
           or declarations.is_same( return_type, const_void_ptr ):
            return decl_wrappers.return_value_policy( decl_wrappers.return_opaque_pointer )
        return None
    def __call__( self, calldef, hint=None ):
        if not isinstance( calldef, declarations.calldef_t ):
            return None

        if isinstance( calldef, declarations.constructor_t ):
            return None
        return_type = declarations.remove_alias( calldef.return_type )
        void_ptr = declarations.pointer_t( declarations.void_t() )
        const_void_ptr = declarations.pointer_t( declarations.const_t( declarations.void_t() ) )
        if declarations.is_same( return_type, void_ptr ) \
           or declarations.is_same( return_type, const_void_ptr ):
            return decl_wrappers.return_value_policy( decl_wrappers.return_opaque_pointer )
        return None
Example #4
0
    def ApplyCommonRules(self, mb):
        # Common function added for getting the "PyObject" of an entity
        mb.mem_funs('GetPySelf').exclude()

        ihandleentity = mb.class_('IHandleEntity')

        # All return values derived from IHandleEntity entity will be returned by value.
        # This ensures the converter is called
        testinherit = MatcherTestInheritClass(ihandleentity)
        decls = mb.calldefs(matchers.custom_matcher_t(testinherit))
        decls.call_policies = call_policies.return_value_policy(
            call_policies.return_by_value)

        # All CBaseEntity related classes should have a custom call trait
        self.baseentcls = mb.class_(
            'CBaseEntity' if self.isserver else 'C_BaseEntity')

        def ent_call_trait(type_):
            return '%(arg)s ? %(arg)s->GetPyHandle() : boost::python::object()'

        entclasses = mb.classes(self.TestCBaseEntity)
        for entcls in entclasses:
            entcls.custom_call_trait = ent_call_trait

        # All functions receiving an IHandleEntity argument should be converted
        def ihandleentity_call_trait(type_):
            return 'PyEntityFromEntityHandle( %(arg)s )'

        ihandleentity.custom_call_trait = ihandleentity_call_trait

        # Anything returning KeyValues should be returned by value so it calls the converter
        keyvalues = mb.class_('KeyValues')
        mb.calldefs(matchers.calldef_matcher_t(
            return_type=pointer_t(declarated_t(keyvalues))),
                    allow_empty=True
                    ).call_policies = call_policies.return_value_policy(
                        call_policies.return_by_value)
        mb.calldefs(matchers.calldef_matcher_t(
            return_type=pointer_t(const_t(declarated_t(keyvalues)))),
                    allow_empty=True
                    ).call_policies = call_policies.return_value_policy(
                        call_policies.return_by_value)

        # Anything returning a void pointer is excluded by default
        mb.calldefs(matchers.calldef_matcher_t(
            return_type=pointer_t(declarated_t(void_t()))),
                    allow_empty=True).exclude()
        mb.calldefs(matchers.calldef_matcher_t(
            return_type=pointer_t(const_t(declarated_t(void_t())))),
                    allow_empty=True).exclude()
Example #5
0
 def _get_setter_type(self):
     return declarations.free_function_type_t(
         return_type=declarations.void_t(),
         arguments_types=[
             declarations.reference_t(self._get_class_inst_type()),
             self._get_exported_var_type()
         ])
Example #6
0
 def _get_setter_type(self):
     return declarations.member_function_type_t.create_decl_string(
             return_type=declarations.void_t()
             , class_decl_string=self.parent.full_name
             , arguments_types=[self.declaration.type]
             , has_const=False
             , with_defaults=False)
Example #7
0
 def _get_setter_type(self):
     return declarations.member_function_type_t.create_decl_string(
             return_type=declarations.void_t()
             , class_decl_string=self.parent.full_name
             , arguments_types=[self.declaration.type]
             , has_const=False
             , with_defaults=False)
Example #8
0
 def _get_setter_type(self):
     return declarations.free_function_type_t.create_decl_string(
         return_type=declarations.void_t(),
         arguments_types=[
             self.inst_arg_type(False), self.declaration.decl_type
         ],
         with_defaults=False)
Example #9
0
    def _get_setter_type(self):
        if self.declaration.type_qualifiers.has_static:
            arguments_types=[ self.declaration.type ]
        else:
            arguments_types=[ self.inst_arg_type(False), self.declaration.type  ]

        return declarations.free_function_type_t.create_decl_string(
                return_type=declarations.void_t()
                , arguments_types=arguments_types
                , with_defaults=False)
Example #10
0
    def _get_setter_type(self):
        if self.declaration.type_qualifiers.has_static:
            arguments_types = [self.declaration.decl_type]
        else:
            arguments_types = [
                self._get_class_inst_type(False), self.declaration.decl_type
            ]

        return declarations.free_function_type_t(
            return_type=declarations.void_t(), arguments_types=arguments_types)
    def _get_setter_type(self):
        if self.declaration.type_qualifiers.has_static:
            arguments_types=[ self.declaration.type ]
        else:
            arguments_types=[ self.inst_arg_type(False), self.declaration.type  ]

        return declarations.free_function_type_t.create_decl_string(
                return_type=declarations.void_t()
                , arguments_types=arguments_types
                , with_defaults=False)
 def visit_reference( self ):
     no_ref = declarations.remove_const( declarations.remove_reference( self.user_type ) )
     if declarations.is_same( declarations.char_t(), no_ref ):
         return "ctypes.c_char_p"
     elif declarations.is_same( declarations.wchar_t(), no_ref ):
         return "ctypes.c_wchar_p"
     elif declarations.is_same( declarations.void_t(), no_ref ):
         return "ctypes.c_void_p"
     else:
         base_visitor = self.create_converter( self.user_type.base )
         internal_type_str = declarations.apply_visitor( base_visitor, base_visitor.user_type )
         return "ctypes.POINTER( %s )" % internal_type_str
Example #13
0
 def visit_reference(self):
     no_ref = declarations.remove_const(
         declarations.remove_reference(self.user_type))
     if declarations.is_same(declarations.char_t(), no_ref):
         return "ctypes.c_char_p"
     elif declarations.is_same(declarations.wchar_t(), no_ref):
         return "ctypes.c_wchar_p"
     elif declarations.is_same(declarations.void_t(), no_ref):
         return "ctypes.c_void_p"
     else:
         base_visitor = self.create_converter(self.user_type.base)
         internal_type_str = declarations.apply_visitor(
             base_visitor, base_visitor.user_type)
         return "ctypes.POINTER( %s )" % internal_type_str
 def visit_pointer( self ):
     no_ptr = declarations.remove_const( declarations.remove_pointer( self.user_type ) )
     if declarations.is_same( declarations.char_t(), no_ptr ) and self.treat_char_ptr_as_binary_data == False:
         return "ctypes.c_char_p"
     elif declarations.is_same( declarations.wchar_t(), no_ptr ) and self.treat_char_ptr_as_binary_data == False:
         return "ctypes.c_wchar_p"
     elif declarations.is_same( declarations.void_t(), no_ptr ):
         return "ctypes.c_void_p"
     else:
         base_visitor = self.create_converter( self.user_type.base )
         internal_type_str = declarations.apply_visitor( base_visitor, base_visitor.user_type )
         if declarations.is_calldef_pointer( self.user_type ):
             return internal_type_str
         else:
             return "ctypes.POINTER( %s )" % internal_type_str
Example #15
0
 def visit_pointer(self):
     no_ptr = declarations.remove_const(
         declarations.remove_pointer(self.user_type))
     if declarations.is_same(
             declarations.char_t(),
             no_ptr) and self.treat_char_ptr_as_binary_data == False:
         return "ctypes.c_char_p"
     elif declarations.is_same(
             declarations.wchar_t(),
             no_ptr) and self.treat_char_ptr_as_binary_data == False:
         return "ctypes.c_wchar_p"
     elif declarations.is_same(declarations.void_t(), no_ptr):
         return "ctypes.c_void_p"
     else:
         base_visitor = self.create_converter(self.user_type.base)
         internal_type_str = declarations.apply_visitor(
             base_visitor, base_visitor.user_type)
         if declarations.is_calldef_pointer(self.user_type):
             return internal_type_str
         else:
             return "ctypes.POINTER( %s )" % internal_type_str
Example #16
0
 def _get_setter_type(self):
     return declarations.free_function_type_t(
             return_type=declarations.void_t()
             , arguments_types=[ declarations.reference_t( self._get_class_inst_type() )
                                 , self._get_exported_var_type() ] )
Example #17
0
 def _get_setter_type(self):
     return declarations.free_function_type_t.create_decl_string(
             return_type=declarations.void_t()
             , arguments_types=[ self.inst_arg_type(False), self.declaration.type  ]
             , with_defaults=False)