diff src/SbpOperators/readoperator.jl @ 792:26bf5b2b3e32 operator_storage_array_of_table

Comment on naming and add suggestion for restructure of check_stencil_toml
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Thu, 22 Jul 2021 14:26:34 +0200
parents 7669c1e3a9a4
children 04e549669b10
line wrap: on
line diff
--- a/src/SbpOperators/readoperator.jl	Thu Jul 22 10:14:04 2021 +0200
+++ b/src/SbpOperators/readoperator.jl	Thu Jul 22 14:26:34 2021 +0200
@@ -23,6 +23,8 @@
 
 # TODO: Control type for the stencil
 # TODO: Think about naming and terminology around freshly parsed TOML.
+# Vidar: What about get_stencil instead of parse_stencil for an already parsed
+# toml. It matches get_stencil_set.
 
 """
     read_stencil_set(fn; filters)
@@ -76,6 +78,29 @@
     return Stencil(weights..., center = toml["c"])
 end
 
+# TBD Vidar:
+# I suggest the following restructure, for a clearer control flow.
+# function check_stencil_toml(toml)
+#     if toml isa Vector{String}
+#         return
+#     end
+#
+#     if toml isa Dict
+#       if !(haskey(toml, "s") && haskey(toml, "c"))
+#             throw(ArgumentError("the table form of a stencil must have fields `s` and `c`."))
+#       end
+#
+#       if !(toml["s"] isa Vector{String})
+#           throw(ArgumentError("a stencil must be specified as a vector of strings."))
+#       end
+#
+#       if !(toml["c"] isa Int)
+#             throw(ArgumentError("the center of a stencil must be specified as an integer."))
+#       end
+#       return
+#     end
+#     throw(ArgumentError("the TOML for a stencil must be a vector of strings or a table."))
+# end
 function check_stencil_toml(toml)
     if !(toml isa Dict || toml isa Vector{String})
         throw(ArgumentError("the TOML for a stencil must be a vector of strings or a table."))