Skip to content

Commit b16fa00

Browse files
committed
Add method to cast json_file as json_value
1 parent 6b9fcd4 commit b16fa00

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/json_module.F90

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,8 @@ module json_module
385385
MAYBEWRAP(json_file_get_integer_vec), &
386386
MAYBEWRAP(json_file_get_double_vec), &
387387
MAYBEWRAP(json_file_get_logical_vec), &
388-
MAYBEWRAP(json_file_get_string_vec)
388+
MAYBEWRAP(json_file_get_string_vec), &
389+
json_file_get_root
389390

390391
generic,public :: update => MAYBEWRAP(json_file_update_integer), &
391392
MAYBEWRAP(json_file_update_logical), &
@@ -412,6 +413,7 @@ module json_module
412413
procedure :: MAYBEWRAP(json_file_get_double_vec)
413414
procedure :: MAYBEWRAP(json_file_get_logical_vec)
414415
procedure :: MAYBEWRAP(json_file_get_string_vec)
416+
procedure :: json_file_get_root
415417

416418
!update:
417419
procedure :: MAYBEWRAP(json_file_update_integer)
@@ -1277,6 +1279,24 @@ subroutine json_file_get_object(me, path, p, found)
12771279
end subroutine json_file_get_object
12781280
!*****************************************************************************************
12791281

1282+
!*****************************************************************************************
1283+
!> author: Izaak Beekman
1284+
! date: 7/23/2015
1285+
!
1286+
! Get a [[json_value]] pointer to the JSON file root.
1287+
1288+
subroutine json_file_get_root(me,p)
1289+
1290+
implicit none
1291+
1292+
class(json_file),intent(inout) :: me
1293+
type(json_value),pointer,intent(out) :: p !! pointer to the variable
1294+
1295+
p => me%p
1296+
1297+
end subroutine json_file_get_root
1298+
!*****************************************************************************************
1299+
12801300
!*****************************************************************************************
12811301
!>
12821302
! Alternate version of [[json_file_get_object]], where "path" is kind=CDK.

src/tests/jf_test_12.f90

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ subroutine test_12(error_cnt)
152152
call my_file%get('$array data.data',fetched_array)
153153
call check_errors(all(fetched_array == reshape(raw_array,[size(raw_array)])))
154154

155+
call my_file%get(tmp_json_ptr)
156+
call check_errors(associated(tmp_json_ptr,root))
157+
155158
contains
156159
subroutine check_errors(assertion)
157160
logical, optional, intent(in) :: assertion

0 commit comments

Comments
 (0)