home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 1998 October
/
PCWorld_1998-10_cd.bin
/
software
/
prehled
/
komix
/
DATA.Z
/
dictelement.sru
< prev
next >
Wrap
Text File
|
1997-08-06
|
4KB
|
183 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
powerobject contents
any ckey
dictelement nextElement, prevElement
end variables
forward prototypes
public function powerobject get (any key)
public function powerobject objectbyindex (integer index)
public function any keybyindex (integer index)
private function dictelement elementbyindex (integer index)
public function integer contains (any key)
public function integer remove (any key)
public function integer set (any key, powerobject obj)
end prototypes
public function powerobject get (any key);//
if isNull(key) and isNull(ckey) then
return contents
end if
if not isNull(ckey) then
if key = ckey then
return contents
end if
end if
if isNull(nextElement) then
powerobject nullobject
setNull(nullobject)
return nullobject
end if
return nextElement.get(key)
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
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
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
public function integer contains (any key);//
if isNull(key) then
return 0
end if
if not isNull(ckey) then
if key = ckey then
return 1
end if
end if
if isNull(nextElement) then
return 0
end if
return nextElement.contains(key)
end function
public function integer remove (any key);// checks next element and remove is applicable
dictelement element
if isNull(nextElement) then
return 0
end if
if isNull(key) and isNull(nextElement.ckey) then
// remove nextElement from list and destroy it
element = nextElement
nextElement = element.nextElement
if not isNull(nextElement) then
nextElement.prevElement = this
end if
setNull(element.prevElement)
setNull(element.nextElement)
destroy element
return 1
end if
if key = nextElement.ckey then
// remove nextElement from list and destroy it
element = nextElement
nextElement = element.nextElement
if not isNull(nextElement) then
nextElement.prevElement = this
end if
setNull(element.prevElement)
setNull(element.nextElement)
destroy element
return 1
end if
return nextElement.remove(key)
end function
public function integer set (any key, powerobject obj);// insert key/obj at end or at key position
if isNull(key) and isNull(ckey) then
// replace
contents = obj
return 0
end if
if not isNull(ckey) and not isNull(key) then
if key = ckey then
// replace
contents = obj
return 0
end if
end if
if isNull(nextElement) then
// add
dictelement element
element = create dictelement
element.ckey = key
element.contents = obj
element.prevElement = this
element.nextElement = nextElement
nextElement = element
return 1
end if
return nextElement.set(key, obj)
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
event destructor;// destroy nextElement
setNull(contents)
setNull(ckey)
setNull(prevElement)
if not isNull(nextElement) then
destroy nextElement
end if
setNull(nextElement)
end event