11module ParticleEventsModule
22 use KindModule, only: DP, I4B, LGP
3+ use ListModule, only: ListType
34 use ParticleModule, only: ParticleType
45 use ParticleEventModule, only: ParticleEventType, &
56 ReleaseEventType, &
@@ -18,10 +19,9 @@ module ParticleEventsModule
1819 end type ParticleEventConsumerType
1920
2021 type, public :: ParticleEventDispatcherType
21- class(ParticleEventConsumerType), pointer :: consumer = > null ()
22+ type (ListType) :: consumers
2223 contains
2324 procedure , public :: subscribe
24- procedure , public :: unsubscribe
2525 procedure , public :: dispatch
2626 procedure :: destroy
2727 end type ParticleEventDispatcherType
@@ -40,18 +40,11 @@ end subroutine handle_event
4040 subroutine subscribe (this , consumer )
4141 class(ParticleEventDispatcherType), intent (inout ) :: this
4242 class(ParticleEventConsumerType), target , intent (inout ) :: consumer
43- this% consumer = > consumer
43+ class(* ), pointer :: p
44+ p = > consumer
45+ call this% consumers% Add(p)
4446 end subroutine subscribe
4547
46- ! > @brief Unsubscribe the consumer from the dispatcher.
47- subroutine unsubscribe (this )
48- class(ParticleEventDispatcherType), intent (inout ) :: this
49- if (associated (this% consumer)) then
50- deallocate (this% consumer)
51- this% consumer = > null ()
52- end if
53- end subroutine unsubscribe
54-
5548 ! > @brief Dispatch an event.
5649 subroutine dispatch (this , particle , event )
5750 use TdisModule, only: kper, kstp, totimc
@@ -60,7 +53,8 @@ subroutine dispatch(this, particle, event)
6053 type (ParticleType), pointer , intent (inout ) :: particle
6154 class(ParticleEventType), pointer , intent (inout ) :: event
6255 ! local
63- integer (I4B) :: per, stp
56+ integer (I4B) :: i, per, stp
57+ class(* ), pointer :: p
6458
6559 ! If tracking time falls exactly on a boundary between time steps,
6660 ! report the previous time step for this datum. This is to follow
@@ -90,14 +84,21 @@ subroutine dispatch(this, particle, event)
9084 event% ttrack = particle% ttrack
9185 event% istatus = particle% istatus
9286 call particle% get_model_coords(event% x, event% y, event% z)
93- call this% consumer% handle_event(particle, event)
87+
88+ do i = 1 , this% consumers% Count ()
89+ p = > this% consumers% GetItem(i)
90+ select type (consumer = > p)
91+ class is (ParticleEventConsumerType)
92+ call consumer% handle_event(particle, event)
93+ end select
94+ end do
9495 deallocate (event)
9596 end subroutine dispatch
9697
9798 ! > @brief Destroy the dispatcher.
9899 subroutine destroy (this )
99100 class(ParticleEventDispatcherType), intent (inout ) :: this
100- if ( associated ( this% consumer)) deallocate (this % consumer )
101+ call this% consumers % Clear( )
101102 end subroutine destroy
102103
103104end module ParticleEventsModule
0 commit comments