home *** CD-ROM | disk | FTP | other *** search
/ PC World 1997 November / PCWorld_1997-11_cd.bin / software / programy / komix / DATA.Z / setelement.sru < prev    next >
Encoding:
Text File  |  1997-04-25  |  2.4 KB  |  108 lines

  1. $PBExportHeader$setelement.sru
  2. $PBExportComments$An element in a classset (actually a list element)
  3. forward
  4. global type setelement from nonvisualobject
  5. end type
  6. end forward
  7.  
  8. global type setelement from nonvisualobject
  9. end type
  10. global setelement setelement
  11.  
  12. type variables
  13. powerobject contents
  14. setelement nextElement, prevElement
  15. end variables
  16.  
  17. forward prototypes
  18. public function boolean contains (powerobject obj)
  19. public function powerobject get (integer index)
  20. public subroutine add (powerobject obj)
  21. public function boolean remove (powerobject obj)
  22. public function boolean remove (integer index)
  23. end prototypes
  24.  
  25. public function boolean contains (powerobject obj);//
  26. if isNull(nextElement) then
  27.     return false
  28. end if
  29. if obj = nextElement.contents then 
  30.     return true
  31. end if
  32. return nextElement.contains(obj)
  33. end function
  34.  
  35. public function powerobject get (integer index);//
  36. if isNull(nextElement) then
  37.     powerobject nullobject
  38.     setNull(nullobject)
  39.     return nullobject
  40. end if
  41. if index = 0 then
  42.     return nextElement.contents    
  43. end if
  44. return nextElement.get(index - 1)
  45. end function
  46.  
  47. public subroutine add (powerobject obj);// insert obj just after this
  48. setelement element
  49.  
  50. element = create setelement
  51. element.contents = obj
  52.  
  53. element.prevElement = this
  54. element.nextElement = nextElement
  55. nextElement = element
  56. end subroutine
  57.  
  58. public function boolean remove (powerobject obj);//
  59. if isNull(nextElement) then
  60.     return false
  61. end if
  62. if obj = nextElement.contents then
  63.     setelement element
  64.     // remove nextElement from list and destroy it
  65.     element = nextElement
  66.     nextElement = element.nextElement
  67.     if not isNull(nextElement) then 
  68.         nextElement.prevElement = this
  69.     end if
  70.     destroy element
  71.     return true
  72. end if
  73. return nextElement.remove(obj)
  74. end function
  75.  
  76. public function boolean remove (integer index);//
  77. if isNull(nextElement) then
  78.     return false
  79. end if
  80. if index = 0 then
  81.     setelement element
  82.     // remove nextElement from list and destroy it
  83.     element = nextElement
  84.     nextElement = element.nextElement
  85.     if not isNull(nextElement) then 
  86.         nextElement.prevElement = this
  87.     end if
  88.     destroy element
  89.     return true
  90. end if
  91. return nextElement.remove(index - 1)
  92. end function
  93.  
  94. on setelement.create
  95. TriggerEvent( this, "constructor" )
  96. end on
  97.  
  98. on setelement.destroy
  99. TriggerEvent( this, "destructor" )
  100. end on
  101.  
  102. event constructor;//
  103. setNull(contents)
  104. setNull(nextElement)
  105. setNull(prevElement)
  106. end event
  107.  
  108.