FTMutableObjectArrayClass Module

FTMutableObjectArray is a mutable array class to which objects can be added, removed, replaced and accessed according to their index in the array.

Fortran has pointers to arrays, but not arrays of pointers. To do the latter, one creates a wrapper derived type and creates an array of that wrapper type. Fortran arrays are great, but they are of fixed length, and they don't easily implement reference counting to keep track of memory. For that, we have the FTMutableObjectArray. Performance reasons dictate that you will use regular arrays for numeric types and the like, but for generic objects we would use an Object Array.

You initialize a FTMutableObjectArray with the number of objects that you expect it to hold. However, it can re-size itself if necessary. To be efficient, it adds more than one entry at a time given by the ``chunkSize'', which you can choose for yourself. (The default is 10.)

Definition

       TYPE(FTMutableObjectArray) :: array

Usage

Initialization

  CLASS(FTMutableObjectArray)  :: array
  INTEGER                      :: N = 11
  CALL array % initWithSize(N)

Destruction

       CALL array  %  destuct() [Non Pointers]
       call release(array) [Pointers]

Adding an Object

       TYPE(FTObject) :: obj
       obj => r1
       CALL array % addObject(obj)

Removing an Object

       TYPE(FTObject) :: obj
       CALL array % removeObjectAtIndex(i)

Accessing an Object

       TYPE(FTObject) :: obj
       obj => array % objectAtIndex(i)

Replacing an Object

       TYPE(FTObject) :: obj
       obj => r1
       CALL array % replaceObjectAtIndexWithObject(i,obj)

Setting the Chunk Size

       CALL array % setChunkSize(size)

Finding The Number Of Items In The Array

       n =  array % count()

Finding The Actual Allocated Size Of The Array

       n =  array % allocatedSize()


Interfaces

public interface cast

public interface release

  • public subroutine releaseFTMutableObjectArray(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(FTMutableObjectArray), POINTER :: self

Derived Types

type, public, extends(FTObject) ::  FTMutableObjectArray

Type-Bound Procedures

procedure, public :: init => initFTObject
procedure, public :: description => FTObjectDescription
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 => initObjectArrayWithSize
procedure, public :: destruct => destructObjectArray
procedure, public :: addObject => addObjectToArray
procedure, public :: replaceObjectAtIndexWithObject
procedure, public :: removeObjectAtIndex
procedure, public :: objectAtIndex
procedure, public :: printDescription => printArray
procedure, public :: className => arrayClassName
procedure, public :: setChunkSize
procedure, public :: chunkSize
procedure, public :: COUNT => numberOfItems
procedure, public :: allocatedSize

Functions

public function objectAtIndex(self, indx) result(obj)

Access the object at the index indx

Read more…

Arguments

Type IntentOptional Attributes Name
class(FTMutableObjectArray) :: self
integer :: indx

Return Value class(FTObject), POINTER

public function chunkSize(self)

Returns the number of items to be added when the array needs to be re-sized

Read more…

Arguments

Type IntentOptional Attributes Name
class(FTMutableObjectArray) :: self

Return Value integer

public function numberOfItems(self)

Generic name: count

Read more…

Arguments

Type IntentOptional Attributes Name
class(FTMutableObjectArray) :: self

Return Value integer

public function allocatedSize(self)

Arguments

Type IntentOptional Attributes Name
class(FTMutableObjectArray) :: self

Return Value integer

public function objectArrayFromObject(obj) result(cast)

Generic Name: cast

Read more…

Arguments

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

Return Value class(FTMutableObjectArray), POINTER

public function arrayClassName(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(FTMutableObjectArray) :: self

Return Value character(len=CLASS_NAME_CHARACTER_LENGTH)


Subroutines

public subroutine initObjectArrayWithSize(self, arraySize)

Designated initializer. Initializes the amount of storage, but the array remains empty.

Read more…

Arguments

Type IntentOptional Attributes Name
class(FTMutableObjectArray) :: self
integer :: arraySize

public subroutine destructObjectArray(self)

Destructor for the class. This is called automatically when the reference count reaches zero. Do not call this yourself.

Arguments

Type IntentOptional Attributes Name
class(FTMutableObjectArray) :: self

public subroutine releaseFTMutableObjectArray(self)

Public, generic name: release(self)

Read more…

Arguments

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

public subroutine addObjectToArray(self, obj)

Add an object to the end of the array

Read more…

Arguments

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

public subroutine removeObjectAtIndex(self, indx)

Remove an object at the index indx

Read more…

Arguments

Type IntentOptional Attributes Name
class(FTMutableObjectArray) :: self
integer :: indx

public subroutine replaceObjectAtIndexWithObject(self, indx, replacement)

Replace an object at the index indx

Read more…

Arguments

Type IntentOptional Attributes Name
class(FTMutableObjectArray) :: self
integer :: indx
class(FTObject), POINTER :: replacement

public subroutine printArray(self, iUnit)

Arguments

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

public subroutine setChunkSize(self, chunkSize)

Set the number of items to be added when the array needs to be re-sized

Read more…

Arguments

Type IntentOptional Attributes Name
class(FTMutableObjectArray) :: self
integer :: chunkSize

public subroutine castToMutableObjectArray(obj, cast)

Arguments

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