• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[vJASS] Example Template Class (singly-linked list)


- This requires vJASS (go figure)
- You require W.E. with vJASS injector code to use this system (like This one)



Q: is it magic?
A: No.....

Q: Is it real?
A: yes.

Q: how does it worx?
A: its a very fancy linked list

Q: Is it syntactically clean?
A: sorta





Make sure you see the subtopic labled "textmacros"





[jass=genericList]
//genericList template class
//written by UnholyDecimator
// 12/6/15


//! textmacro genList takes listType, getterName, structName
struct $structName$
$listType$ cur
thistype next

public static method create takes $listType$ r returns thistype
local thistype new
set new = .allocate()

set new.cur = r
set new.next = 0

return new
endmethod

public method get$getterName$ takes nothing returns $listType$
return cur
endmethod

public method isChild takes nothing returns boolean
if (next == 0) then
return false
endif

return true
endmethod

public method attachChild takes $listType$ r returns nothing
set next = thistype.create(r)
endmethod

public method getChild takes nothing returns thistype
if (isChild()) then
return next
endif

return 0
endmethod

public method destroy takes nothing returns nothing
if(isChild()) then
call next.destroy()
endif
set cur = null
set next = 0
call .deallocate()
endmethod
endstruct

//! endtextmacro

[/code]



[jass=raceList]
//! runtextmacro genList("string", "String", "stringList")
[/code]



dfjcet.png



Example Map w/ Implementation
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,464
This is a singly linked-list. To show you how this could be simplified and be more similar to other list resources that we have:

JASS:
//! textmacro genList takes listType, getterName, structName, nullVal
struct $structName$
    $listType$ cur
    readonly thistype next
    
    static method create takes $listType$ r returns thistype
        local thistype new = .allocate()
        
        set new.cur = r
        
        return new
    endmethod
    
    method get$getterName$ takes nothing returns $listType$
        return cur
    endmethod
    
    method operator inList takes nothing returns boolean
        return next != 0
    endmethod
    
    method add takes $listType$ r returns nothing
        set next = thistype.create(r)
    endmethod
    
    method destroy takes nothing returns nothing
        if inList then
            call next.destroy()
        endif
        set cur = $nullVal$
        set next = 0
        call .deallocate()
    endmethod
endstruct

//! endtextmacro
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
I think this should be graveyarded by the fact that List<T> is approved now, and it has more funcionality, so this is like a weak subset of that + I think this has terrible API, after every insert you have to call getChild, which gets pretty heavy.
 
Top