Skip to content

Commit

Permalink
consolidating
Browse files Browse the repository at this point in the history
  • Loading branch information
pletzer committed Dec 3, 2024
1 parent a4684a3 commit da25b0c
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 48 deletions.
2 changes: 0 additions & 2 deletions class/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ include_directories(
)

set(LIB_FILES
myclass_mod.f90
test_myclass.f90
)

Expand All @@ -13,7 +12,6 @@ set(HEADER_FILES
add_library(f_oo_myclass ${LIB_FILES})

add_executable(test_myclass test_myclass.f90)
target_link_libraries(test_myclass f_oo_myclass)

add_test(NAME test_myclass
COMMAND test_myclass)
Expand Down
46 changes: 0 additions & 46 deletions class/myclass_mod.f90

This file was deleted.

47 changes: 47 additions & 0 deletions class/test_myclass.f90
Original file line number Diff line number Diff line change
@@ -1,3 +1,50 @@
module myclass_mod

implicit none
type myclass_type
private
! members
integer, allocatable :: arr(:)
contains
! methods
procedure :: set => myclass_set
final :: myclass_del
end type myclass_type

! constructor
interface myclass_type
module procedure myclass_new
end interface

contains

function myclass_new(n) result(this)
implicit none
type(myclass_type) :: this
integer, intent(in) :: n
allocate(this%arr(n))
print *, 'constructor was called'
end function myclass_new

subroutine myclass_set(this, vals)
implicit none
class(myclass_type), intent(inout) :: this
integer :: vals(:)
this%arr = vals
print *, 'set method was called'
end subroutine myclass_set

subroutine myclass_del(this)
implicit none
type(myclass_type), intent(inout) :: this
integer :: ier
! some compilers have already deallocated this%arr
deallocate(this%arr, stat=ier)
print *, 'destructor was called'
end subroutine myclass_del

end module myclass_mod

subroutine test()
use myclass_mod
implicit none
Expand Down

0 comments on commit da25b0c

Please sign in to comment.