Skip to content

Commit

Permalink
Add missing comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Manangka committed Apr 9, 2024
1 parent 9d4be1c commit b53ca71
Show file tree
Hide file tree
Showing 8 changed files with 198 additions and 64 deletions.
33 changes: 16 additions & 17 deletions src/Utilities/KeyValueList.f90
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module KeyValueListModule
public :: KeyValueNodeType

!> @brief A key-value pair node
!!
!!
!<
type KeyValueNodeType
type(KeyValueNodeType), allocatable :: next !< the next node
Expand All @@ -16,9 +16,8 @@ module KeyValueListModule
end type KeyValueNodeType

!> @brief A list that stores items as a key-value pair
!!
!! Items in this list can be retrieved by using either an
!! index or a key.
!!
!! Items in this list can be retrieved by using a key.
!<
type KeyValueListType
type(KeyValueNodeType), allocatable :: first !< first item in the list
Expand All @@ -33,7 +32,7 @@ module KeyValueListModule

interface
!> @brief Function signature tho which a find_node predicate should adhere
!!
!!
!<
function predicate(node, index, arg) result(res)
import KeyValueNodeType, I4B
Expand All @@ -47,7 +46,7 @@ function predicate(node, index, arg) result(res)
contains

!> @brief Add a key-value pair to the list
!!
!!
!<
subroutine add(this, key, value)
! -- dummy
Expand Down Expand Up @@ -75,8 +74,8 @@ subroutine add(this, key, value)
end subroutine add

!> @brief Get a value using a key
!!
!! If the key can't be found the return value will be a null pointer
!!
!! If the key can't be found the return value will be a null pointer
!<
function get(this, key) result(value)
! -- dummy
Expand All @@ -98,8 +97,8 @@ function get(this, key) result(value)
end function

!> @brief Find a node in the list fullfilling a predicate.
!!
!! If the key can't be found the return value will be a null pointer
!!
!! If the key can't be found the return value will be a null pointer
!<
function find_node(this, predFunc, arg) result(res)
! -- dummy
Expand All @@ -124,7 +123,7 @@ function find_node(this, predFunc, arg) result(res)
end function

!> @brief The nummer of items in the list
!!
!!
!<
function count(this) result(val)
! -- dummy
Expand All @@ -135,8 +134,8 @@ function count(this) result(val)
end function

!> @brief Clears the list
!!
!! clears all the node of the list
!!
!! clears all the node of the list
!<
subroutine clear(this)
! -- dummy
Expand All @@ -148,8 +147,8 @@ subroutine clear(this)
end subroutine

!> @brief Clears the node
!!
!! Recursive method that clears the next node before clearing itself
!!
!! Recursive method that clears the next node before clearing itself
!<
recursive subroutine clear_node(node)
! -- dummy
Expand All @@ -163,7 +162,7 @@ recursive subroutine clear_node(node)
end subroutine clear_node

!> @brief Predicate that checks if the current node is the last node of the list
!!
!!
!<
function last_node_predicate(node, index, arg) result(res)
! -- dummy
Expand All @@ -176,7 +175,7 @@ function last_node_predicate(node, index, arg) result(res)
end function

!> @brief Predicate that checks if the key of the current node equals the provided key
!!
!!
!<
function macthing_key_predicate(node, index, arg) result(res)
! -- dummy
Expand Down
26 changes: 23 additions & 3 deletions src/Utilities/KeyValueListIterator.f90
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ module KeyValueListIteratorModule
use KindModule, only: I4B
use KeyValueListModule, only: KeyValueListType, KeyValueNodeType

!> @brief An iterator used to iterate throuh a KeyValueList
!!
!<
type :: KeyValueListIteratorType
type(KeyValueListType), pointer :: container
type(KeyValueNodeType), pointer :: current_node
type(KeyValueListType), pointer :: container !< the KeyValueList to iterate through
type(KeyValueNodeType), pointer :: current_node !< the current node in the list the iterator is pointing to
contains
procedure :: has_next
procedure :: next
Expand All @@ -17,16 +20,24 @@ module KeyValueListIteratorModule

contains

!> @brief Constructor to create a KeyValueListIterator
!!
!<
function Constructor(container) Result(iterator)
type(KeyValueListIteratorType) :: iterator
! -- dummy
type(KeyValueListType), target :: container
type(KeyValueListIteratorType) :: iterator

iterator%container => container
iterator%current_node => null()

end function Constructor

!> @brief Indicates if there is a next node in the iteration chain
!!
!<
function has_next(this) result(res)
! -- dummy
class(KeyValueListIteratorType) :: this
type(logical) :: res

Expand All @@ -38,16 +49,25 @@ function has_next(this) result(res)

end function

!> @brief Forward the iterator to the next node
!!
!<
subroutine next(this)
! -- dummy
class(KeyValueListIteratorType) :: this

if (associated(this%current_node)) then
this%current_node => this%current_node%next
else
this%current_node => this%container%first
end if
end subroutine

!> @brief Get the value the iterator is pointing to
!!
!<
function value(this) result(res)
! -- dummy
class(KeyValueListIteratorType) :: this
class(*), pointer :: res

Expand Down
32 changes: 28 additions & 4 deletions src/Utilities/Memory/Memory.f90
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,17 @@ function mt_associated(this) result(al)
if (associated(this%acharstr1d)) al = .true.
end function mt_associated

!> @brief Check if the MemoryType is associated to pointer
!!
!<
function mt_ptr_sclr_associated(this, ptr) result(al)
! -- dummy
class(MemoryType) :: this
class(*), pointer :: ptr
class(*), pointer :: mem
logical :: al
! -- local
class(*), pointer :: mem

al = .false.
mem => this%strsclr
if (associated(mem, ptr)) al = .true.
Expand All @@ -124,11 +130,17 @@ function mt_ptr_sclr_associated(this, ptr) result(al)
if (associated(mem, ptr)) al = .true.
end function mt_ptr_sclr_associated

!> @brief Check if the MemoryType is associated to pointer
!!
!<
function mt_ptr_1d_associated(this, ptr) result(al)
! -- dummy
class(MemoryType) :: this
class(*), pointer :: ptr(:)
class(*), pointer :: mem(:)
logical :: al
! -- local
class(*), pointer :: mem(:)

al = .false.
mem => this%astr1d
if (associated(mem, ptr)) al = .true.
Expand All @@ -140,11 +152,17 @@ function mt_ptr_1d_associated(this, ptr) result(al)
if (associated(mem, ptr)) al = .true.
end function mt_ptr_1d_associated

!> @brief Check if the MemoryType is associated to pointer
!!
!<
function mt_ptr_2d_associated(this, ptr) result(al)
! -- dummy
class(MemoryType) :: this
class(*), pointer :: ptr(:, :)
class(*), pointer :: mem(:, :)
logical :: al
! -- local
class(*), pointer :: mem(:, :)

al = .false.

mem => this%aint2d
Expand All @@ -153,11 +171,17 @@ function mt_ptr_2d_associated(this, ptr) result(al)
if (associated(mem, ptr)) al = .true.
end function mt_ptr_2d_associated

!> @brief Check if the MemoryType is associated to pointer
!!
!<
function mt_ptr_3d_associated(this, ptr) result(al)
! -- dummy
class(MemoryType) :: this
class(*), pointer :: ptr(:, :, :)
class(*), pointer :: mem(:, :, :)
logical :: al
! -- local
class(*), pointer :: mem(:, :, :)

al = .false.

mem => this%aint3d
Expand Down
26 changes: 13 additions & 13 deletions src/Utilities/Memory/MemoryHashTable.f90
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@ module MemoryHashTableModule
public :: MemoryHashTableType

!> @brief HashTable that stores MemoryType items.
!!
!! The key used for storing the MemoryType is constructed
!! by concatenating the memory path and memory name.
!!
!! The key used for storing the MemoryType is constructed
!! by concatenating the memory path and memory name.
!<
type :: MemoryHashTableType
type(PtrHashTableType) :: hash_table !< the HashTable
contains
procedure :: add
procedure :: get_by_path
procedure :: get
procedure :: count
procedure :: clear
end type MemoryHashTableType

contains
!> @brief Add a MemoryType to the HashTable
!!
!!
!<
subroutine add(this, mt)
! -- dummy
Expand All @@ -42,12 +42,12 @@ subroutine add(this, mt)
end subroutine add

!> @brief Get a MemoryType from the HashTable using a key
!!
!! The name and mem_path are used to contruct the key for the lookup.
!! Function returns a MemoryType pointer if the key is found.
!! If the key is not found a null pointer is returned.
!!
!! The name and mem_path are used to contruct the key for the lookup.
!! Function returns a MemoryType pointer if the key is found.
!! If the key is not found a null pointer is returned.
!<
function get_by_path(this, name, mem_path) result(res)
function get(this, name, mem_path) result(res)
! -- dummy
class(MemoryHashTableType) :: this
character(len=*) :: name !< variable name
Expand All @@ -66,10 +66,10 @@ function get_by_path(this, name, mem_path) result(res)
res => obj
end select

end function get_by_path
end function get

!> @brief The nummer of items in the HashTable
!!
!!
!<
function count(this) result(res)
! -- dummy
Expand All @@ -81,7 +81,7 @@ function count(this) result(res)
end function count

!> @brief Clears the HashTable
!!
!!
!<
subroutine clear(this)
class(MemoryHashTableType) :: this
Expand Down
22 changes: 21 additions & 1 deletion src/Utilities/Memory/MemoryHashTableIterator.f90
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ module MemoryHashTableIteratorModule

public :: MemoryHashTableIteratorType

!> @brief An iterator used to iterate throuh a MemoryHashTable
!!
!<
type :: MemoryHashTableIteratorType
type(PtrHashTableIteratorType) :: hashtable_iterator
type(PtrHashTableIteratorType) :: hashtable_iterator !< the current iterator to the underlaying hastable
contains
procedure :: has_next
procedure :: next
Expand All @@ -22,30 +25,47 @@ module MemoryHashTableIteratorModule
end interface MemoryHashTableIteratorType

contains
!> @brief Constructor to create a MemoryHashTableIterator
!!
!<
function Constructor(container) Result(iterator)
! -- dummy
type(MemoryHashTableIteratorType) :: iterator
type(MemoryHashTableType), target :: container

iterator%hashtable_iterator = PtrHashTableIteratorType(container%hash_table)

end function Constructor

!> @brief Indicates if there is a next node in the iteration chain
!!
!<
function has_next(this) result(res)
! -- dummy
class(MemoryHashTableIteratorType) :: this
type(logical) :: res

res = this%hashtable_iterator%has_next()
end function

!> @brief Forward the iterator to the next node
!!
!<
subroutine next(this)
! -- dummy
class(MemoryHashTableIteratorType) :: this

call this%hashtable_iterator%next()
end subroutine

!> @brief Get the value the iterator is pointing to
!!
!<
function value(this) result(res)
! -- dummy
class(MemoryHashTableIteratorType), target :: this
type(MemoryType), pointer :: res
! -- local
class(*), pointer :: obj !< void pointer to MemoryType

obj => this%hashtable_iterator%value()
Expand Down
Loading

0 comments on commit b53ca71

Please sign in to comment.