MODFLOW 6  version 6.6.0.dev0
USGS Modular Hydrologic Model
KeyValueListIterator.f90
Go to the documentation of this file.
2  use kindmodule, only: i4b
5 
6  !> @brief An iterator used to iterate through a KeyValueList
7  !!
8  !<
10  private
11  type(keyvaluenodetype), pointer :: first_node => null() !< the KeyValueList to iterate through
12  type(keyvaluenodetype), pointer :: current_node => null() !< the current node in the list the iterator is pointing to
13  contains
14  procedure :: has_next
15  procedure :: next
16  procedure :: value
17  end type
18 
19  interface keyvaluelistiteratortype
20  module procedure constructor
21  end interface keyvaluelistiteratortype
22 
23 contains
24 
25  !> @brief Constructor to create a KeyValueListIterator
26  !!
27  !<
28  function constructor(first_node) Result(iterator)
29  type(keyvaluenodetype), pointer, intent(in) :: first_node
30  type(keyvaluelistiteratortype) :: iterator
31 
32  iterator%first_node => first_node
33  iterator%current_node => null()
34 
35  end function constructor
36 
37  !> @brief Indicates if there is a next node in the iteration chain
38  !!
39  !<
40  function has_next(this) result(res)
41  class(keyvaluelistiteratortype) :: this
42  type(logical) :: res
43 
44  if (associated(this%current_node)) then
45  res = associated(this%current_node%next)
46  else
47  res = associated(this%first_node)
48  end if
49 
50  end function
51 
52  !> @brief Increment the iterator to the next node
53  !!
54  !<
55  subroutine next(this)
56  class(keyvaluelistiteratortype) :: this
57 
58  if (associated(this%current_node)) then
59  this%current_node => this%current_node%next
60  else
61  this%current_node => this%first_node
62  end if
63  end subroutine
64 
65  !> @brief Get the value the iterator is pointing at
66  !!
67  !<
68  function value(this) result(res)
69  class(keyvaluelistiteratortype) :: this
70  class(*), pointer :: res
71 
72  if (associated(this%current_node)) then
73  res => this%current_node%value
74  else
75  res => null()
76  end if
77 
78  end function
79 
subroutine next(this)
Increment the iterator to the next node.
class(*) function, pointer value(this)
Get the value the iterator is pointing at.
type(logical) function has_next(this)
Indicates if there is a next node in the iteration chain.
type(keyvaluelistiteratortype) function constructor(first_node)
Constructor to create a KeyValueListIterator.
This module defines variable data types.
Definition: kind.f90:8
An iterator used to iterate through a KeyValueList.