1
subroutine addref_quadrature_type(object)
2
!!< Increment the reference count of object creating a new reference
4
type(quadrature_type), intent(inout), target :: object
5
integer, save :: id = 0
7
if (associated(object%refcount)) then
8
! Reference count already exists, just increment it.
9
object%refcount%count=object%refcount%count+1
13
object%refcount=>new_refcount("&
14
&quadrature_type", object%name)
15
object%refcount%id = id
18
end subroutine addref_quadrature_type
20
subroutine incref_quadrature_type(object)
21
!!< Increment the reference count of object. If there are no references
23
type(quadrature_type), intent(in), target :: object
24
integer, pointer :: ptr !! Dummy pointer to evade compilers which
25
!! don't understand the rules for intent.
27
if (.not.associated(object%refcount)) then
28
FLAbort ("Attempt to incref quadrature_type "//trim(object%name)//" which has no references")
31
! Reference count already exists, just increment it.
32
ptr=>object%refcount%count
35
end subroutine incref_quadrature_type
37
subroutine decref_quadrature_type(object)
38
!!< Decrement the reference count on object. If the reference count drops
39
!!< to 0 deallocate the refcount as a hint to the calling routine that
40
!!< the object can safely be deallocated.
41
type(quadrature_type), intent(inout) :: object
43
if (.not.associated(object%refcount)) then
44
! No refcount. Just exit
48
object%refcount%count=object%refcount%count-1
50
if (object%refcount%count<=0) then
52
if (object%refcount%count<0) then
53
! Warn for negative reference count
54
ewrite(0,'(a, i0)') "Reference count of &
55
&quadrature_type "//trim(object%name)//&
56
" is ", object%refcount%count
57
FLAbort("that should never happen.")
60
object%refcount%prev%next=>object%refcount%next
61
if (associated(object%refcount%next)) then
62
object%refcount%next%prev=>object%refcount%prev
65
deallocate(object%refcount)
69
end subroutine decref_quadrature_type
71
pure function has_references_quadrature_type(object) result (has_references)
72
!!< Return true if there are any references to object
73
type(quadrature_type), intent(in) :: object
74
logical :: has_references
76
has_references=associated(object%refcount)
78
end function has_references_quadrature_type