Skip to content
Snippets Groups Projects
Commit 3e17f701 authored by Florian Prill's avatar Florian Prill
Browse files

removed assign operator and the need for UNINITIALIZED.

parent 9c535070
No related branches found
No related tags found
No related merge requests found
......@@ -53,7 +53,8 @@ MODULE mtime_hl
!> NOTE / TODO:
!
! This "UNINITIALIZED" constant hints at a problem:
! Why does this wrapper module *not* implement the assignment
! operator? - Lenghty answer:
!
! The fundamental question is: Why do our "t_datetime",
! "t_timedelta", "t_xxx" types need assignment operators which
......@@ -81,27 +82,16 @@ MODULE mtime_hl
! of "t_datetime" attempts to create an mtime "datetime" pointer
! based on the uninitializd "tmp_b%dt".
!
! It would be better to drop the "copy assign" implementations in
! libmtime_hl altogether. At least for the basic "datetime",
! "timedelta", "julianday" this is possible, since the data types
! do not contain data members on the heap.
!
! But what can we do for the more complex events? - We can work
! around this problem by defining "uninitialized states" which
! are recognized by the assign operator. Sigh!
!
INTEGER(c_int), PARAMETER :: UNINITIALIZED = -1_c_int
!> Wrapper class for "mtime" data type "datetime".
!
TYPE t_datetime
!private
!> wrapped datatype of the standard mtime interface
TYPE(datetime) :: dt = datetime(date(year=0_c_int64_t, month=UNINITIALIZED, day=0_c_int),&
& time(hour=0_c_int, minute=0_c_int, second=0_c_int, ms=0_c_int))
!private
!> wrapped datatype of the standard mtime interface
TYPE(datetime) :: dt
CONTAINS
! --- conversions
......@@ -126,7 +116,6 @@ MODULE mtime_hl
! --- overloaded operators
PROCEDURE :: assign_t_datetime
PROCEDURE :: add_timedelta => t_datetime_add_timedelta
PROCEDURE :: sub_timedelta => t_datetime_sub_timedelta
PROCEDURE :: sub_datetime => t_datetime_sub_datetime
......@@ -139,7 +128,6 @@ MODULE mtime_hl
PROCEDURE :: get_c_pointer => t_datetime_get_c_pointer
GENERIC :: ASSIGNMENT(=) => assign_t_datetime
GENERIC :: OPERATOR(+) => add_timedelta
GENERIC :: OPERATOR(-) => sub_timedelta
GENERIC :: OPERATOR(-) => sub_datetime
......@@ -165,10 +153,8 @@ MODULE mtime_hl
!private
!> wrapped datatype of the standard mtime interface
TYPE(timedelta) :: td = timedelta( flag_std_form = 0_c_int, sign = '+', year = 0_c_int64_t, &
& month = UNINITIALIZED, day = 0_c_int, hour = 0_c_int, &
& minute = 0_c_int, second = 0_c_int, ms = 0_c_int )
TYPE(timedelta) :: td
CONTAINS
! --- conversions
......@@ -200,7 +186,6 @@ MODULE mtime_hl
! note: the "+", "-" operators are not well-defined for timedelta
! objects!
PROCEDURE :: assign_t_timedelta
PROCEDURE :: equal_datetime => t_timedelta_equal
PROCEDURE :: not_equal_datetime => t_timedelta_not_equal
PROCEDURE :: less_than_datetime => t_timedelta_less_than
......@@ -213,7 +198,6 @@ MODULE mtime_hl
PROCEDURE :: get_c_pointer => t_timedelta_get_c_pointer
GENERIC :: ASSIGNMENT(=) => assign_t_timedelta
GENERIC :: OPERATOR(==) => equal_datetime
GENERIC :: OPERATOR(/=) => not_equal_datetime
GENERIC :: OPERATOR(<) => less_than_datetime
......@@ -421,24 +405,6 @@ CONTAINS
! datetime section:
! ================================================================================
! generic assignment for constructors
!
SUBROUTINE assign_t_datetime(to, from)
CLASS(t_datetime), INTENT(out) :: to
CLASS(t_datetime), INTENT(in) :: from
TYPE(datetime), POINTER :: dt_tmp
INTEGER :: errno
! first, check if "from" is an initialized t_datetime object:
IF (from%dt%date%month /= UNINITIALIZED) THEN
dt_tmp => newdatetime(from%dt, errno)
CALL handle_errno(errno, __FILE__, __LINE__)
to%dt = dt_tmp
CALL deallocatedatetime(dt_tmp)
ELSE
to%dt = from%dt
END IF
END SUBROUTINE assign_t_datetime
! constructor for a datetime string
!
......@@ -652,25 +618,6 @@ CONTAINS
! timedelta section:
! ================================================================================
! generic assignment for constructors
!
SUBROUTINE assign_t_timedelta(to, from)
CLASS(t_timedelta), INTENT(out) :: to
CLASS(t_timedelta), INTENT(in) :: from
TYPE(timedelta), POINTER :: td_tmp
INTEGER :: errno
! first, check if "from" is an initialized t_datetime object:
IF (from%td%month /= UNINITIALIZED) THEN
td_tmp => newTimedelta(from%td, errno)
CALL handle_errno(errno, __FILE__, __LINE__)
to%td = td_tmp
to%td%sign = td_tmp%sign
CALL deallocateTimedelta(td_tmp)
ELSE
to%td = from%td
END IF
END SUBROUTINE assign_t_timedelta
! constructor for timedelta string
!
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment