libsim Versione 7.2.6
arrayof_pre.F90
1! This universal template can be used to wrap any derived type into a
2! derived type defining a 1-dimensional array of the original type;
3! this array can be dynamically extended or shortened by adding or
4! removing elements at an arbitrary position through the ::insert and
5! ::remove methods. All the allocations, deallocations, copy
6! operations are taken care of in the present module; the user can
7! also call the ::packarray method in order to reduce the memory
8! occupation of the object or the ::delete method in order to delete
9! all the data and release all the memory. Before use, any object of
10! the array type should be initialised through the constructor
11! ARRAYOF_TYPE_new:: .
12!
13! The template requires the definition of the following preprocessor macros
14! before being included:
15! - \c ARRAYOF_ORIGTYPE the type to be wrapped
16! - \c ARRAYOF_TYPE the name of the "arrayed" derived type, containing a 1-d array of ARRAYOF_ORIGTYPE, if undefined it will be \a arrayof_ARRAYOF_ORIGTYPE
17! - \c ARRAYOF_ORIGDESTRUCTOR(x) the instruction required in order to "destroy" an object of \c ARRAYOF_ORIGTYPE when the ::remove method is called, optional, if undefined no destructor is called
18! - \c ARRAYOF_ORIGEQ to be defined if ARRAYOF_ORIGTYPE supports the == operator, in that case the *_unique method are defined for the array
19! - \c ARRAYOF_PRIVATE to be defined if the array type is not going to be PUBLIC
20!
21! The template comes in 2 parts, one to be included in the
22! declaration part of the module (before \c CONTAINS) and the second
23! in the execution part of it (after \c CONTAINS).
24#ifndef ARRAYOF_TYPE
25#define ARRAYOF_TYPE arrayof_/**/ARRAYOF_ORIGTYPE
26#endif
27
28!> Derived type defining a dynamically extensible array of ARRAYOF_ORIGTYPE elements
29TYPE arrayof_type
30 arrayof_origtype, POINTER :: array(:)=>null() !< array of ARRAYOF_ORIGTYPE
31 INTEGER :: arraysize=0 !< current logical size of the array; it may be different from the physical size \c SIZE(this%array), and it should be used instead of \c SIZE() intrinsic function in order to evaluate the number of elements assigned to \a array
32!> overallocation factor, values close to 1 determine more calls to the system alloc function (decreased performances)
33!!at the advantage of less memory consumption, the default is 2; the results are not affected by the value of this member
34 DOUBLE PRECISION :: overalloc=2.0d0
35END TYPE arrayof_type
36
37!> Method for inserting elements of the array at a desired position.
38!! If necessary, the array is reallocated to accomodate the new elements.
39INTERFACE insert
40 MODULE PROCEDURE arrayof_type/**/_insert, arrayof_type/**/_insert_array
41END INTERFACE
42
43!> Quick method to append an element to the array.
44!! The return value is the position at which the element has been
45!! appended.
46!! \param TYPE(ARRAYOF_TYPE)::this array object to extend
47!! \param ARRAYOF_ORIGTYPE,INTENT(in)::content object of \a TYPE ARRAYOF_ORIGTYPE to append
48INTERFACE append
49 MODULE PROCEDURE arrayof_type/**/_append
50END INTERFACE
51
52!> Method for removing elements of the array at a desired position.
53!! If necessary, the array is reallocated to reduce space.
54INTERFACE remove
55 MODULE PROCEDURE arrayof_type/**/_remove
56END INTERFACE
57
58!> Destructor for finalizing an array object. If defined, calls the
59!! destructor for every element of the array object;
60!! finally it deallocates all the space occupied.
61INTERFACE delete
62 MODULE PROCEDURE arrayof_type/**/_delete
63END INTERFACE
64
65!> Method for packing the array object reducing at a minimum
66!! the memory occupation, without destroying its contents.
67!! The value of this::overalloc remains unchanged.
68!! After the call to the method, the object can continue to be used,
69!! extended and shortened as before. If the object is empty the array
70!! is allocated to zero length.
71INTERFACE packarray
72 MODULE PROCEDURE arrayof_type/**/_packarray
73END INTERFACE
74
75#ifndef ARRAYOF_PRIVATE
76PUBLIC arrayof_type
77#endif
78
79PRIVATE arrayof_type/**/_alloc, &
80 arrayof_type/**/_insert, arrayof_type/**/_insert_array, &
81 arrayof_type/**/_append, arrayof_type/**/_remove, &
82 arrayof_type/**/_delete, &
83 arrayof_type/**/_packarray
84
85!PUBLIC insert, append, remove, delete, packarray
86
87#ifdef ARRAYOF_ORIGEQ
88INTERFACE insert_unique
89 MODULE PROCEDURE arrayof_type/**/_insert_unique
90END INTERFACE
91
92INTERFACE append_unique
93 MODULE PROCEDURE arrayof_type/**/_append_unique
94END INTERFACE
95
96#ifdef ARRAYOF_ORIGGT
97INTERFACE insert_sorted
98 MODULE PROCEDURE arrayof_type/**/_insert_sorted
99END INTERFACE insert_sorted
100
101PRIVATE arrayof_type/**/_insert_sorted
102#endif
103
104PRIVATE arrayof_type/**/_insert_unique, arrayof_type/**/_append_unique
105
106!PUBLIC insert_unique, append_unique
107#endif
108

Generated with Doxygen.