FTDictionaryClass Module

A dictionary is a special case of a hash table that stores key-value pairs.

It is an example of what is called an ``associative container''. In the implementation of FTObjectLibrary, the value can be any subclass of FTObject and the key is a character variable. The library includes the base dictionary that can store and retrieve any subclass of FTObject. It also includes a subclass that is designed to store and retrieve FTValue objects.

FTDictionary (Inherits from FTObject)

Initialization

     CLASS(FTDictionary), POINTER :: dict
     ALLOCATE(dict)
     CALL dict % initWithSize(N) ! N = size of dictionary. Should be power of two

Adding entries

     CLASS(FTDictionary), POINTER :: dict
     CLASS(FTObject)    , POINTER :: obj
     CHARACTER(LEN=N)             :: key
     obj => r                            ! r is subclass of FTObject
     CALL dict % addObjectForKey(obj,key)

Accessing entries

     obj => dict % objectForKey(key)
     CALL cast(obj,v) ! v is the type of object to be extracted

Destruction

     CALL release(dict) ! Pointer
     call dict % destruct() ! Stack variable

Accessing an object

       TYPE(FTObject) :: obj
       obj => dict % objectForKey(key)

Converting a base class pointer to a dictionary

       dict =>  dictionaryFromObject(obj)

Getting all of the keys

       CHARACTER(LEN=FTDICT_KWD_STRING_LENGTH), POINTER :: keys(:)
       keys =>  dict % allKeys()

(The target of the pointer must be deallocated by the caller)

Getting all of the objects

       CLASS(FTMutableObjectArray), POINTER :: objectArray
       objectArray =>  dict % allObjects() ! The array is owned by the caller.

(The target of the pointer must be released by the caller)



Interfaces

public interface cast

public interface release

  • public subroutine releaseFTDictionary(self)

    Public, generic name: release(self)

    Call release(self) on an object to release control of an object. If its reference count is zero, then it is deallocated.

    Arguments

    Type IntentOptional Attributes Name
    type(FTDictionary), POINTER :: self

Derived Types

type, public, extends(FTObject) ::  FTDictionary

Components

Type Visibility Attributes Name Initial
integer, public :: numberOfEntries
logical, public :: isCaseSensitive
type(FTLinkedList), public, DIMENSION(:), POINTER :: entries => NULL()

Type-Bound Procedures

procedure, public, non_overridable :: copy => copyFTObject
procedure, public, non_overridable :: retain => retainFTObject
procedure, public, non_overridable :: isUnreferenced
procedure, public, non_overridable :: refCount
procedure, public :: initWithSize
procedure, public :: init
procedure, public :: setCaseSensitive
procedure, public :: caseSensitive
procedure, public :: allKeys => AllKeys
procedure, public :: allObjects => AllObjects
procedure, public :: destruct => destructFTDictionary
procedure, public :: addObjectForKey
procedure, public :: removeObjectForKey
procedure, public :: description => FTDictionaryDescription
procedure, public :: printDescription => printFTDictionaryDescription
procedure, public :: objectForKey
procedure, public :: containsKey
procedure, public :: className => dictionaryClassName
procedure, public :: COUNT

Functions

public function caseSensitive(self)

Arguments

Type IntentOptional Attributes Name
class(FTDictionary) :: self

Return Value logical

public function COUNT(self)

Arguments

Type IntentOptional Attributes Name
class(FTDictionary) :: self

Return Value integer

public function objectForKey(self, key)

Arguments

Type IntentOptional Attributes Name
class(FTDictionary) :: self
character(len=*) :: key

Return Value class(FTObject), POINTER

public function containsKey(self, key) result(r)

Arguments

Type IntentOptional Attributes Name
class(FTDictionary) :: self
character(len=*) :: key

Return Value logical

public function objectForKeyInList(key, list)

Arguments

Type IntentOptional Attributes Name
character(len=*) :: key
class(FTLinkedList) :: list

Return Value class(FTObject), POINTER

public function FTDictionaryDescription(self)

Arguments

Type IntentOptional Attributes Name
class(FTDictionary) :: self

Return Value character(len=description_character_length)

public function AllObjects(self) result(objectArray)

Arguments

Type IntentOptional Attributes Name
class(FTDictionary) :: self

Return Value class(FTMutableObjectArray), POINTER

public function AllKeys(self) result(keys)

Arguments

Type IntentOptional Attributes Name
class(FTDictionary) :: self

Return Value character(len=FTDICT_KWD_STRING_LENGTH), POINTER, (:)

public function dictionaryFromObject(obj) result(cast)

Arguments

Type IntentOptional Attributes Name
class(FTObject), POINTER :: obj

Return Value class(FTDictionary), POINTER

public function dictionaryClassName(self) result(s)

Class name returns a string with the name of the type of the object

Read more…

Arguments

Type IntentOptional Attributes Name
class(FTDictionary) :: self

Return Value character(len=CLASS_NAME_CHARACTER_LENGTH)


Subroutines

public subroutine init(self)

Arguments

Type IntentOptional Attributes Name
class(FTDictionary) :: self

public subroutine initWithSize(self, sze)

Arguments

Type IntentOptional Attributes Name
class(FTDictionary) :: self
integer, intent(in) :: sze

public subroutine destructFTDictionary(self)

Arguments

Type IntentOptional Attributes Name
class(FTDictionary) :: self

public subroutine releaseFTDictionary(self)

Public, generic name: release(self)

Read more…

Arguments

Type IntentOptional Attributes Name
type(FTDictionary), POINTER :: self

public subroutine setCaseSensitive(self, bool)

Arguments

Type IntentOptional Attributes Name
class(FTDictionary) :: self
logical :: bool

public subroutine addObjectForKey(self, object, key)

Arguments

Type IntentOptional Attributes Name
class(FTDictionary) :: self
class(FTObject), POINTER :: object
character(len=*) :: key

public subroutine removeObjectForKey(self, key)

Arguments

Type IntentOptional Attributes Name
class(FTDictionary) :: self
character(len=*) :: key

public subroutine printFTDictionaryDescription(self, iUnit)

Arguments

Type IntentOptional Attributes Name
class(FTDictionary) :: self
integer :: iUnit

public subroutine castToDictionary(obj, cast)

Arguments

Type IntentOptional Attributes Name
class(FTObject), POINTER :: obj
class(FTDictionary), POINTER :: cast