Warcraft 3 documentation
vJASS & Zinc Documentation
For the latest documentation about how it works vJASS and Zinc language layers for Warcraft III, please follow these links:
Jasshelper documentation - Zinc documentation - WC3 Optimizer documentation

StaticUniqueList No New Posts Codes & Snippets

Started by
moyack

0 Members and 1 Guest are viewing this topic.

StaticUniqueList
on: February 24, 2012, 09:01:18 PM
Category: Variables
Language: vJASS

Related Topics or Resources



by

Code: jass
  1. library StaticUniqueList /* v1.0.0.2
  2. ************************************************************************************
  3. *
  4. *       */ uses /*
  5. *
  6. *               */ ErrorMessage /*
  7. *
  8. ************************************************************************************
  9. *
  10. *       module StaticUniqueList
  11. *
  12. *               Description
  13. *               -------------------------
  14. *
  15. *                       Node Properties:
  16. *
  17. *                               Unique
  18. *                               Not 0
  19. *
  20. *               Fields
  21. *               -------------------------
  22. *
  23. *                       readonly static integer sentinel
  24. *
  25. *                       readonly static thistype first
  26. *                       readonly static thistype last
  27. *
  28. *                       readonly thistype next
  29. *                       readonly thistype prev
  30. *
  31. *               Methods
  32. *               -------------------------
  33. *
  34. *                       static method push takes thistype node returns nothing
  35. *                       static method enqueue takes thistype node returns nothing
  36. *
  37. *                       static method pop takes nothing returns nothing
  38. *                       static method dequeue takes nothing returns nothing
  39. *
  40. *                       method remove takes nothing returns nothing
  41. *
  42. *                       static method clear takes nothing returns nothing
  43. *
  44. ************************************************************************************/
  45.         module StaticUniqueList
  46.                 debug private boolean isNode
  47.                
  48.                 private thistype _next
  49.                 method operator next takes nothing returns thistype
  50.                         debug call ThrowError(this == 0,        "StaticUniqueList", "next", "thistype", this, "Attempted To Go Out Of Bounds.")
  51.                         debug call ThrowError(not isNode,       "StaticUniqueList", "next", "thistype", this, "Attempted To Read Invalid Node.")
  52.                        
  53.                         return _next
  54.                 endmethod
  55.                
  56.                 private thistype _prev
  57.                 method operator prev takes nothing returns thistype
  58.                         debug call ThrowError(this == 0,        "StaticUniqueList", "prev", "thistype", this, "Attempted To Go Out Of Bounds.")
  59.                         debug call ThrowError(not isNode,       "StaticUniqueList", "prev", "thistype", this, "Attempted To Read Invalid Node.")
  60.                        
  61.                         return _prev
  62.                 endmethod
  63.                
  64.                 static method operator first takes nothing returns thistype
  65.                         return thistype(0)._next
  66.                 endmethod
  67.                 static method operator last takes nothing returns thistype
  68.                         return thistype(0)._prev
  69.                 endmethod
  70.                
  71.                 private static method setFirst takes thistype node returns nothing
  72.                         set thistype(0)._next = node
  73.                 endmethod
  74.                
  75.                 private static method setLast takes thistype node returns nothing
  76.                         set thistype(0)._prev = node
  77.                 endmethod
  78.                
  79.                 static constant integer sentinel = 0
  80.                
  81.                 static method push takes thistype node returns nothing
  82.                         debug call ThrowError(node == 0,        "StaticUniqueList", "push", "thistype", 0, "Attempted To Push Null Node.")
  83.                         debug call ThrowError(node.isNode,      "StaticUniqueList", "push", "thistype", 0, "Attempted To Push Owned Node (" + I2S(node) + ").")
  84.                        
  85.                         debug set node.isNode = true
  86.                        
  87.                         set first._prev = node
  88.                         set node._next = first
  89.                         call setFirst(node)
  90.                                
  91.                         set node._prev = 0
  92.                 endmethod
  93.                 static method enqueue takes thistype node returns nothing
  94.                         debug call ThrowError(node == 0,        "StaticUniqueList", "enqueue", "thistype", 0, "Attempted To Enqueue Null Node.")
  95.                         debug call ThrowError(node.isNode,      "StaticUniqueList", "enqueue", "thistype", 0, "Attempted To Enqueue Owned Node (" + I2S(node) + ").")
  96.                        
  97.                         debug set node.isNode = true
  98.                        
  99.                         set last._next = node
  100.                         set node._prev = last
  101.                         call setLast(node)
  102.                        
  103.                         set node._next = 0
  104.                 endmethod
  105.                 static method pop takes nothing returns nothing
  106.                         debug call ThrowError(first == 0,       "StaticUniqueList", "pop", "thistype", 0, "Attempted To Pop Empty List.")
  107.                        
  108.                         debug set first.isNode = false
  109.                        
  110.                         call setFirst(first._next)
  111.                         set first._prev = 0
  112.                 endmethod
  113.                 static method dequeue takes nothing returns nothing
  114.                         debug call ThrowError(last == 0,        "StaticUniqueList", "dequeue", "thistype", 0, "Attempted To Dequeue Empty List.")
  115.                        
  116.                         debug set last.isNode = false
  117.                        
  118.                         call setLast(last._prev)
  119.                         set last._next = 0
  120.                 endmethod
  121.                 method remove takes nothing returns nothing
  122.                         debug call ThrowError(this == 0,        "StaticUniqueList", "remove", "thistype", 0, "Attempted To Remove Null Node.")
  123.                         debug call ThrowError(not isNode,       "StaticUniqueList", "remove", "thistype", 0, "Attempted To Remove Invalid Node (" + I2S(this) + ").")
  124.                        
  125.                         debug set isNode = false
  126.                        
  127.                         set _prev._next = _next
  128.                         set _next._prev = _prev
  129.                 endmethod
  130.                 static method clear takes nothing returns nothing
  131.                         static if DEBUG_MODE then
  132.                                 local thistype node = first
  133.                        
  134.                                 loop
  135.                                         exitwhen node == 0
  136.                                         set node.isNode = false
  137.                                         set node = node._next
  138.                                 endloop
  139.                         endif
  140.                        
  141.                         call setFirst(0)
  142.                         call setLast(0)
  143.                 endmethod
  144.         endmodule
  145. endlibrary
« Last Edit: December 19, 2017, 12:39:36 AM by moyack »



 

Vivir aprendiendo.co - A place for learning stuff, in Spanish   Chaos Realm - The world of Game modders and wc3 addicts   Diplo, a gaming community   Power of Corruption, an altered melee featuring Naga and Demon. Play it now!!!   WC3JASS.com - The JASS Vault + vJASS and Zinc   Jetcraft - A Starcraft II mod   WormTastic Clan (wTc)   Warcraft RESOURCES Reforged: Modelos, mapas, proyectos y mas...