function not needed

This commit is contained in:
Sharan Roongta 2021-03-29 13:47:23 +02:00
parent ecf5639360
commit aa5cd76d33
1 changed files with 154 additions and 191 deletions

View File

@ -20,16 +20,10 @@ module YAML_types
procedure(asFormattedString), deferred :: asFormattedString procedure(asFormattedString), deferred :: asFormattedString
procedure :: & procedure :: &
asScalar => tNode_asScalar asScalar => tNode_asScalar
procedure :: &
isScalar => tNode_isScalar
procedure :: & procedure :: &
asList => tNode_asList asList => tNode_asList
procedure :: &
isList => tNode_isList
procedure :: & procedure :: &
asDict => tNode_asDict asDict => tNode_asDict
procedure :: &
isDict => tNode_isDict
procedure :: & procedure :: &
tNode_get_byIndex => tNode_get_byIndex tNode_get_byIndex => tNode_get_byIndex
procedure :: & procedure :: &
@ -347,57 +341,6 @@ function tNode_asDict(self) result(dict)
end function tNode_asDict end function tNode_asDict
!--------------------------------------------------------------------------------------------------
!> @brief Checks if node is a scalar
!--------------------------------------------------------------------------------------------------
function tNode_isScalar(self) result(scalar)
class(tNode), intent(in), target :: self
logical :: scalar
scalar = .false.
select type(self)
class is(tScalar)
scalar = .true.
end select
end function tNode_isScalar
!--------------------------------------------------------------------------------------------------
!> @brief Checks if node is a list
!--------------------------------------------------------------------------------------------------
function tNode_isList(self) result(list)
class(tNode), intent(in), target :: self
logical :: list
list = .false.
select type(self)
class is(tList)
list = .true.
end select
end function tNode_isList
!--------------------------------------------------------------------------------------------------
!> @brief Checks if node is a dict
!--------------------------------------------------------------------------------------------------
function tNode_isDict(self) result(dict)
class(tNode), intent(in), target :: self
logical :: dict
dict = .false.
select type(self)
class is(tDict)
dict = .true.
end select
end function tNode_isDict
!-------------------------------------------------------------------------------------------------- !--------------------------------------------------------------------------------------------------
!> @brief Access by index !> @brief Access by index
!-------------------------------------------------------------------------------------------------- !--------------------------------------------------------------------------------------------------
@ -411,11 +354,12 @@ function tNode_get_byIndex(self,i) result(node)
class(tItem), pointer :: item class(tItem), pointer :: item
integer :: j integer :: j
if (self%isList()) then select type(self)
self_ => self%asList() class is(tList)
else self_ => self%asList()
call IO_error(706,ext_msg='Expected List') class default
endif call IO_error(706,ext_msg='Expected List')
endselect
item => self_%first item => self_%first
@ -442,12 +386,13 @@ function tNode_get_byIndex_asFloat(self,i) result(nodeAsFloat)
type(tScalar), pointer :: scalar type(tScalar), pointer :: scalar
node => self%get(i) node => self%get(i)
if (node%isScalar()) then select type(node)
scalar => node%asScalar() class is(tScalar)
nodeAsFloat = scalar%asFloat() scalar => node%asScalar()
else nodeAsFloat = scalar%asFloat()
call IO_error(706,ext_msg='Expected Scalar') class default
endif call IO_error(706,ext_msg='Expected Scalar')
end select
end function tNode_get_byIndex_asFloat end function tNode_get_byIndex_asFloat
@ -465,12 +410,13 @@ function tNode_get_byIndex_asInt(self,i) result(nodeAsInt)
type(tScalar), pointer :: scalar type(tScalar), pointer :: scalar
node => self%get(i) node => self%get(i)
if (node%isScalar()) then select type(node)
scalar => node%asScalar() class is(tScalar)
nodeAsInt = scalar%asInt() scalar => node%asScalar()
else nodeAsInt = scalar%asInt()
call IO_error(706,ext_msg='Expected Scalar') class default
endif call IO_error(706,ext_msg='Expected Scalar')
end select
end function tNode_get_byIndex_asInt end function tNode_get_byIndex_asInt
@ -488,12 +434,13 @@ function tNode_get_byIndex_asBool(self,i) result(nodeAsBool)
type(tScalar), pointer :: scalar type(tScalar), pointer :: scalar
node => self%get(i) node => self%get(i)
if (node%isScalar()) then select type(node)
scalar => node%asScalar() class is(tScalar)
nodeAsBool = scalar%asBool() scalar => node%asScalar()
else nodeAsBool = scalar%asBool()
call IO_error(706,ext_msg='Expected Scalar') class default
endif call IO_error(706,ext_msg='Expected Scalar')
endselect
end function tNode_get_byIndex_asBool end function tNode_get_byIndex_asBool
@ -511,12 +458,13 @@ function tNode_get_byIndex_asString(self,i) result(nodeAsString)
type(tScalar), pointer :: scalar type(tScalar), pointer :: scalar
node => self%get(i) node => self%get(i)
if (node%isScalar()) then select type(node)
scalar => node%asScalar() class is(tScalar)
nodeAsString = scalar%asString() scalar => node%asScalar()
else nodeAsString = scalar%asString()
call IO_error(706,ext_msg='Expected Scalar') class default
endif call IO_error(706,ext_msg='Expected Scalar')
endselect
end function tNode_get_byIndex_asString end function tNode_get_byIndex_asString
@ -534,12 +482,13 @@ function tNode_get_byIndex_asFloats(self,i) result(nodeAsFloats)
class(tList), pointer :: list class(tList), pointer :: list
node => self%get(i) node => self%get(i)
if (node%isList()) then select type(node)
list => node%asList() class is(tList)
nodeAsFloats = list%asFloats() list => node%asList()
else nodeAsFloats = list%asFloats()
call IO_error(706,ext_msg='Expected list') class default
endif call IO_error(706,ext_msg='Expected list')
endselect
end function tNode_get_byIndex_asFloats end function tNode_get_byIndex_asFloats
@ -557,12 +506,13 @@ function tNode_get_byIndex_asInts(self,i) result(nodeAsInts)
class(tList), pointer :: list class(tList), pointer :: list
node => self%get(i) node => self%get(i)
if (node%isList()) then select type(node)
list => node%asList() class is(tList)
nodeAsInts = list%asInts() list => node%asList()
else nodeAsInts = list%asInts()
call IO_error(706,ext_msg='Expected list') class default
endif call IO_error(706,ext_msg='Expected list')
endselect
end function tNode_get_byIndex_asInts end function tNode_get_byIndex_asInts
@ -580,12 +530,13 @@ function tNode_get_byIndex_asBools(self,i) result(nodeAsBools)
class(tList), pointer :: list class(tList), pointer :: list
node => self%get(i) node => self%get(i)
if (node%isList()) then select type(node)
list => node%asList() class is(tList)
nodeAsBools = list%asBools() list => node%asList()
else nodeAsBools = list%asBools()
call IO_error(706,ext_msg='Expected list') class default
endif call IO_error(706,ext_msg='Expected list')
endselect
end function tNode_get_byIndex_asBools end function tNode_get_byIndex_asBools
@ -603,12 +554,13 @@ function tNode_get_byIndex_asStrings(self,i) result(nodeAsStrings)
type(tList), pointer :: list type(tList), pointer :: list
node => self%get(i) node => self%get(i)
if (node%isList()) then select type(node)
list => node%asList() class is(tList)
nodeAsStrings = list%asStrings() list => node%asList()
else nodeAsStrings = list%asStrings()
call IO_error(706,ext_msg='Expected list') class default
endif call IO_error(706,ext_msg='Expected list')
endselect
end function tNode_get_byIndex_asStrings end function tNode_get_byIndex_asStrings
@ -626,15 +578,16 @@ function tNode_get_byIndex_asKey(self,i) result(key)
type(tDict), pointer :: dict type(tDict), pointer :: dict
type(tItem), pointer :: item type(tItem), pointer :: item
if (self%isDict()) then select type(self)
dict => self%asDict() class is(tDict)
item => dict%first dict => self%asDict()
do j = 1, min(i,dict%length)-1 item => dict%first
item => item%next do j = 1, min(i,dict%length)-1
enddo item => item%next
else enddo
call IO_error(706,ext_msg='Expected dict') class default
endif call IO_error(706,ext_msg='Expected dict')
endselect
key = item%key key = item%key
@ -655,25 +608,26 @@ function tNode_contains(self,k) result(exists)
type(tDict), pointer :: dict type(tDict), pointer :: dict
exists = .false. exists = .false.
if (self%isDict()) then select type(self)
dict => self%asDict() class is(tDict)
do j=1, dict%length dict => self%asDict()
if (dict%getKey(j) == k) then do j=1, dict%length
exists = .true. if (dict%getKey(j) == k) then
return exists = .true.
endif return
enddo endif
elseif (self%isList()) then enddo
list => self%asList() class is(tList)
do j=1, list%length list => self%asList()
if (list%get_asString(j) == k) then do j=1, list%length
exists = .true. if (list%get_asString(j) == k) then
return exists = .true.
endif return
enddo endif
else enddo
call IO_error(706,ext_msg='Expected "list" or "dict"') class default
endif call IO_error(706,ext_msg='Expected "list" or "dict"')
endselect
end function tNode_contains end function tNode_contains
@ -696,11 +650,12 @@ function tNode_get_byKey(self,k,defaultVal) result(node)
found = present(defaultVal) found = present(defaultVal)
if (found) node => defaultVal if (found) node => defaultVal
if (self%isDict()) then select type(self)
self_ => self%asDict() class is(tDict)
else self_ => self%asDict()
call IO_error(706,ext_msg='Expected Dict for key '//k) class default
endif call IO_error(706,ext_msg='Expected Dict for key '//k)
endselect
j = 1 j = 1
item => self_%first item => self_%first
@ -738,12 +693,13 @@ function tNode_get_byKey_asFloat(self,k,defaultVal) result(nodeAsFloat)
if (self%contains(k)) then if (self%contains(k)) then
node => self%get(k) node => self%get(k)
if (node%isScalar()) then select type(node)
scalar => node%asScalar() class is(tScalar)
nodeAsFloat = scalar%asFloat() scalar => node%asScalar()
else nodeAsFloat = scalar%asFloat()
call IO_error(706,ext_msg='Expected Scalar for key '//k) class default
endif call IO_error(706,ext_msg='Expected Scalar for key '//k)
endselect
elseif (present(defaultVal)) then elseif (present(defaultVal)) then
nodeAsFloat = defaultVal nodeAsFloat = defaultVal
else else
@ -768,12 +724,13 @@ function tNode_get_byKey_asInt(self,k,defaultVal) result(nodeAsInt)
if (self%contains(k)) then if (self%contains(k)) then
node => self%get(k) node => self%get(k)
if (node%isScalar()) then select type(node)
scalar => node%asScalar() class is(tScalar)
nodeAsInt = scalar%asInt() scalar => node%asScalar()
else nodeAsInt = scalar%asInt()
call IO_error(706,ext_msg='Expected Scalar for key '//k) class default
endif call IO_error(706,ext_msg='Expected Scalar for key '//k)
endselect
elseif (present(defaultVal)) then elseif (present(defaultVal)) then
nodeAsInt = defaultVal nodeAsInt = defaultVal
else else
@ -798,12 +755,13 @@ function tNode_get_byKey_asBool(self,k,defaultVal) result(nodeAsBool)
if (self%contains(k)) then if (self%contains(k)) then
node => self%get(k) node => self%get(k)
if (node%isScalar()) then select type(node)
scalar => node%asScalar() class is(tScalar)
nodeAsBool = scalar%asBool() scalar => node%asScalar()
else nodeAsBool = scalar%asBool()
call IO_error(706,ext_msg='Expected Scalar for key '//k) class default
endif call IO_error(706,ext_msg='Expected Scalar for key '//k)
endselect
elseif (present(defaultVal)) then elseif (present(defaultVal)) then
nodeAsBool = defaultVal nodeAsBool = defaultVal
else else
@ -828,12 +786,13 @@ function tNode_get_byKey_asString(self,k,defaultVal) result(nodeAsString)
if (self%contains(k)) then if (self%contains(k)) then
node => self%get(k) node => self%get(k)
if (node%isScalar()) then select type(node)
scalar => node%asScalar() class is(tScalar)
nodeAsString = scalar%asString() scalar => node%asScalar()
else nodeAsString = scalar%asString()
call IO_error(706,ext_msg='Expected Scalar for key '//k) class default
endif call IO_error(706,ext_msg='Expected Scalar for key '//k)
endselect
elseif (present(defaultVal)) then elseif (present(defaultVal)) then
nodeAsString = defaultVal nodeAsString = defaultVal
else else
@ -860,12 +819,13 @@ function tNode_get_byKey_asFloats(self,k,defaultVal,requiredSize) result(nodeAsF
if (self%contains(k)) then if (self%contains(k)) then
node => self%get(k) node => self%get(k)
if (node%isList()) then select type(self)
list => node%asList() class is(tList)
nodeAsFloats = list%asFloats() list => node%asList()
else nodeAsFloats = list%asFloats()
call IO_error(706,ext_msg='Expected list for key '//k) class default
endif call IO_error(706,ext_msg='Expected list for key '//k)
endselect
elseif (present(defaultVal)) then elseif (present(defaultVal)) then
nodeAsFloats = defaultVal nodeAsFloats = defaultVal
else else
@ -895,12 +855,13 @@ function tNode_get_byKey_asInts(self,k,defaultVal,requiredSize) result(nodeAsInt
if (self%contains(k)) then if (self%contains(k)) then
node => self%get(k) node => self%get(k)
if (node%isList()) then select type(node)
list => node%asList() class is(tList)
nodeAsInts = list%asInts() list => node%asList()
else nodeAsInts = list%asInts()
call IO_error(706,ext_msg='Expected list for key '//k) class default
endif call IO_error(706,ext_msg='Expected list for key '//k)
endselect
elseif (present(defaultVal)) then elseif (present(defaultVal)) then
nodeAsInts = defaultVal nodeAsInts = defaultVal
else else
@ -929,12 +890,13 @@ function tNode_get_byKey_asBools(self,k,defaultVal) result(nodeAsBools)
if (self%contains(k)) then if (self%contains(k)) then
node => self%get(k) node => self%get(k)
if (node%isList())then select type(node)
list => node%asList() class is(tList)
nodeAsBools = list%asBools() list => node%asList()
else nodeAsBools = list%asBools()
call IO_error(706,ext_msg='Expected list for key '//k) class default
endif call IO_error(706,ext_msg='Expected list for key '//k)
endselect
elseif (present(defaultVal)) then elseif (present(defaultVal)) then
nodeAsBools = defaultVal nodeAsBools = defaultVal
else else
@ -959,12 +921,13 @@ function tNode_get_byKey_asStrings(self,k,defaultVal) result(nodeAsStrings)
if (self%contains(k)) then if (self%contains(k)) then
node => self%get(k) node => self%get(k)
if (node%isList()) then select type(node)
list => node%asList() class is(tList)
nodeAsStrings = list%asStrings() list => node%asList()
else nodeAsStrings = list%asStrings()
call IO_error(706,ext_msg='Expected list for key '//k) class default
endif call IO_error(706,ext_msg='Expected list for key '//k)
endselect
elseif (present(defaultVal)) then elseif (present(defaultVal)) then
nodeAsStrings = defaultVal nodeAsStrings = defaultVal
else else