FTObject is the root class for all object types.
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.
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.
In general, subclasses of FTObject override
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
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
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
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.
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
The className() procedure returns the name of the class.
Subclasses should override className() !>
Created: January 7, 2013 11:30 AM @author David A. Kopriva
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
integer, | public, | parameter | :: | DESCRIPTION_CHARACTER_LENGTH | = | 1024 | |
integer, | public, | parameter | :: | CLASS_NAME_CHARACTER_LENGTH | = | 32 |
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.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(FTObject), | POINTER | :: | self |
final :: destructFTObject |
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 |
Class name returns a string with the name of the type of the object
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(FTObject) | :: | 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()
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(FTObject) | :: | self |
Returns the reference count for the object. Normally this is done only for debugging purposes.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(FTObject) | :: | 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.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(FTObject) | :: | self |
Generic Name: init()
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(FTObject) | :: | self |
Generic Name: destruct()
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(FTObject) | :: | self |
Retain increases the reference count by one and implies ownership to the caller. ### Usage: CALL obj\ % retain()
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(FTObject) | :: | 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.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(FTObject), | POINTER | :: | self |
Generic Name: printDescription()
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(FTObject) | :: | self | ||||
integer | :: | iUnit |