- Joined
- Dec 9, 2007
- Messages
- 3,096
JASS:
library Table2
globals
private constant integer MAX_INSTANCES=8100 //400000
private hashtable ht
private gamecache gc
endglobals
private keyword hack
private function SaveString takes hashtable table,integer parentKey,integer childKey,string value returns boolean
return SaveStr(table,parentKey,childKey,value)
endfunction // REMAKING TO FIT THE MACRO!
private function LoadString takes hashtable table,integer parentKey,integer childKey returns string
return LoadStr(table,parentKey,childKey)
endfunction // REMAKING TO FIT THE MACRO!
private struct CachedTable[MAX_INSTANCES]
readonly string sthis
static method create takes nothing returns CachedTable
local CachedTable this = CachedTable.allocate()
set this.sthis = SCOPE_PRIVATE + I2S(this)
return this
endmethod
method reset takes nothing returns nothing
call FlushStoredMission(gc, this.sthis )
endmethod
private method onDestroy takes nothing returns nothing
call FlushStoredMission(gc, this.sthis )
endmethod
static method hack takes string s returns nothing
set CachedTable(0).sthis = s
endmethod
private static method onInit takes nothing returns nothing
call FlushGameCache(InitGameCache("libtable.gc"))
set gc=InitGameCache("libtable.gc")
endmethod
endstruct
private struct GTable[MAX_INSTANCES]
method reset takes nothing returns nothing
call FlushChildHashtable(ht, integer(this) )
endmethod
private method onDestroy takes nothing returns nothing
call this.reset()
endmethod
private static method onInit takes nothing returns nothing
set ht = InitHashtable()
endmethod
endstruct
//! textmacro Table takes type, key, typetwo, keytwo
struct $type$_$typetwo$_Table extends GTable
method operator [] takes $type$ key returns $typetwo$
return Load$keytwo$(ht, integer(this), $key$)
endmethod
method operator []= takes $type$ key, $typetwo$ value returns nothing
call Save$keytwo$(ht, integer(this) ,$key$, value)
endmethod
method flush takes $type$ key returns nothing
call RemoveSaved$keytwo$(ht, integer(this), $key$)
endmethod
method exists takes $type$ key returns boolean
return HaveSaved$keytwo$( ht, integer(this) ,$key$)
endmethod
static method flush2D takes string firstkey returns nothing
call $type$_$typetwo$_Table(- StringHash(firstkey)).reset()
endmethod
static method operator [] takes string firstkey returns $type$_$typetwo$_Table
return $type$_$typetwo$_Table(- StringHash(firstkey) )
endmethod
endstruct
//! endtextmacro
//! textmacro CachedTable takes type, key, typetwo, keytwo
struct $type$_$typetwo$_CachedTable extends CachedTable
method operator [] takes $type$ key returns $typetwo$
return GetStored$keytwo$(gc, this.sthis ,$key$)
endmethod
method operator []= takes $type$ key, $typetwo$ value returns nothing
call Store$keytwo$(gc, this.sthis ,$key$, value)
endmethod
method flush takes $type$ key returns nothing
call FlushStored$keytwo$(gc, this.sthis ,$key$)
endmethod
method exists takes $type$ key returns boolean
return HaveStored$keytwo$(gc, this.sthis ,$key$)
endmethod
static method flush2D takes string firstkey returns nothing
call CachedTable.hack(firstkey)
call $type$_$typetwo$_CachedTable(0).reset()
endmethod
static method operator [] takes string firstkey returns $type$_$typetwo$_CachedTable
call CachedTable.hack(firstkey)
return $type$_$typetwo$_CachedTable(0)
endmethod
endstruct
//! endtextmacro
//! runtextmacro CachedTable("integer", "I2S(key)" , "integer", "Integer" )
//! runtextmacro CachedTable("real" , "R2S(key)" , "integer", "Integer" )
//! runtextmacro CachedTable("string" , "key" , "integer", "Integer" )
//! runtextmacro CachedTable("handle" , "I2S(GetHandleId(key))", "integer", "Integer" )
//! runtextmacro CachedTable("integer", "I2S(key)" , "real", "Real" )
//! runtextmacro CachedTable("real" , "R2S(key)" , "real", "Real" )
//! runtextmacro CachedTable("string" , "key" , "real", "Real" )
//! runtextmacro CachedTable("handle" , "I2S(GetHandleId(key))", "real", "Real" )
//! runtextmacro CachedTable("integer", "I2S(key)" , "string", "String" )
//! runtextmacro CachedTable("real" , "R2S(key)" , "string", "String" )
//! runtextmacro CachedTable("string" , "key" , "string", "String" )
//! runtextmacro CachedTable("handle" , "I2S(GetHandleId(key))", "string", "String" )
//! runtextmacro CachedTable("integer", "I2S(key)" , "boolean", "Boolean" )
//! runtextmacro CachedTable("real" , "R2S(key)" , "boolean", "Boolean" )
//! runtextmacro CachedTable("string" , "key" , "boolean", "Boolean" )
//! runtextmacro CachedTable("handle" , "I2S(GetHandleId(key))", "boolean", "Boolean" )
//! runtextmacro Table("integer", "key" , "integer", "Integer" )
//! runtextmacro Table("string" , "StringHash(key)" , "integer", "Integer" )
//! runtextmacro Table("handle" , "GetHandleId(key)", "integer", "Integer" )
//! runtextmacro Table("integer", "key" , "real", "Real" )
//! runtextmacro Table("string" , "StringHash(key)" , "real", "Real" )
//! runtextmacro Table("handle" , "GetHandleId(key)", "real", "Real" )
//! runtextmacro Table("integer", "key" , "string", "String" )
//! runtextmacro Table("string" , "StringHash(key)" , "string", "String" )
//! runtextmacro Table("handle" , "GetHandleId(key)", "string", "String" )
//! runtextmacro Table("integer", "key" , "boolean", "Boolean" )
//! runtextmacro Table("string" , "StringHash(key)" , "boolean", "Boolean" )
//! runtextmacro Table("handle" , "GetHandleId(key)", "boolean", "Boolean" )
endlibrary
Documentation...
Well, there's not much to say about it.
They're a better version of Vexorian's tables, that can store more types of variables like strings, reals and booleans.
Well, there's not much to say about it.
They're a better version of Vexorian's tables, that can store more types of variables like strings, reals and booleans.
- How do I initialize a table? There's no name!
My way to initialize tables is easy.
it takes the variables types and the type of table.
[label]_[value]_[tabletype]
- [label] can be either integer, string, handle or even real for cached tables.
- [value] can be either integer, string, boolean or real for all types
- [tabletype] can be either Table or CachedTable. Table is a hashtabled-table, which is faster than CachedTable, which uses a gamecache instead.
it takes the variables types and the type of table.
[label]_[value]_[tabletype]
- [label] can be either integer, string, handle or even real for cached tables.
- [value] can be either integer, string, boolean or real for all types
- [tabletype] can be either Table or CachedTable. Table is a hashtabled-table, which is faster than CachedTable, which uses a gamecache instead.
There's not much to say, I don't have a better documentation because it doesn't need.
It's too simple.
The reason why I define the custom functions is blizzard's fault! They have different function names for string on hashtables.
For all haters! | I copied only a part of Vexorian's work, and I don't want to take any credit for this submission. |
For all moderators! | Don't think about the author, think about the possibilities! These tables are supposed to make it easier for programmers to store the data! |