- Joined
- Dec 9, 2007
- Messages
- 3,096
JASS:
/*********************************************************************************\
|* HyperTable *|
|* a library by vercas *|
|* *|
|* Credit me (vercas) if you use this library in any of your projects.*|
|*********************************************************************************|
|* How to use: *|
|* create a new HyperTable by the following way: *|
|* [argument type 1]_[argument type 2]_[argument type to store]_HyperTable *|
|*********************************************************************************|
|* So far, I've made *|
|* [integer/string/handle][integer/string/handle][integer/string/real/boolean] *|
|* HyperTables *|
|* So, in the 2D array you may have either integer, string or boolean *|
|* And you may save/load integers, reals, strings or booleans *|
|* Look at the footer of the library for the text macros; you may *|
|* understand the way it works better *|
|* The way this works is pretty easy: you give it an argument, it gives *|
|* you a helper; you give the helper an arguments or two, it loads *|
|* or saves the data for you! *|
|* The helper destroys itself, so you don't have to worry about that! *|
|* The variables are nulled, so they won't take extra memory! *|
|*********************************************************************************|
|* My way of doing this isn't the most performance-wise, but, at least, it *|
|* works as it is supposed to! *|
|*********************************************************************************|
|* So, the syntax is like a 2D array: *|
|* yourtable[one][two] ... *|
|* "one" and "two" are the two arguments passed to the hashtables *|
|* "yourtable" is, of course, the name of your HyperTable variable! *|
|* to get a value *|
|* yourtable[one][two] = value *|
|* "value" here is the value you set in the array... *|
|* *|
|* The purpose of this library is to make 2D arrays able to store more *|
|* than 8192 values. *|
|* These HyperTables may store up to 4294967295^2 values per table! *|
|* This means 18446744065119617025 values! *|
|* Who needs so many, anyway??!! *|
\*********************************************************************************/
library HyperTable/**************************************************************/
globals
private constant integer MAX_INSTANCES = 255
/* The maximum number of HyperTables you may have...*\
\* Who on earth needs so many ??!! */
endglobals
//! textmacro HyperTable takes one, two, ret, Load, Save
private struct $one$_$two$_$ret$_Table_helper
hashtable h
$one$ i
method operator [] takes $two$ i returns $ret$
local $one$ s = this.i
local hashtable h = this.h
call this.destroy()
return $Load$
endmethod
method operator []= takes $two$ i, $ret$ u returns nothing
call $Save$
call this.destroy()
endmethod
static method create takes hashtable h, $one$ i returns thistype
local thistype this = thistype.allocate()
set this.i = i
set this.h = h
return this
endmethod
private method OnDestroy takes nothing returns nothing
set this.h = null
endmethod
endstruct
struct $one$_$two$_$ret$_Table[MAX_INSTANCES]
hashtable h = InitHashtable()
method operator [] takes $one$ i returns $one$_$two$_$ret$_Table_helper
return $one$_$two$_$ret$_Table_helper.create(this.h, i)
endmethod
private method OnDestroy takes nothing returns nothing
set this.h = null
endmethod
endstruct
//! endtextmacro
//! runtextmacro HyperTable("integer","integer","integer","LoadInteger(h,s ,i )","SaveInteger(this.h,this.i ,i ,u)")
//! runtextmacro HyperTable("integer","integer","string" ,"LoadStr( h,s ,i )","SaveStr( this.h,this.i ,i ,u)")
//! runtextmacro HyperTable("integer","integer","real" ,"LoadReal( h,s ,i )","SaveReal( this.h,this.i ,i ,u)")
//! runtextmacro HyperTable("integer","integer","boolean","LoadBoolean(h,s ,i )","SaveBoolean(this.h,this.i ,i ,u)")
//! runtextmacro HyperTable("string" ,"integer","integer","LoadInteger(h,StringHash(s) ,i )","SaveInteger(this.h,StringHash(this.i) ,i ,u)")
//! runtextmacro HyperTable("string" ,"integer","string" ,"LoadStr( h,StringHash(s) ,i )","SaveStr( this.h,StringHash(this.i) ,i ,u)")
//! runtextmacro HyperTable("string" ,"integer","real" ,"LoadReal( h,StringHash(s) ,i )","SaveReal( this.h,StringHash(this.i) ,i ,u)")
//! runtextmacro HyperTable("string" ,"integer","boolean","LoadBoolean(h,StringHash(s) ,i )","SaveBoolean(this.h,StringHash(this.i) ,i ,u)")
//! runtextmacro HyperTable("handle" ,"integer","integer","LoadInteger(h,GetHandleId(s),i )","SaveInteger(this.h,GetHandleId(this.i),i ,u)")
//! runtextmacro HyperTable("handle" ,"integer","string" ,"LoadStr( h,GetHandleId(s),i )","SaveStr( this.h,GetHandleId(this.i),i ,u)")
//! runtextmacro HyperTable("handle" ,"integer","real" ,"LoadReal( h,GetHandleId(s),i )","SaveReal( this.h,GetHandleId(this.i),i ,u)")
//! runtextmacro HyperTable("handle" ,"integer","boolean","LoadBoolean(h,GetHandleId(s),i )","SaveBoolean(this.h,GetHandleId(this.i),i ,u)")
//! runtextmacro HyperTable("integer","string","integer","LoadInteger( h,s ,StringHash(i) )","SaveInteger(this.h,this.i ,StringHash(i) ,u)")
//! runtextmacro HyperTable("integer","string","string" ,"LoadStr( h,s ,StringHash(i) )","SaveStr( this.h,this.i ,StringHash(i) ,u)")
//! runtextmacro HyperTable("integer","string","real" ,"LoadReal( h,s ,StringHash(i) )","SaveReal( this.h,this.i ,StringHash(i) ,u)")
//! runtextmacro HyperTable("integer","string","boolean","LoadBoolean( h,s ,StringHash(i) )","SaveBoolean(this.h,this.i ,StringHash(i) ,u)")
//! runtextmacro HyperTable("string" ,"string","integer","LoadInteger( h,StringHash(s) ,StringHash(i) )","SaveInteger(this.h,StringHash(this.i) ,StringHash(i) ,u)")
//! runtextmacro HyperTable("string" ,"string","string" ,"LoadStr( h,StringHash(s) ,StringHash(i) )","SaveStr( this.h,StringHash(this.i) ,StringHash(i) ,u)")
//! runtextmacro HyperTable("string" ,"string","real" ,"LoadReal( h,StringHash(s) ,StringHash(i) )","SaveReal( this.h,StringHash(this.i) ,StringHash(i) ,u)")
//! runtextmacro HyperTable("string" ,"string","boolean","LoadBoolean( h,StringHash(s) ,StringHash(i) )","SaveBoolean(this.h,StringHash(this.i) ,StringHash(i) ,u)")
//! runtextmacro HyperTable("handle" ,"string","integer","LoadInteger( h,GetHandleId(s),StringHash(i) )","SaveInteger(this.h,GetHandleId(this.i),StringHash(i) ,u)")
//! runtextmacro HyperTable("handle" ,"string","string" ,"LoadStr( h,GetHandleId(s),StringHash(i) )","SaveStr( this.h,GetHandleId(this.i),StringHash(i) ,u)")
//! runtextmacro HyperTable("handle" ,"string","real" ,"LoadReal( h,GetHandleId(s),StringHash(i) )","SaveReal( this.h,GetHandleId(this.i),StringHash(i) ,u)")
//! runtextmacro HyperTable("handle" ,"string","boolean","LoadBoolean( h,GetHandleId(s),StringHash(i) )","SaveBoolean(this.h,GetHandleId(this.i),StringHash(i) ,u)")
//! runtextmacro HyperTable("integer","handle","integer","LoadInteger( h,s ,GetHandleId(i))","SaveInteger(this.h,this.i ,GetHandleId(i),u)")
//! runtextmacro HyperTable("integer","handle","string" ,"LoadStr( h,s ,GetHandleId(i))","SaveStr( this.h,this.i ,GetHandleId(i),u)")
//! runtextmacro HyperTable("integer","handle","real" ,"LoadReal( h,s ,GetHandleId(i))","SaveReal( this.h,this.i ,GetHandleId(i),u)")
//! runtextmacro HyperTable("integer","handle","boolean","LoadBoolean( h,s ,GetHandleId(i))","SaveBoolean(this.h,this.i ,GetHandleId(i),u)")
//! runtextmacro HyperTable("string" ,"handle","integer","LoadInteger( h,StringHash(s) ,GetHandleId(i))","SaveInteger(this.h,StringHash(this.i) ,GetHandleId(i),u)")
//! runtextmacro HyperTable("string" ,"handle","string" ,"LoadStr( h,StringHash(s) ,GetHandleId(i))","SaveStr( this.h,StringHash(this.i) ,GetHandleId(i),u)")
//! runtextmacro HyperTable("string" ,"handle","real" ,"LoadReal( h,StringHash(s) ,GetHandleId(i))","SaveReal( this.h,StringHash(this.i) ,GetHandleId(i),u)")
//! runtextmacro HyperTable("string" ,"handle","boolean","LoadBoolean( h,StringHash(s) ,GetHandleId(i))","SaveBoolean(this.h,StringHash(this.i) ,GetHandleId(i),u)")
//! runtextmacro HyperTable("handle" ,"handle","integer","LoadInteger( h,GetHandleId(s),GetHandleId(i))","SaveInteger(this.h,GetHandleId(this.i),GetHandleId(i),u)")
//! runtextmacro HyperTable("handle" ,"handle","string" ,"LoadStr( h,GetHandleId(s),GetHandleId(i))","SaveStr( this.h,GetHandleId(this.i),GetHandleId(i),u)")
//! runtextmacro HyperTable("handle" ,"handle","real" ,"LoadReal( h,GetHandleId(s),GetHandleId(i))","SaveReal( this.h,GetHandleId(this.i),GetHandleId(i),u)")
//! runtextmacro HyperTable("handle" ,"handle","boolean","LoadBoolean( h,GetHandleId(s),GetHandleId(i))","SaveBoolean(this.h,GetHandleId(this.i),GetHandleId(i),u)")
endlibrary/***********************************************************************/
/*********************************************************************************\
|* God bless textmacros! *|
|* This trigger would have been 1522 lines long without them! *|
\*********************************************************************************/
The library sais it all...
For questions, ask...
There's also a test map attached for integer testing...
Attachments
Last edited: