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)
class is(tList)
self_ => self%asList() self_ => self%asList()
else class default
call IO_error(706,ext_msg='Expected List') call IO_error(706,ext_msg='Expected List')
endif 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)
class is(tScalar)
scalar => node%asScalar() scalar => node%asScalar()
nodeAsFloat = scalar%asFloat() nodeAsFloat = scalar%asFloat()
else class default
call IO_error(706,ext_msg='Expected Scalar') call IO_error(706,ext_msg='Expected Scalar')
endif 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)
class is(tScalar)
scalar => node%asScalar() scalar => node%asScalar()
nodeAsInt = scalar%asInt() nodeAsInt = scalar%asInt()
else class default
call IO_error(706,ext_msg='Expected Scalar') call IO_error(706,ext_msg='Expected Scalar')
endif 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)
class is(tScalar)
scalar => node%asScalar() scalar => node%asScalar()
nodeAsBool = scalar%asBool() nodeAsBool = scalar%asBool()
else class default
call IO_error(706,ext_msg='Expected Scalar') call IO_error(706,ext_msg='Expected Scalar')
endif 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)
class is(tScalar)
scalar => node%asScalar() scalar => node%asScalar()
nodeAsString = scalar%asString() nodeAsString = scalar%asString()
else class default
call IO_error(706,ext_msg='Expected Scalar') call IO_error(706,ext_msg='Expected Scalar')
endif 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)
class is(tList)
list => node%asList() list => node%asList()
nodeAsFloats = list%asFloats() nodeAsFloats = list%asFloats()
else class default
call IO_error(706,ext_msg='Expected list') call IO_error(706,ext_msg='Expected list')
endif 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)
class is(tList)
list => node%asList() list => node%asList()
nodeAsInts = list%asInts() nodeAsInts = list%asInts()
else class default
call IO_error(706,ext_msg='Expected list') call IO_error(706,ext_msg='Expected list')
endif 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)
class is(tList)
list => node%asList() list => node%asList()
nodeAsBools = list%asBools() nodeAsBools = list%asBools()
else class default
call IO_error(706,ext_msg='Expected list') call IO_error(706,ext_msg='Expected list')
endif 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)
class is(tList)
list => node%asList() list => node%asList()
nodeAsStrings = list%asStrings() nodeAsStrings = list%asStrings()
else class default
call IO_error(706,ext_msg='Expected list') call IO_error(706,ext_msg='Expected list')
endif 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)
class is(tDict)
dict => self%asDict() dict => self%asDict()
item => dict%first item => dict%first
do j = 1, min(i,dict%length)-1 do j = 1, min(i,dict%length)-1
item => item%next item => item%next
enddo enddo
else class default
call IO_error(706,ext_msg='Expected dict') call IO_error(706,ext_msg='Expected dict')
endif endselect
key = item%key key = item%key
@ -655,7 +608,8 @@ 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)
class is(tDict)
dict => self%asDict() dict => self%asDict()
do j=1, dict%length do j=1, dict%length
if (dict%getKey(j) == k) then if (dict%getKey(j) == k) then
@ -663,7 +617,7 @@ function tNode_contains(self,k) result(exists)
return return
endif endif
enddo enddo
elseif (self%isList()) then class is(tList)
list => self%asList() list => self%asList()
do j=1, list%length do j=1, list%length
if (list%get_asString(j) == k) then if (list%get_asString(j) == k) then
@ -671,9 +625,9 @@ function tNode_contains(self,k) result(exists)
return return
endif endif
enddo enddo
else class default
call IO_error(706,ext_msg='Expected "list" or "dict"') call IO_error(706,ext_msg='Expected "list" or "dict"')
endif 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)
class is(tDict)
self_ => self%asDict() self_ => self%asDict()
else class default
call IO_error(706,ext_msg='Expected Dict for key '//k) call IO_error(706,ext_msg='Expected Dict for key '//k)
endif 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)
class is(tScalar)
scalar => node%asScalar() scalar => node%asScalar()
nodeAsFloat = scalar%asFloat() nodeAsFloat = scalar%asFloat()
else class default
call IO_error(706,ext_msg='Expected Scalar for key '//k) call IO_error(706,ext_msg='Expected Scalar for key '//k)
endif 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)
class is(tScalar)
scalar => node%asScalar() scalar => node%asScalar()
nodeAsInt = scalar%asInt() nodeAsInt = scalar%asInt()
else class default
call IO_error(706,ext_msg='Expected Scalar for key '//k) call IO_error(706,ext_msg='Expected Scalar for key '//k)
endif 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)
class is(tScalar)
scalar => node%asScalar() scalar => node%asScalar()
nodeAsBool = scalar%asBool() nodeAsBool = scalar%asBool()
else class default
call IO_error(706,ext_msg='Expected Scalar for key '//k) call IO_error(706,ext_msg='Expected Scalar for key '//k)
endif 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)
class is(tScalar)
scalar => node%asScalar() scalar => node%asScalar()
nodeAsString = scalar%asString() nodeAsString = scalar%asString()
else class default
call IO_error(706,ext_msg='Expected Scalar for key '//k) call IO_error(706,ext_msg='Expected Scalar for key '//k)
endif 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)
class is(tList)
list => node%asList() list => node%asList()
nodeAsFloats = list%asFloats() nodeAsFloats = list%asFloats()
else class default
call IO_error(706,ext_msg='Expected list for key '//k) call IO_error(706,ext_msg='Expected list for key '//k)
endif 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)
class is(tList)
list => node%asList() list => node%asList()
nodeAsInts = list%asInts() nodeAsInts = list%asInts()
else class default
call IO_error(706,ext_msg='Expected list for key '//k) call IO_error(706,ext_msg='Expected list for key '//k)
endif 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)
class is(tList)
list => node%asList() list => node%asList()
nodeAsBools = list%asBools() nodeAsBools = list%asBools()
else class default
call IO_error(706,ext_msg='Expected list for key '//k) call IO_error(706,ext_msg='Expected list for key '//k)
endif 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)
class is(tList)
list => node%asList() list => node%asList()
nodeAsStrings = list%asStrings() nodeAsStrings = list%asStrings()
else class default
call IO_error(706,ext_msg='Expected list for key '//k) call IO_error(706,ext_msg='Expected list for key '//k)
endif endselect
elseif (present(defaultVal)) then elseif (present(defaultVal)) then
nodeAsStrings = defaultVal nodeAsStrings = defaultVal
else else