@@ -101,6 +101,11 @@ module json_file_module
101
101
json_file_rename_name_ascii
102
102
#endif
103
103
104
+ ! >
105
+ ! Verify that a path is valid
106
+ ! (i.e., a variable with this path exists in the file).
107
+ generic,public :: valid_path = > MAYBEWRAP(json_file_valid_path)
108
+
104
109
! >
105
110
! Get a variable from a [[json_file(type)]], by specifying the path.
106
111
generic,public :: get = > MAYBEWRAP(json_file_get_object), &
@@ -167,6 +172,13 @@ module json_file_module
167
172
! traverse
168
173
procedure ,public :: traverse = > json_file_traverse
169
174
175
+ ! ***************************************************
176
+ ! operators
177
+ ! ***************************************************
178
+
179
+ generic,public :: operator (.in .) = > MAYBEWRAP(json_file_valid_path_op)
180
+ procedure ,pass(me) :: MAYBEWRAP(json_file_valid_path_op)
181
+
170
182
! ***************************************************
171
183
! private routines
172
184
! ***************************************************
@@ -189,6 +201,9 @@ module json_file_module
189
201
procedure :: json_file_rename_name_ascii
190
202
#endif
191
203
204
+ ! validate path:
205
+ procedure :: MAYBEWRAP(json_file_valid_path)
206
+
192
207
! get:
193
208
procedure :: MAYBEWRAP(json_file_get_object)
194
209
procedure :: MAYBEWRAP(json_file_get_integer)
@@ -866,6 +881,92 @@ subroutine json_file_get_root(me,p)
866
881
end subroutine json_file_get_root
867
882
! *****************************************************************************************
868
883
884
+ ! *****************************************************************************************
885
+ ! > author: Jacob Williams
886
+ !
887
+ ! A wrapper for [[json_file_valid_path]] for the `.in.` operator
888
+
889
+ function json_file_valid_path_op (path ,me ) result(found)
890
+
891
+ implicit none
892
+
893
+ character (kind= CK,len=* ),intent (in ) :: path ! ! the path to the variable
894
+ class(json_file),intent (in ) :: me ! ! the JSON file
895
+ logical (LK) :: found ! ! if the variable was found
896
+
897
+ type (json_core) :: core_copy ! ! a copy of `core` from `me`
898
+
899
+ ! This is sort of a hack. Since `me` has to have `intent(in)`
900
+ ! for the operator to work, we need to make a copy of `me%core`
901
+ ! so we can call the low level routine (since it needs it to
902
+ ! be `intent(inout)`) because it's technically possible for this
903
+ ! function to raise an exception. This normally should never
904
+ ! happen here unless the JSON structure is malformed.
905
+
906
+ core_copy = me% core ! copy the settings (need them to know
907
+ ! how to interpret the path)
908
+
909
+ found = core_copy% valid_path(me% p, path) ! call the low-level routine
910
+
911
+ call core_copy% destroy() ! just in case (but not really necessary)
912
+
913
+ end function json_file_valid_path_op
914
+ ! *****************************************************************************************
915
+
916
+ ! *****************************************************************************************
917
+ ! > author: Jacob Williams
918
+ !
919
+ ! Alternate version of [[json_file_valid_path_op]], where "path" is kind=CDK.
920
+
921
+ function wrap_json_file_valid_path_op (path ,me ) result(found)
922
+
923
+ implicit none
924
+
925
+ character (kind= CDK,len=* ),intent (in ) :: path ! ! the path to the variable
926
+ class(json_file),intent (in ) :: me ! ! the JSON file
927
+ logical (LK) :: found ! ! if the variable was found
928
+
929
+ found = to_unicode(path) .in . me
930
+
931
+ end function wrap_json_file_valid_path_op
932
+ ! *****************************************************************************************
933
+
934
+ ! *****************************************************************************************
935
+ ! > author: Jacob Williams
936
+ !
937
+ ! Returns true if the `path` is present in the JSON file.
938
+
939
+ function json_file_valid_path (me ,path ) result(found)
940
+
941
+ implicit none
942
+
943
+ class(json_file),intent (inout ) :: me
944
+ character (kind= CK,len=* ),intent (in ) :: path ! ! the path to the variable
945
+ logical (LK) :: found ! ! if the variable was found
946
+
947
+ found = me% core% valid_path(me% p, path)
948
+
949
+ end function json_file_valid_path
950
+ ! *****************************************************************************************
951
+
952
+ ! *****************************************************************************************
953
+ ! > author: Jacob Williams
954
+ !
955
+ ! Alternate version of [[json_file_valid_path]], where "path" is kind=CDK.
956
+
957
+ function wrap_json_file_valid_path (me ,path ) result(found)
958
+
959
+ implicit none
960
+
961
+ class(json_file),intent (inout ) :: me
962
+ character (kind= CDK,len=* ),intent (in ) :: path ! ! the path to the variable
963
+ logical (LK) :: found ! ! if the variable was found
964
+
965
+ found = me% valid_path(to_unicode(path))
966
+
967
+ end function wrap_json_file_valid_path
968
+ ! *****************************************************************************************
969
+
869
970
! *****************************************************************************************
870
971
! > author: Jacob Williams
871
972
!
0 commit comments