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 releaseFTMutableObjectArray(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()

Uses

  • module~~ftmutableobjectarrayclass~~UsesGraph module~ftmutableobjectarrayclass FTMutableObjectArrayClass module~ftobjectclass FTObjectClass module~ftmutableobjectarrayclass->module~ftobjectclass

Used by

  • module~~ftmutableobjectarrayclass~~UsedByGraph module~ftmutableobjectarrayclass FTMutableObjectArrayClass module~ftdictionaryclass FTDictionaryClass module~ftdictionaryclass->module~ftmutableobjectarrayclass module~ftlinkedlistclass FTLinkedListClass module~ftdictionaryclass->module~ftlinkedlistclass module~ftlinkedlistiteratorclass FTLinkedListIteratorClass module~ftdictionaryclass->module~ftlinkedlistiteratorclass module~ftlinkedlistclass->module~ftmutableobjectarrayclass module~ftobjectlibrary FTObjectLibrary module~ftobjectlibrary->module~ftmutableobjectarrayclass module~ftobjectlibrary->module~ftdictionaryclass module~ftobjectlibrary->module~ftlinkedlistclass module~ftexceptionclass FTExceptionClass module~ftobjectlibrary->module~ftexceptionclass module~ftobjectlibrary->module~ftlinkedlistiteratorclass module~ftsparsematrixclass FTSparseMatrixClass module~ftobjectlibrary->module~ftsparsematrixclass module~ftstackclass FTStackClass module~ftobjectlibrary->module~ftstackclass module~ftvaluedictionaryclass FTValueDictionaryClass module~ftobjectlibrary->module~ftvaluedictionaryclass module~ftexceptionclass->module~ftdictionaryclass module~ftexceptionclass->module~ftlinkedlistiteratorclass module~ftexceptionclass->module~ftstackclass module~ftexceptionclass->module~ftvaluedictionaryclass module~ftlinkedlistiteratorclass->module~ftlinkedlistclass module~ftmultiindextableclass FTMultiIndexTableClass module~ftmultiindextableclass->module~ftlinkedlistclass module~ftsparsematrixclass->module~ftlinkedlistclass module~ftsparsematrixclass->module~ftlinkedlistiteratorclass module~ftstackclass->module~ftlinkedlistclass module~ftstringsetclass FTStringSetClass module~ftstringsetclass->module~ftdictionaryclass module~ftvaluedictionaryclass->module~ftdictionaryclass module~sharedexceptionmanagermodule SharedExceptionManagerModule module~sharedexceptionmanagermodule->module~ftexceptionclass

Interfaces

public interface cast


Derived Types

type, public, extends(FTObject) ::  FTMutableObjectArray

Finalizations Procedures

final :: destructObjectArray

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 :: 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 releaseFTMutableObjectArray(self)

Arguments

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

public recursive 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
type(FTMutableObjectArray) :: 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