fb:porticula NoPaste
secure_callback.bi
Uploader: | The_Muh |
Datum/Zeit: | 15.10.2009 18:26:59 |
Declare Sub zero_pointer()
Sub zero_pointer()
? "ERROR! ZERO-Pointer detected"
End Sub
type _callback_type as callback_type
Type secure_call
Private:
callback_count as integer
callback As _callback_type ptr
Public:
Declare Property call_sub () As _callback_type Ptr
Declare Property set_sub (subname as integer, Byval target As Any Ptr)
declare constructor (sub_count as integer)
declare destructor ()
End Type
constructor secure_call(sub_count as integer)
this.callback_count = sub_count
this.callback = callocate(this.callback_count, sizeof(sub))
for i as integer = 0 to this.callback_count -1
cast(integer ptr, @this.callback)[i] = 0
next
end constructor
destructor secure_call()
this.callback_count = 0
deallocate this.callback
end destructor
Property secure_call.call_sub() As _callback_type Ptr
for i as integer = 0 to this.callback_count -1
if cast(integer ptr, @this.callback)[i] = 0 then
cast(sub ptr, @this.callback)[i] = @zero_pointer
end if
next
Return Cast(Any Ptr, @This.callback)
End Property
Property secure_call.set_sub(subname as integer, Byval target As Any Ptr)
if this.callback_count < subname then
dim old_count as integer = this.callback_count
this.callback_count = subname +1
this.callback = reallocate(this.callback, sizeof(sub)* (this.callback_count))
for i as integer = old_count +1 to subname
cast(sub ptr, @this.callback)[i] = @zero_pointer
next
end if
cast(sub ptr, @this.callback)[subname] = Cast(Any Ptr, target)
End Property