-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathobject_class.f90
78 lines (51 loc) · 2.11 KB
/
object_class.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
!=====================================================================!
! Module containing Object type which is the topmost in hierarchy.
!
! Author: Komahan Boopathy (komahan@gatech.edu)
!=====================================================================!
module object_class
implicit none
private
public :: object
!-------------------------------------------------------------------!
! Type definition
!-------------------------------------------------------------------!
type :: object
contains
procedure :: equals
procedure :: hashcode
procedure :: print
end type object
!-------------------------------------------------------------------!
! Constructor function for type
!-------------------------------------------------------------------!
!!$ interface object
!!$ module procedure create_object
!!$ end interface object
contains
!===================================================================!
! Returns if the supplied instance is equal to the instance on which
! this method is invoked.
!===================================================================!
type(logical) function equals(this, element)
class(object) , intent(in) :: this
class(*) , intent(in) :: element
! objects are equal only if they are coexistant in space-time
equals = loc(element) .eq. loc(this)
end function equals
!===================================================================!
! Returns the unique hashcode of the object
!===================================================================!
type(integer) function hashcode(this)
class(object), intent(in) :: this
! Return the memory address as hashcode
hashcode = loc(this)
end function hashcode
!===================================================================!
! Returns the string representation of the object
!===================================================================!
subroutine print(this)
class(object), intent(in) :: this
print *, "object@", this % hashcode()
end subroutine print
end module object_class