abstract_container_mod Module

module~~abstract_container_mod~~UsesGraph module~abstract_container_mod abstract_container_mod iso_fortran_env iso_fortran_env iso_fortran_env->module~abstract_container_mod
Help

Provides an abstract container derived type which can be used as a sort of unlimited polymorphic entity whose contents are retrievable with type-guards. Different subclasses are created in order to hold different data-types. See container for instructions on creating concrete subclasses. See container_mod for subclasses containing the built-in data-types.

Used By

module~~abstract_container_mod~~UsedByGraph module~abstract_container_mod abstract_container_mod module~iterator_mod iterator_mod module~abstract_container_mod->module~iterator_mod module~container_mod container_mod module~abstract_container_mod->module~container_mod module~array_list_mod array_list_mod module~abstract_container_mod->module~array_list_mod module~iterable_mod iterable_mod module~abstract_container_mod->module~iterable_mod module~map_mod map_mod module~abstract_container_mod->module~map_mod module~dictionary_mod dictionary_mod module~abstract_container_mod->module~dictionary_mod module~node_mod node_mod module~abstract_container_mod->module~node_mod module~list_mod list_mod module~abstract_container_mod->module~list_mod module~ordered_mod ordered_mod module~abstract_container_mod->module~ordered_mod module~dynamic_set_mod dynamic_set_mod module~abstract_container_mod->module~dynamic_set_mod module~deque_mod deque_mod module~abstract_container_mod->module~deque_mod module~data_set_mod data_set_mod module~abstract_container_mod->module~data_set_mod module~iterator_mod->module~array_list_mod module~iterator_mod->module~iterable_mod module~iterator_mod->module~ordered_mod module~array_list_mod->module~dictionary_mod module~array_list_mod->module~data_set_mod module~multimap_mod multimap_mod module~array_list_mod->module~multimap_mod module~iterable_mod->module~ordered_mod module~iterable_mod->module~dynamic_set_mod module~countable_mod countable_mod module~iterable_mod->module~countable_mod module~map_mod->module~multimap_mod module~dictionary_mod->module~map_mod module~dictionary_mod->module~multimap_mod module~linked_node_mod linked_node_mod module~node_mod->module~linked_node_mod module~list_mod->module~array_list_mod module~ordered_mod->module~array_list_mod module~queue_mod queue_mod module~ordered_mod->module~queue_mod module~multiset_mod multiset_mod module~dynamic_set_mod->module~multiset_mod module~deque_mod->module~list_mod module~data_set_mod->module~dictionary_mod module~data_set_mod->module~dynamic_set_mod module~countable_mod->module~ordered_mod module~countable_mod->module~data_set_mod module~bidir_node_mod bidir_node_mod module~linked_node_mod->module~bidir_node_mod module~queue_mod->module~deque_mod
Help

Abstract Interfaces

abstract interface

  • public subroutine action_sub(item)

    Arguments

    Type IntentOptional AttributesName
    class(container), intent(inout) :: item

    A container object which is will be modified in some way

    Description

    An abstract interface for a procedure which will act on each item in a list.

abstract interface

  • private function guard(this, lhs)

    Arguments

    Type IntentOptional AttributesName
    class(container), intent(in) :: this
    class(*), intent(inout) :: lhs

    The variable which the container contents are to be transferred to.

    Return Value logical

abstract interface

  • public pure function test_func(item)

    Arguments

    Type IntentOptional AttributesName
    class(container), intent(in) :: item

    The item which is being evaluated

    Return Value logical

    Whether the item passes the test or not

    Description

    An abstract interface for a function which tests a container object in some way

abstract interface

  • public pure function addition_func(item1, item2)

    Arguments

    Type IntentOptional AttributesName
    class(container), intent(in) :: item1

    One of the items in the addition

    class(container), intent(in) :: item2

    The other item in the addition

    Return Value class(container), allocatable

    The sum, item1 + item2

    Description

    Performs an addition operation on two container objects, returning the result in a container.

abstract interface

  • public pure function subtraction_func(item1, item2)

    Arguments

    Type IntentOptional AttributesName
    class(container), intent(in) :: item1

    The item which the other is subtracted from

    class(container), intent(in) :: item2

    The item subtracted from the other

    Return Value real

    A real number, the absolute value of which represents the magnitude of the difference between item1 and item2.

    Description

    An abstract interface for a procedure finding the difference between two items, item1 - item2. Note that a procedure may satisfy both this abstract interface and comparison_func.

abstract interface

  • public pure function comparison_func(item1, item2)

    Arguments

    Type IntentOptional AttributesName
    class(container), intent(in) :: item1

    The first item in the comparison

    class(container), intent(in) :: item2

    The second item in the comparison

    Return Value real

    negative if item1 < item2, 0 if item1 == item2, positive if item1 > item2

    Description

    An abstract interface for a procedure comparing two container objects. Note that a procedure may satisfy both this abstract interface and subtraction_func.


Derived Types

type, public, abstract :: container

Components

TypeVisibility AttributesNameInitial
integer(kind=i1), private, dimension(:), allocatable:: storage

Variable in which to place data contents

logical, private :: filled =.false.

.true. if container is set, .false. otherwise

Type-Bound Procedures

procedure(guard), private, deferred :: typeguard

Performs the actual transfer of the container's contents to another variable.

procedure, public :: contents

Retrieves the contents of the container, in the form of an integer array.

procedure, public :: is_filled

Returns whether contents have been assigned to the container

procedure, public :: set

Sets the contents of the container.

procedure, private, pass(rhs) :: assign_container

Assigns container contents to another variable.

procedure, private :: is_equal

Check whether two containers have the same contents.

generic, public :: assignment(=) => assign_container
generic, public :: operator(==) => is_equal

Description

An abstract derived type which contains data. This type can be used for a sort of unlimited polymorphism. It is extended to create different classes capable of holding particular data-types. Extensions must implement the procedure typeguard in order to provide the ability to transfer data out of the container and into a variable. Assuming that you are creating a concrete class called example_container, this should be implemented as follows:


Functions

private pure function contents(this)

Arguments

Type IntentOptional AttributesName
class(container), intent(in) :: this

Return Value integer(kind=i1), dimension(:),allocatable

Description

Author
Chris MacMackin
Date
December 2015

Returns the contents, encoded as a character array, of the container.

private elemental function is_filled(this)

Arguments

Type IntentOptional AttributesName
class(container), intent(in) :: this

Return Value logical

Description

Author
Chris MacMackin
Date
March 2016

Returns .true. if a value has been assigned to the container, .false. otherwise.

private elemental function is_equal(lhs, rhs)

Arguments

Type IntentOptional AttributesName
class(container), intent(in) :: lhs
class(container), intent(in) :: rhs

Return Value logical

Description

Author
Chris MacMackin
Date
December 2015

Checks whether two containers are of the same type and are storing the same contents.


Subroutines

private subroutine assign_container(lhs, rhs)

Arguments

Type IntentOptional AttributesName
class(*), intent(inout) :: lhs

The variable which the container contents will be assigned to.

class(container), intent(in) :: rhs

The container variable.

Description

Author
Chris MacMackin
Date
December 2015

Transfers the contents of the container to another variable. If the other variable is another container of the same type then the contents will be transferred. If the other variable is the same type as the contents of the container (as determined by the typeguard routine provided for that concrete type extension) then it will be given the value held by the container. Otherwise, an error message will be printed and the program stopped. If compiled with gfortran then a backtrace will also be printed. In the event that the container was never set to a value, then this also constitutes an error.

private subroutine set(this, content)

Arguments

Type IntentOptional AttributesName
class(container), intent(out) :: this
class(*), intent(in) :: content

The value to be placed in the container

Description

Author
Chris MacMackin
Date
December 2015

Sets the contents of the storage array to value passed. The type of the variable provided must be the same as the container variable is designed to accept (as determined by the concrete type implementation of the typeguard method in the extension) or be of the same type of container. Otherwise an error message will be printed and the program will exit. If gfortran was used to compile then a backtrace will also be printed.