Executor
I see you
- Reaction score
- 57
Hi,
I need help generating a struct, which is able to store every type in wc3 efficiently (no hashtable). I dislike many ifs.
The following code is my momentarily progress. Theoratically it would work, but when I now want to copy for example one "Data" I have to access the right struct of the type, but I don't know how to connect a structTYPE to an integer. Ask if you need further explanations, cannot really verbalize it.
I need help generating a struct, which is able to store every type in wc3 efficiently (no hashtable). I dislike many ifs.
The following code is my momentarily progress. Theoratically it would work, but when I now want to copy for example one "Data" I have to access the right struct of the type, but I don't know how to connect a structTYPE to an integer. Ask if you need further explanations, cannot really verbalize it.
JASS:
//! textmacro TypeIndexer takes TYPE
private struct $TYPE$_Indexer
$TYPE$ value
static method newValue takes $TYPE$ t returns integer
local thistype this = thistype.allocate()
set .value = t
return this
endmethod
endstruct
//! endtextmacro
//! runtextmacro TypeIndexer("integer")
//! runtextmacro TypeIndexer("real")
//! runtextmacro TypeIndexer("boolean")
//! runtextmacro TypeIndexer("string")
//! runtextmacro TypeIndexer("player")
//! runtextmacro TypeIndexer("widget")
//! runtextmacro TypeIndexer("destructable")
//! runtextmacro TypeIndexer("item")
//! runtextmacro TypeIndexer("unit")
//! runtextmacro TypeIndexer("ability")
//! runtextmacro TypeIndexer("timer")
//! runtextmacro TypeIndexer("trigger")
//! runtextmacro TypeIndexer("triggercondition")
//! runtextmacro TypeIndexer("triggeraction")
//! runtextmacro TypeIndexer("event")
//! runtextmacro TypeIndexer("force")
//! runtextmacro TypeIndexer("group")
//! runtextmacro TypeIndexer("location")
//! runtextmacro TypeIndexer("rect")
//! runtextmacro TypeIndexer("boolexpr")
//! runtextmacro TypeIndexer("sound")
//! runtextmacro TypeIndexer("effect")
//! runtextmacro TypeIndexer("unitpool")
//! runtextmacro TypeIndexer("itempool")
//! runtextmacro TypeIndexer("quest")
//! runtextmacro TypeIndexer("questitem")
//! runtextmacro TypeIndexer("defeatcondition")
//! runtextmacro TypeIndexer("timerdialog")
//! runtextmacro TypeIndexer("leaderboard")
//! runtextmacro TypeIndexer("multiboard")
//! runtextmacro TypeIndexer("multiboarditem")
//! runtextmacro TypeIndexer("trackable")
//! runtextmacro TypeIndexer("dialog")
//! runtextmacro TypeIndexer("button")
//! runtextmacro TypeIndexer("texttag")
//! runtextmacro TypeIndexer("lightning")
//! runtextmacro TypeIndexer("image")
//! runtextmacro TypeIndexer("ubersplat")
//! runtextmacro TypeIndexer("region")
//! runtextmacro TypeIndexer("fogstate")
//! runtextmacro TypeIndexer("fogmodifier")
//! runtextmacro TypeIndexer("hashtable")
private struct Data
integer TYPE
integer index
method assignStringValue takes string value returns thistype
if IsInt(value) then
set .TYPE = TYPE_INTEGER
set .index = integer_Indexer.newValue(S2I(value))
elseif IsReal(value) then
set .TYPE = TYPE_REAL
set .index = real_Indexer.newValue(S2R(value))
elseif (value=="TRUE") or (value=="FALSE") then
set .TYPE = TYPE_BOOLEAN
set .index = boolean_Indexer.newValue(S2B(value))
elseif IsRawcode(value) then
set .TYPE = TYPE_INTEGER
set .index = integer_Indexer.newValue(String2Rawcode(SubString(value,1,StringLength(value)-1)))
else
set .TYPE = TYPE_STRING
set .index = string_Indexer.newValue(value)
endif
return this
endmethod
static method create takes nothing returns thistype
local thistype this = thistype.allocate()
return this
endmethod
endstruct