collections 1.0.0
COLLECTIONS is a library providing a set of types supporting collections in Fortran.
Loading...
Searching...
No Matches
collections::list Type Reference

Defines a generic, dynamically sizable list. More...

Public Member Functions

procedure, public count => list_get_count
 Gets the number of items stored in the list. More...
 
procedure, public get_capacity => list_get_capacity
 Gets the capacity of the list. More...
 
procedure, public set_capacity => list_set_capacity
 Sets the capacity of the list. More...
 
procedure, public push => list_push
 Pushes an item onto the back of the list. More...
 
procedure, public pop => list_pop
 Pops the last item off the back of the list. More...
 
procedure, public get => list_get
 Gets the requested item from the list. More...
 
procedure, public set => list_set
 Sets the specified item into the list. More...
 
procedure, public insert => list_insert
 Inserts an item into the list. More...
 
procedure, public remove => list_remove
 Removes an item from the list. More...
 
procedure, public clear => list_clear
 Clears the entire list. More...
 

Detailed Description

Defines a generic, dynamically sizable list.

Example
The following example illustrates basic usage of the list.
program list_example
use iso_fortran_env
implicit none
! Variables
integer(int32), parameter :: n = 10
integer(int32) :: i
type(list) :: x
class(*), pointer :: ptr
! Create a list
do i = 1, n
call x%push(2 * i)
end do
! Print it out to the command line
print '(A)', "***** Original List *****"
do i = 1, n
ptr => x%get(i)
! The list uses unlimited polymorphic types; therefore, we need to
! use the select type construct.
select type (ptr)
type is (integer(int32))
print *, ptr
end select
end do
! Insert the integer value of 100 into the 5th slot in the list
call x%insert(5, 100)
! Print it out again to illustrate the change
print '(A)', new_line('a') // "***** After Insertion *****"
do i = 1, x%count()
ptr => x%get(i)
select type (ptr)
type is (integer(int32))
print *, ptr
end select
end do
end program
A module containing various collections using Fortran's unlimited polymorphic functionallity.
Definition: collections.f90:93
The above program generates the following output.
***** Original List *****
2
4
6
8
10
12
14
16
18
20
***** After Insertion *****
2
4
6
8
100
10
12
14
16
18
20

Definition at line 259 of file collections.f90.

Member Function/Subroutine Documentation

◆ clear()

procedure, public collections::list::clear

Clears the entire list.

Syntax
subroutine clear(class(list) this)
Parameters
[in,out]thisThe list object.

Definition at line 432 of file collections.f90.

◆ count()

procedure, public collections::list::count

Gets the number of items stored in the list.

Syntax
integer(int32) get_count(class(list) this)
Parameters
[in]thisThe list object.
Returns
The number of items stored in the list.

Definition at line 274 of file collections.f90.

◆ get()

procedure, public collections::list::get

Gets the requested item from the list.

Syntax
class(*) pointer function get(class(list) this, integer(int32) i, optional class(errors) err)
Parameters
[in]thisThe list object.
[in]iThe one-based index of the item to retrieve.
[in,out]errAn optional output that can be used to track the error status of the routine. Possible error codes are as follows.
  • FL_NO_ERROR: No error.
  • FL_INDEX_OUT_OF_RANGE_ERROR: The index parameter i is outside the bounds of the list.
Returns
A pointer to the requested object.

Definition at line 356 of file collections.f90.

◆ get_capacity()

procedure, public collections::list::get_capacity

Gets the capacity of the list.

Syntax
integer(int32) get_capacity(class(list) this)
Parameters
[in]thisThe list object.
Returns
The capacity of the list.
Remarks
The capacity is the available "space" in the collection for adding additional items without resizing the internal data store. This capacity includes the currently utilized space. To obtain a count of the actual number of items stored in the list use the count routine.

Definition at line 291 of file collections.f90.

◆ insert()

procedure, public collections::list::insert

Inserts an item into the list.

Syntax
subroutine insert(class(list) this, integer(int32) i, class(*) x, optional logical manage, optional class(errors) err)
Parameters
[in,out]thisThe list object.
[in]iThe one-based index defining where to put the item.
[in]xThe object to store.
[in]manageAn optional input used to determine if the list should manage memory for this object. If set to true a clone of x is stored and the list will handle management of resources held by the clone. If false, the list will not manage resources held by x and x itself will be stored. Notice, in this manner it is possible for x to go out of scope while the list still persists thereby resulting in a potentially undefined behavior. It is recommended to use the default value of true except for very specific and well controlled edge cases.
[in,out]errAn optional output that can be used to track the error status of the routine. Possible error codes are as follows.
  • FL_NO_ERROR: No error.
  • FL_INDEX_OUT_OF_RANGE_ERROR: The index parameter i is outside the bounds of the list.
  • FL_OUT_OF_MEMORY_ERROR: Memory allocation error.

Definition at line 408 of file collections.f90.

◆ pop()

procedure, public collections::list::pop

Pops the last item off the back of the list.

Syntax
subroutine pop(class(list) this)
Parameters
[in,out]thisThe list object.

Definition at line 339 of file collections.f90.

◆ push()

procedure, public collections::list::push

Pushes an item onto the back of the list.

Syntax
subroutine push(class(list) this, class(*) x, optional logical manage, optional class(errors) err)
Parameters
[in,out]thisThe list object.
[in]xThe object to store.
[in]manageAn optional input used to determine if the list should manage memory for this object. If set to true a clone of x is stored and the list will handle management of resources held by the clone. If false, the list will not manage resources held by x and x itself will be stored. Notice, in this manner it is possible for x to go out of scope while the list still persists thereby resulting in a potentially undefined behavior. It is recommended to use the default value of true except for very specific and well controlled edge cases.
[in,out]errAn optional output that can be used to track the error status of the routine. Possible error codes are as follows.
  • FL_NO_ERROR: No error.
  • otherwise: Memory allocation error.

Definition at line 330 of file collections.f90.

◆ remove()

procedure, public collections::list::remove

Removes an item from the list.

Syntax
subroutine remove(class(list) this, integer(int32) i, optional class(errors) err)
Parameters
[in,out]thisThe list object.
[in]iThe one-based index defining which item to remove.
[in,out]errAn optional output that can be used to track the error status of the routine. Possible error codes are as follows.
  • FL_NO_ERROR: No error.
  • FL_INDEX_OUT_OF_RANGE_ERROR: The index parameter i is outside the bounds of the list.

Definition at line 423 of file collections.f90.

◆ set()

procedure, public collections::list::set

Sets the specified item into the list.

Syntax
subroutine set(class(list) this, integer(int32) i, class(*) x, optional logical manage, optional class(errors) err))
Parameters
[in,out]thisThe list object.
[in]iThe one-based index defining where to put the item.
[in]xThe object to store.
[in]manageAn optional input used to determine if the list should manage memory for this object. If set to true a clone of x is stored and the list will handle management of resources held by the clone. If false, the list will not manage resources held by x and x itself will be stored. Notice, in this manner it is possible for x to go out of scope while the list still persists thereby resulting in a potentially undefined behavior. It is recommended to use the default value of true except for very specific and well controlled edge cases.
[in,out]errAn optional output that can be used to track the error status of the routine. Possible error codes are as follows.
  • FL_NO_ERROR: No error.
  • FL_INDEX_OUT_OF_RANGE_ERROR: The index parameter i is outside the bounds of the list.
  • FL_OUT_OF_MEMORY_ERROR: Memory allocation error.

Definition at line 382 of file collections.f90.

◆ set_capacity()

procedure, public collections::list::set_capacity

Sets the capacity of the list.

Syntax
subroutine set_capacity(class(list) this, integer(int32) n, optional class(errors) err)
Parameters
[in,out]thisThe list object.
[in]nThe new capacity of the list. This value must be greater than or equal to 1.
[in,out]errAn optional output that can be used to track the error status of the routine. Possible error codes are as follows.
  • FL_NO_ERROR: No error.
  • FL_INVALID_ARGUMENT_ERROR: Invalid value for n.
  • FL_OUT_OF_MEMORY_ERROR: Memory allocation error.

Definition at line 307 of file collections.f90.


The documentation for this type was generated from the following file: