home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 1998 October
/
PCWorld_1998-10_cd.bin
/
software
/
prehled
/
komix
/
DATA.Z
/
RefDict.4gl
< prev
next >
Wrap
Text File
|
1996-07-02
|
4KB
|
182 lines
-----------------------------------------------------------------------------
--
-- Copyright (c) 1994 by Westmount Technology B.V., Delft, The Netherlands.
--
-- This software is furnished under a license and may be used only in
-- accordance with the terms of such license and with the inclusion of
-- the above copyright notice. This software or any other copies thereof
-- may not be provided or otherwise made available to any other person.
-- No title to and ownership of the software is hereby transferred.
--
-- The information in this software is subject to change without notice
-- and should not be construed as a commitment by Westmount Technology B.V.
--
-----------------------------------------------------------------------------
--
-- File : @(#)RefDict.4gl 1.1
-- Author :
-- Original date : 19-10-1994
-- Description : A simple RefDict (map of key-value pairs)
-- Both key and value are ixObject references
--
-----------------------------------------------------------------------------
INCLUDE "RefDict.4gh"
FUNCTION DictSlot::DictSlot(aKey ixObject, aValue ixObject)
LET key = aKey
LET value = aValue
END FUNCTION
FUNCTION DictSlot::isEqualTo(other ixObject) RETURNING BOOLEAN
VARIABLE otherSlot DictSlot
IF other IS NULL THEN
RETURN FALSE
END IF
LET otherSlot = other CAST DictSlot
IF otherSlot IS NULL THEN
RETURN FALSE
END IF
RETURN key.isEqualTo(otherSlot.getKey())
END FUNCTION
FUNCTION DictSlot::getKey() RETURNING ixObject
RETURN key
END FUNCTION
FUNCTION DictSlot::getValue() RETURNING ixObject
RETURN value
END FUNCTION
FUNCTION DictSlot::setValue(newValue ixObject) RETURNING VOID
LET value = newValue
END FUNCTION
FUNCTION RefDict::RefDict()
LET s = NEW ORefSet()
END FUNCTION
FUNCTION RefDict::find(key ixObject) RETURNING DictSlot
VARIABLE i INTEGER
VARIABLE slot DictSlot
VARIABLE obj ixObject
FOR i = 1 TO s.getCount()
LET obj = s.get(i)
IF obj IS NOT NULL THEN
LET slot = obj CAST DictSlot
IF key.isEqualTo(slot.getKey()) THEN
RETURN slot
END IF
END IF
END FOR
RETURN NULL
END FUNCTION
FUNCTION RefDict::set(key ixObject, value ixObject) RETURNING VOID
VARIABLE slot DictSlot = find(key)
VARIABLE retVal INTEGER
IF slot IS NOT NULL THEN
-- slot already exists
CALL slot.setValue(value)
RETURN
END IF
-- add a new slot
LET retVal = s.append(NEW DictSlot(key, value))
END FUNCTION
FUNCTION RefDict::get(key ixObject) RETURNING ixObject
VARIABLE slot DictSlot = find(key)
IF slot IS NOT NULL THEN
RETURN slot.getValue()
END IF
RETURN NULL
END FUNCTION
FUNCTION RefDict::remove(key ixObject) RETURNING VOID
VARIABLE retVal INTEGER
VARIABLE slot DictSlot = find(key)
IF slot IS NOT NULL THEN
CALL s.remove(slot)
END IF
END FUNCTION
FUNCTION RefDict::isPresent(key ixObject) RETURNING BOOLEAN
VARIABLE slot DictSlot = find(key)
IF slot IS NULL THEN
RETURN FALSE
END IF
RETURN TRUE
END FUNCTION
FUNCTION RefDict::size() RETURNING INTEGER
RETURN s.size()
END FUNCTION
FUNCTION RefDict::firstKey() RETURNING ixObject
VARIABLE obj ixObject = s.first()
VARIABLE slot DictSlot
IF obj IS NOT NULL THEN
LET slot = obj CAST DictSlot
IF slot IS NOT NULL THEN
RETURN slot.getKey()
END IF
END IF
RETURN NULL
END FUNCTION
FUNCTION RefDict::nextKey() RETURNING ixObject
VARIABLE obj ixObject = s.next()
VARIABLE slot DictSlot
IF obj IS NOT NULL THEN
LET slot = obj CAST DictSlot
IF slot IS NOT NULL THEN
RETURN slot.getKey()
END IF
END IF
RETURN NULL
END FUNCTION
FUNCTION RefDict::firstValue() RETURNING ixObject
VARIABLE obj ixObject = s.first()
VARIABLE slot DictSlot
IF obj IS NOT NULL THEN
LET slot = obj CAST DictSlot
IF slot IS NOT NULL THEN
RETURN slot.getValue()
END IF
END IF
RETURN NULL
END FUNCTION
FUNCTION RefDict::nextValue() RETURNING ixObject
VARIABLE obj ixObject = s.next()
VARIABLE slot DictSlot
IF obj IS NOT NULL THEN
LET slot = obj CAST DictSlot
IF slot IS NOT NULL THEN
RETURN slot.getValue()
END IF
END IF
RETURN NULL
END FUNCTION