// What I'm doing here is storing both the attached and the attaching
// value into the hashtable.
globals
constant integer Attacher___MODE_KEY = 0
constant integer Attacher___MODE_VAL = 1
constant hashtable Table = InitHashtable()
endglobals
function Attacher___GetHandleKey takes handle typeval returns integer
return GetHandleId(typeval)
endfunction
function Attacher_GethandleKey takes handle typeval returns integer
return Attacher___GetHandleKey(typeval)
endfunction
function Savehandle takes hashtable table,integer mode,integer key,handle typeval returns integer
if mode == Attacher___MODE_KEY then
set key = Attacher_GetHandleId(typeval)
endif
call SaveHandle(table , key , mode , typeval)
return key
endfunction
function Loadhandle takes hashtable table,integer mode,integer key returns handle
return LoadHandle(table , key , mode)
endfunction
function Havehandle takes hashtable table,integer key returns boolean
return ( HaveSavedHandle(table , key , Attacher___MODE_KEY) and HaveSavedHandle(table , key , Attacher___MODE_VAL) )
endfunction
function SetHandleHandle takes handle key_handle, handle val returns nothing
local integer key = Savehandle( Table, MODE_KEY, 0, key_handle )
call Savehandle( Table, MODE_VAL, key, val )
endfunction
function GetHandleHandle takes handle key_handle returns handle
local integer key = Attacher_GethandleKey( key_handle )
local handle loaded = Loadhandle( Table, MODE_KEY, key )
if key_handle == loaded then
return Loadhandle( Table, MODE_VAL, key )
endif
return null
endfunction