MODFLOW 6  version 6.7.0.dev0
USGS Modular Hydrologic Model
MemoryStore.f90
Go to the documentation of this file.
2  use kindmodule, only: i4b
9 
10  private
11  public :: memorystoretype
12 
14  private
15  type(ptrhashtabletype) :: container
16  contains
17  procedure :: iterator
18  procedure :: add
19  procedure :: get
20  procedure :: count
21  procedure :: clear
22  end type memorystoretype
23 
24 contains
25 
26  !> @brief An iterator used to iterate through a MemoryContainer
27  !!
28  !<
29  function iterator(this) result(itr)
30  class(memorystoretype) :: this
31  type(memorycontaineriteratortype) :: itr
32  ! -- local
33  class(iteratortype), allocatable :: container_iterator
34 
35  allocate (container_iterator, source=this%container%iterator())
36  itr = memorycontaineriteratortype(container_iterator)
37  end function
38 
39  !> @brief Add a MemoryType to the container
40  !!
41  !! The MemoryType is stored together with a key for easy lookup
42  !! The key is constructed using the memory type's path and name
43  !<
44  subroutine add(this, mt)
45  class(memorystoretype) :: this
46  type(memorytype), pointer, intent(in) :: mt
47  ! -- local
48  class(*), pointer :: obj => null()
49  character(len=LENMEMADDRESS) :: key
50 
51  key = create_mem_address(mt%path, mt%name)
52  obj => mt
53  call this%container%add(key, obj)
54  end subroutine add
55 
56  !> @brief Get a MemoryType using a key
57  !!
58  !! If the key can't be found the return value will be a null pointer
59  !<
60  function get(this, name, path) result(mt)
61  class(memorystoretype) :: this
62  character(len=*), intent(in) :: name
63  character(len=*), intent(in) :: path
64  type(memorytype), pointer :: mt
65  ! -- local
66  character(len=LENMEMADDRESS) :: key
67  class(*), pointer :: obj
68 
69  key = create_mem_address(path, name)
70  obj => this%container%get(key)
71 
72  select type (obj)
73  type is (memorytype)
74  mt => obj
75  class default
76  mt => null()
77  end select
78 
79  end function get
80 
81  !> @brief The nummer of items in the container
82  !!
83  !<
84  function count(this) result(cnt)
85  class(memorystoretype) :: this
86  integer(I4B) :: cnt
87 
88  cnt = this%container%count()
89  end function count
90 
91  !> @brief Clears the memory container
92  !!
93  !<
94  subroutine clear(this)
95  class(memorystoretype) :: this
96 
97  call this%container%clear()
98  end subroutine clear
99 
100 end module memorystoremodule
This module contains simulation constants.
Definition: Constants.f90:9
integer(i4b), parameter lenmemaddress
maximum length of the full memory address, including variable name
Definition: Constants.f90:31
This module defines variable data types.
Definition: kind.f90:8
character(len=lenmemaddress) function create_mem_address(mem_path, var_name)
returns the address string of the memory object
type(memorycontaineriteratortype) function iterator(this)
An iterator used to iterate through a MemoryContainer.
Definition: MemoryStore.f90:30
subroutine add(this, mt)
Add a MemoryType to the container.
Definition: MemoryStore.f90:45
type(memorytype) function, pointer get(this, name, path)
Get a MemoryType using a key.
Definition: MemoryStore.f90:61
subroutine clear(this)
Clears the memory container.
Definition: MemoryStore.f90:95
integer(i4b) function count(this)
The nummer of items in the container.
Definition: MemoryStore.f90:85
An iterator used to iterate through a MemoryContainer.
HashTable that stores void pointer items.