Skip to content

Commit 844d29e

Browse files
committed
Playing around
1 parent 300694f commit 844d29e

2 files changed

Lines changed: 45 additions & 6 deletions

File tree

src/example_fgen_basic/result/result.f90

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
!> https://github.com/samharrison7/fortran-error-handler
55
module m_result
66

7-
use m_error_v, only: ErrorV
7+
use m_error_v, only: ErrorV, NO_ERROR_CODE
88

99
implicit none
1010
private
@@ -40,10 +40,10 @@ module m_result
4040

4141
end type Result
4242

43-
interface Result
43+
! interface Result
4444
!! Constructor interface - see build (TODO: figure out cross-ref syntax) for details
45-
module procedure :: constructor
46-
end interface Result
45+
! module procedure :: constructor
46+
! end interface Result
4747

4848
contains
4949

@@ -71,6 +71,26 @@ module m_result
7171
!
7272
! end subroutine build
7373

74+
!subroutine constructor(self, code, message)
75+
! !! Build instance
76+
!
77+
! class(*), allocatable :: data_v(..)
78+
! class(ErrorV), intent(inout) :: self
79+
! ! Hopefully can leave without docstring (like Python)
80+
! integer, intent(in) :: code = NO_ERROR_CODE
81+
! !! Error code
82+
! !!
83+
! !! Use [TODO: figure out xref] `NO_ERROR_CODE` if there is no error
84+
! character(len=*), optional, intent(in) :: message = ""
85+
! !! Error message
86+
!
87+
! self % code = code
88+
! if (present(message)) then
89+
! self % message = message
90+
! end if
91+
!
92+
!end subroutine constructor
93+
7494
function finalise(self) result(res)
7595
!! Finalise the instance (i.e. free/deallocate)
7696

src/example_fgen_basic/result/result_int.f90

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,25 @@ module m_result_int
3737

3838
contains
3939

40+
function constructor(res, data_v, error_v) result(self)
41+
!! Build instance
42+
43+
type(ResultInteger), intent(out) :: self
44+
! Hopefully can leave without docstring (like Python)
45+
46+
class(ErrorV), intent(in) :: error_v
47+
!! Error message
48+
49+
integer, optional, intent(in) :: data_v
50+
!! Data
51+
52+
self%error_v = ErrorV()
53+
54+
if (present(error_v)) self%error_v = error_v
55+
if (present(data_v)) self%data_v = data_v
56+
57+
end function constructor
58+
4059
subroutine build(self, res, data_v, error_v)
4160
!! Build instance
4261

@@ -49,11 +68,11 @@ subroutine build(self, res, data_v, error_v)
4968
integer, optional, intent(in) :: data_v
5069
!! Data
5170

52-
res = Result()
53-
5471
class(ErrorV), optional, intent(in) :: error_v
5572
!! Error message
5673

74+
res = Result()
75+
5776
if (present(data_v) and present(error_v)) then
5877
call res % build(message="Both data and error were provided")
5978
elseif (present(data_v)) then

0 commit comments

Comments
 (0)