libsim Versione 7.2.6
list_integer.F03
1!> \brief class to use lists in fortran 2003.
2!!
3!! Linked data structure is a data structure which
4!! consists of a set of data records (nodes) linked together and organized by references .
5!!
6!! A doubly-linked list is a linked data structure that consists of a set
7!! of sequentially linked records called nodes. Each node contains two
8!! fields, called links, that are references to the previous and to the
9!! next node in the sequence of nodes. The beginning and ending nodes'
10!! previous and next links, respectively, point to some kind of
11!! terminator.
12!!
13!! The program example is the better starting point:
14!!\include example_list.F03
15!!\ingroup base
16!!
17module list_integer
19 private
20 public :: integerlist, toarray_integerl
21
22!> Integer specific implementation of doubly-linked list
23!!
24!! extend list_abstract::list
25 type, extends(list) :: integerlist
26#ifdef DOXYGEN
27 integer::none ! doxigen workaround: if missed do not show procedure
28#endif
29 contains
30! procedure :: addInteger !< add integer in list
31 procedure :: current => currentinteger !< get integer pointed by iterator
32 procedure :: display => displayinteger !< print the integer list
33 procedure :: toarray => toarray_integerl !< convert to array the integer list
34! generic :: add => addInteger
35 end type integerlist
36
37contains
38
39!> Print the integer list
40subroutine displayinteger(this)
41class(integerList),intent(inout) :: this
42
43call this%rewind()
44do while(this%element())
45 print *,"index:",this%currentindex()," value:", this%current()
46 call this%next()
47end do
48end subroutine displayinteger
49
50!!$ subroutine addInteger(this, value)
51!!$ class(integerList) :: thisb
52!!$ integer value
53!!$ class(*), allocatable :: v
54!!$
55!!$ allocate(v,source=value)
56!!$ call this%addvalue(v)
57!!$
58!!$ end subroutine addInteger
59
60!> get integer pointed by iterator
61integer function currentinteger(this)
62class(integerList) :: this
63class(*), pointer :: v
64
65v => this%currentpoli()
66select type(v)
67type is (integer)
68 currentinteger = v
69end select
70end function currentinteger
71
72!> /brief Return an array of integer from list
73function toarray_integerl(this)
74integer,allocatable :: toarray_integerl(:) !< array
75class(integerlist) :: this !< list of integer
76
77integer :: i
78
79allocate (toarray_integerl(this%countelements()))
80
81call this%rewind()
82i=0
83do while(this%element())
84 i=i+1
85 toarray_integerl(i) =this%current()
86 call this%next()
87end do
88end function toarray_integerl
89
90
91end module list_integer
abstract class to use lists in fortran 2003.
class to use lists in fortran 2003.
Abstract implementation of doubly-linked list.
Integer specific implementation of doubly-linked list.

Generated with Doxygen.