home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 1997 November
/
PCWorld_1997-11_cd.bin
/
software
/
programy
/
komix
/
DATA.Z
/
dictelement.sru
< prev
next >
Wrap
Text File
|
1997-04-03
|
3KB
|
158 lines
$PBExportHeader$dictelement.sru
$PBExportComments$An element in a classdict
forward
global type dictelement from nonvisualobject
end type
end forward
global type dictelement from nonvisualobject
end type
global dictelement dictelement
type variables
private powerobject contents
private any ckey
private dictelement nextElement, prevElement
end variables
forward prototypes
public function boolean contains (any key)
public function powerobject get (any key)
public subroutine set (any key, powerobject obj)
public subroutine remove (any key)
public function powerobject objectbyindex(integer index)
public function any keybyindex(integer index)
private function dictelement elementbyindex(integer index)
end prototypes
public function boolean contains (any key);//
if isNull(key) then
return false
end if
if not isNull(ckey) then
if key = ckey then
return true
end if
end if
if isNull(nextElement) then
return false
end if
return nextElement.contains(key)
end function
public function powerobject get (any key);//
powerobject nullobject
setNull(nullobject)
if isNull(key) then
return nullobject
end if
if not isNull(ckey) then
if key = ckey then
return contents
end if
end if
if isNull(nextElement) then
return nullobject
end if
return nextElement.get(key)
end function
public subroutine set (any key, powerobject obj);// insert key/obj just after this
if isNull(key) then
return
end if
if not isNull(ckey) then
if key = ckey then
contents = obj
return
end if
end if
if isNull(nextElement) then
dictelement element
element = create dictelement
element.ckey = key
element.contents = obj
element.prevElement = this
element.nextElement = nextElement
nextElement = element
return
end if
nextElement.set(key, obj)
end subroutine
public subroutine remove (any key);//
if isNull(key) then
return
end if
if isNull(nextElement) then
return
end if
if key = nextElement.ckey then
dictelement element
// remove nextElement from list and destroy it
element = nextElement
nextElement = element.nextElement
if not isNull(nextElement) then
nextElement.prevElement = this
end if
destroy element
return
end if
nextElement.remove(key)
end subroutine
public function any keybyindex (integer index);//
dictelement element
element = elementbyindex(index)
if isNull(element) then
any nullany
setNull(nullany)
return nullany
end if
return element.ckey
end function
public function powerobject objectbyindex (integer index);//
dictelement element
element = elementbyindex(index)
if isNull(element) then
powerobject nullobject
setNull(nullobject)
return nullobject
end if
return element.contents
end function
private function dictelement elementbyindex (integer index);//
if isNull(nextElement) then
dictelement nullelement
setNull(nullelement)
return nullelement
end if
if index = 0 then
return nextElement
end if
return nextElement.elementbyindex(index - 1)
end function
on dictelement.create
TriggerEvent( this, "constructor" )
end on
on dictelement.destroy
TriggerEvent( this, "destructor" )
end on
event constructor;//
setNull(contents)
setNull(ckey)
setNull(nextElement)
setNull(prevElement)
end event