- Joined
- Sep 12, 2008
- Messages
- 657
hey.. actually managed to do something with my stack code,
which so far amazingly helped me alot.. [percents, enumoration data, etc]
but i need ideas on what to add/how to improve it,
and if there is anything wrong i've done.
thanks in advance. [well.. its actually my first code i manged to fix without getting too mad.. TBH just made it 1 hour ago.. guessing this wasnt to hard.. used some functions from my old code too, which saved me lot's of time.] please do not tell me theres the original stack,
as i realise that. and i wanted this cuz i like behing able to customize my own codes to my usage. (like the textmacro)
which so far amazingly helped me alot.. [percents, enumoration data, etc]
but i need ideas on what to add/how to improve it,
and if there is anything wrong i've done.
JASS:
library Stack
globals
public constant boolean DEBUG_MODE = true
endglobals
endlibrary
//! textmacro NEW_STACK takes nameHEADER, valueTYPE, ZeroTheValue
function interface enumorationResponse$valueTYPE$ takes $valueTYPE$ data, handle passedKey returns boolean
struct $nameHEADER$Stack
public integer LAST_INDEX
public integer instanceCount
public $valueTYPE$ array data [12000]
public handle array passedKey [12000]
public boolean array locked [12000]
public boolean array online [12000]
public method add takes $valueTYPE$ value, handle messageKey returns integer
if instanceCount < 11999 then
set data[instanceCount] = value
set passedKey[instanceCount] = messageKey
set locked[instanceCount] = false
set online[instanceCount] = true
set instanceCount = instanceCount + 1
elseif instanceCount >= 11999 and Stack_DEBUG_MODE == true then
call BJDebugMsg("$nameHEADER$Stack has reached data limit, cannot add more values to the stack.")
return null
endif
set LAST_INDEX = instanceCount
return instanceCount
endmethod
public method editKey takes integer index, handle key returns boolean
if locked[index] == true then
return false
endif
set passedKey[index] = key
return true
endmethod
public method lock takes integer index, boolean lock returns nothing
set locked[index] = lock
endmethod
public method swap takes integer indexA, integer indexB returns boolean
local $valueTYPE$ dataA = data[indexA]
local $valueTYPE$ dataB = data[indexB]
local handle keyA = passedKey[indexA]
local handle keyB = passedKey[indexB]
if locked[indexA] or locked[indexB] or online[indexA] == false or online[indexB] == false then
return false
endif
set data[indexA] = dataB
set data[indexB] = dataA
set passedKey[indexA] = keyB
set passedKey[indexB] = keyA
return true
endmethod
public method clean takes integer index returns boolean
if online[index] == false then
return false
endif
set online[index] = false
static if $boolean$ then
set data[index] = 0
else
set data[index] = null
endif
set passedKey[index] = null
set locked[index] = false
return true
endmethod
public method enumorate takes enumorationResponse$valueTYPE$ ev, boolean TopToBottom returns nothing
local integer start = 0
local integer i
local integer end = instanceCount
local integer step = 0
local integer step2 = 1
local boolean destroy = false
if TopToBottom then
set start = instanceCount
set end = 0
set step = -1
set step2 = 0
endif
set i = start
loop
set i = i + step
if online[i] == true then
set destroy = ev.evaluate(data[i], passedKey[i])
endif
if destroy then
call clean(i)
endif
set i = i + step2
exitwhen i == end
endloop
endmethod
endstruct
//! endtextmacro
//! runtextmacro NEW_STACK("i", "integer", "true")
//! runtextmacro NEW_STACK("r", "real", "true")
//! runtextmacro NEW_STACK("d", "destructable", "false")
thanks in advance. [well.. its actually my first code i manged to fix without getting too mad.. TBH just made it 1 hour ago.. guessing this wasnt to hard.. used some functions from my old code too, which saved me lot's of time.] please do not tell me theres the original stack,
as i realise that. and i wanted this cuz i like behing able to customize my own codes to my usage. (like the textmacro)