wraithseeker
Tired.
- Reaction score
- 122
JASS:
//* Table library by Vexorian
library Table initializer init
//***************************************************************
//* Table object
//* ------------
//*
//* set t=Table.create() - instanceates a new table object
//* call t.destroy() - destroys it
//* t[1234567] - Get value for key 1234567
//* (zero if not assigned previously)
//* set t[12341]=32 - Assigning it.
//* call t.flush(12341) - Flushes the stored value, so it
//* doesn't use any more memory
//* t.exists(32) - Was key 32 assigned? Notice
//* that flush() unassigns values.
//* call t.reset() - Flushes the whole contents of the
//* Table.
//*
//* call t.destroy() - Does reset() and also recycles the id.
//*
//* If you use HandleTable instead of Table, it is the same
//* but it uses handles as keys, the same with StringTable.
//*
//***************************************************************
//=============================================================
globals
private constant integer MAX_INSTANCES=8100 //400000
//=========================================================
private gamecache gc
endglobals
private struct GTable[MAX_INSTANCES]
method reset takes nothing returns nothing
call FlushStoredMission(gc,I2S(this))
endmethod
private method onDestroy takes nothing returns nothing
call FlushStoredMission(gc,I2S(this))
endmethod
endstruct
//Hey: Don't instanciate other people's textmacros that you are not supposed to, thanks.
//! textmacro Table__make takes name, type, key
struct $name$ extends GTable
method operator [] takes $type$ key returns integer
return GetStoredInteger(gc,I2S(this),$key$)
endmethod
method operator []= takes $type$ key, integer value returns nothing
call StoreInteger(gc,I2S(this),$key$, value)
endmethod
method flush takes $type$ key returns nothing
call FlushStoredInteger(gc,I2S(this),$key$)
endmethod
method exists takes $type$ key returns boolean
return HaveStoredInteger(gc,I2S(this),$key$)
endmethod
endstruct
//! endtextmacro
private function H2I takes handle h returns integer
return h
return 0
endfunction
//! runtextmacro Table__make("Table","integer","I2S(key)" )
//! runtextmacro Table__make("StringTable","string","key" )
//! runtextmacro Table__make("HandleTable","handle","I2S(H2I(key))" )
//=============================================================
// initialize it all.
//
private function init takes nothing returns nothing
call FlushGameCache(InitGameCache("libtable.gc"))
set gc=InitGameCache("libtable.gc")
endfunction
endlibrary
Here is table and it works cool as it is so I don't get why you want to modify it at all.