FTObjectClass Module

FTObject is the root class for all object types.

Overview

FTObject defines the basic methods that are essential for reference counted objects.

FTObject is generally not going to be instantiated by itself, but rather it will be subclassed and one will work with instances of the subclasses. Otherwise, pointers of type FTObject that point to instances of subclasses will be stored in the container classes.

Tasks

  • init()

    Initializes an object and any memory that it needs to allocate, etc. Should be orrerrided in subclasses.The base class implementation does nothing but increase the reference count of the object.

  • destruct()

    Destructor of the object, which releases and deallocates owned objects and memory. Should be overridden in subclasses. The base class implementation does nothing but decrease the reference count of the object.

  • printDescription(iUnit)

    Prints a description of the object to a specified file unit. The base class implementation does nothing but print "FTObject"

  • copy()

    Creates a copy (pointer) to the object of CLASS(FTObject) sourced with the object.

  • retain()

    Increases the reference count of the object. Any procedure or object that retain()'s an object gains an ownership stake in that object. This procedure is not overridable.

  • release()

    Decreases the reference count of an object. To be called only by objects or procedures that have ownership in an object pointer, i.e., for which init() or retain() have been called. Override this procedure in subclasses for releasing the actual type.

  • isUnreferenced()

    Test to see if there are no more owners of an object.

  • refCount()

    Returns the number of owners of an object. Usually this is of interest only for debugging purposes. This procedure is not overridable.

Subclassing FTObject

In general, subclasses of FTObject override

  • init()
  • destruct()
  • printDescription()
  • release()

They should also provide a cast() subroutine to convert from the base class to a subclass. The cast() routine can look something like

 SUBROUTINE castToSubclass(obj,cast) 
    IMPLICIT NONE  
    CLASS(FTObject), POINTER :: obj
    CLASS(SubClass), POINTER :: cast

    cast => NULL()
    SELECT TYPE (e => obj)
       TYPE is (SubClass)
          cast => e
       CLASS DEFAULT

    END SELECT

 END SUBROUTINE castToSubclass

Subclassing init

The init() procedure performs subclass specific operations to initialize an object.

Subclasses that override init() must include a call to the super class method. For example, overriding init looks like

 SUBROUTINE initSubclass(self) 
    IMPLICIT NONE
    CLASS(Subclass) :: self

    CALL self % FTObject % init()
    Allocate and initialize all member objects
    ... Other Subclass specific code
 END SUBROUTINE initSubclass

Subclassing destruct

The destruct() procedure reverses the operations done in the init() procedure. It releases and deallocates any pointers that it owns. Subclasses that override destruct() must include a call to the super class method. For example, overriding destruct looks like

 SUBROUTINE destructSubclass(self) 
    IMPLICIT NONE
    CLASS(Subclass) :: self

    Release and deallocate (if necessary) all member objects

 END SUBROUTINE destructSubclass

Subclassing printDescription(iUnit)

printDescription is a method whose existence is to support debugging. Call printDescription(iUnit) on any objects owned by self for a cascading of what is stored in the object.

Casting an object from the base to a subclass

Container classes and the copy function return pointers to a CLASS(FTObject). To use any subclass features one must "cast" to the subclass. We like to have a specific cast routine to do this as painlessly as possible. Each subclass should include a SUBROUTINE like this:

 SUBROUTINE castToSubclass(obj,cast) 
    IMPLICIT NONE  
    CLASS(FTObject), POINTER :: obj
    CLASS(Subclass), POINTER :: cast
    cast => NULL()
    SELECT TYPE (e => obj)
       TYPE is (Subclass)
          cast => e
       CLASS DEFAULT
    END SELECT
 END SUBROUTINE castToValue

Subclassing className

The className() procedure returns the name of the class.

Subclasses should override className() !>

Created: January 7, 2013 11:30 AM @author David A. Kopriva


Used by

  • module~~ftobjectclass~~UsedByGraph module~ftobjectclass FTObjectClass module~ftdataclass FTDataClass module~ftdataclass->module~ftobjectclass module~ftkeyobjectpairclass FTKeyObjectPairClass module~ftkeyobjectpairclass->module~ftobjectclass module~ftlinkedlistrecordclass FTLinkedListRecordClass module~ftlinkedlistrecordclass->module~ftobjectclass module~ftmultiindextableclass FTMultiIndexTableClass module~ftmultiindextableclass->module~ftobjectclass module~ftmultiindextabledata FTMultiIndexTableData module~ftmultiindextableclass->module~ftmultiindextabledata module~ftlinkedlistclass FTLinkedListClass module~ftmultiindextableclass->module~ftlinkedlistclass module~ftmultiindextabledata->module~ftobjectclass module~ftmutableobjectarrayclass FTMutableObjectArrayClass module~ftmutableobjectarrayclass->module~ftobjectclass module~ftobjectlibrary FTObjectLibrary module~ftobjectlibrary->module~ftobjectclass module~ftobjectlibrary->module~ftmutableobjectarrayclass module~ftsparsematrixclass FTSparseMatrixClass module~ftobjectlibrary->module~ftsparsematrixclass module~ftvalueclass FTValueClass module~ftobjectlibrary->module~ftvalueclass module~ftdictionaryclass FTDictionaryClass module~ftobjectlibrary->module~ftdictionaryclass module~ftobjectlibrary->module~ftlinkedlistclass module~ftvaluedictionaryclass FTValueDictionaryClass module~ftobjectlibrary->module~ftvaluedictionaryclass module~ftexceptionclass FTExceptionClass module~ftobjectlibrary->module~ftexceptionclass module~ftlinkedlistiteratorclass FTLinkedListIteratorClass module~ftobjectlibrary->module~ftlinkedlistiteratorclass module~ftstackclass FTStackClass module~ftobjectlibrary->module~ftstackclass module~ftsparsematrixclass->module~ftobjectclass module~ftsparsematrixdata FTSparseMatrixData module~ftsparsematrixclass->module~ftsparsematrixdata module~ftsparsematrixclass->module~ftlinkedlistclass module~ftsparsematrixclass->module~ftlinkedlistiteratorclass module~ftsparsematrixdata->module~ftobjectclass module~ftstringsetclass FTStringSetClass module~ftstringsetclass->module~ftobjectclass module~ftstringsetclass->module~ftdictionaryclass module~ftvalueclass->module~ftobjectclass module~ftdictionaryclass->module~ftkeyobjectpairclass module~ftdictionaryclass->module~ftmutableobjectarrayclass module~ftdictionaryclass->module~ftlinkedlistclass module~ftdictionaryclass->module~ftlinkedlistiteratorclass module~ftlinkedlistclass->module~ftlinkedlistrecordclass module~ftlinkedlistclass->module~ftmutableobjectarrayclass module~ftvaluedictionaryclass->module~ftvalueclass module~ftvaluedictionaryclass->module~ftdictionaryclass module~ftexceptionclass->module~ftdictionaryclass module~ftexceptionclass->module~ftvaluedictionaryclass module~ftexceptionclass->module~ftlinkedlistiteratorclass module~ftexceptionclass->module~ftstackclass module~ftlinkedlistiteratorclass->module~ftlinkedlistclass module~ftstackclass->module~ftlinkedlistclass module~sharedexceptionmanagermodule SharedExceptionManagerModule module~sharedexceptionmanagermodule->module~ftexceptionclass

Variables

Type Visibility Attributes Name Initial
integer, public, parameter :: DESCRIPTION_CHARACTER_LENGTH = 1024
integer, public, parameter :: CLASS_NAME_CHARACTER_LENGTH = 32

Interfaces

public interface release

  • public recursive subroutine releaseFTObject(self)

    releaseFTObject decreases the reference count by one and implies relinquishing ownership by the caller. Call this if control over the existence of an object pointer is no longer desired by the caller. When the reference count goes to zero, the destructor of the object is called automatically and the object is deallocated.

    Arguments

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

Derived Types

type, public ::  FTObject

Finalizations Procedures

final :: destructFTObject

Type-Bound Procedures

procedure, public :: init => initFTObject
procedure, public :: description => FTObjectDescription
procedure, public :: printDescription => printFTObjectDescription
procedure, public :: className
procedure, public, non_overridable :: copy => copyFTObject
procedure, public, non_overridable :: retain => retainFTObject
procedure, public, non_overridable :: isUnreferenced
procedure, public, non_overridable :: refCount

Functions

public function className(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(FTObject) :: self

Return Value character(len=CLASS_NAME_CHARACTER_LENGTH)

public function isUnreferenced(self)

Owners of objects should call isUnreferenced after releasing a pointer object. If true, the object should be deallocated and then set to point to NULL()

Read more…

Arguments

Type IntentOptional Attributes Name
class(FTObject) :: self

Return Value logical

public function refCount(self)

Returns the reference count for the object. Normally this is done only for debugging purposes.

Arguments

Type IntentOptional Attributes Name
class(FTObject) :: self

Return Value integer

public function FTObjectDescription(self)

Returns a character string of length DESCRIPTION_CHARACTER_LENGTH that represents the object. the base class implementation returns an empty string. Note that if the description is too long, the expected string will be truncated. In general, one wants to use printDescription.

Arguments

Type IntentOptional Attributes Name
class(FTObject) :: self

Return Value character(len=DESCRIPTION_CHARACTER_LENGTH)


Subroutines

public subroutine initFTObject(self)

Generic Name: init()

Read more…

Arguments

Type IntentOptional Attributes Name
class(FTObject) :: self

public subroutine destructFTObject(self)

Generic Name: destruct()

Read more…

Arguments

Type IntentOptional Attributes Name
type(FTObject) :: self

public subroutine retainFTObject(self)

Retain increases the reference count by one and implies ownership to the caller. ### Usage: CALL obj\ % retain()

Arguments

Type IntentOptional Attributes Name
class(FTObject) :: self

public recursive subroutine releaseFTObject(self)

releaseFTObject decreases the reference count by one and implies relinquishing ownership by the caller. Call this if control over the existence of an object pointer is no longer desired by the caller. When the reference count goes to zero, the destructor of the object is called automatically and the object is deallocated.

Arguments

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

public subroutine printFTObjectDescription(self, iUnit)

Generic Name: printDescription()

Read more…

Arguments

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