Skip to content

Commit a83481c

Browse files
Merge pull request #462 from jacobwilliams/208-default-for-get-by-path
adding default optional args to get by path routines
2 parents 662133b + bfaf554 commit a83481c

File tree

8 files changed

+618
-318
lines changed

8 files changed

+618
-318
lines changed

src/json_file_module.F90

Lines changed: 86 additions & 56 deletions
Large diffs are not rendered by default.

src/json_get_scalar_by_path.inc

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
type(json_value),pointer :: p
2+
3+
if (present(default)) then
4+
value = default
5+
else
6+
value = default_if_not_specified
7+
end if
8+
9+
if ( json%exception_thrown ) then
10+
call flag_not_found(found)
11+
return
12+
end if
13+
14+
nullify(p)
15+
call json%get(me=me, path=path, p=p)
16+
17+
if (.not. associated(p)) then
18+
call json%throw_exception('Error in '//routine//':'//&
19+
' Unable to resolve path: '// trim(path),found)
20+
else
21+
call json%get(p,value)
22+
end if
23+
24+
if ( json%exception_thrown ) then
25+
if ( present(found) .or. present(default)) then
26+
call flag_not_found(found)
27+
if (present(default)) value = default
28+
call json%clear_exceptions()
29+
end if
30+
else
31+
if ( present(found) ) found = .true.
32+
end if

src/json_get_vec_by_path.inc

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
type(json_value),pointer :: p
2+
3+
if ( json%exception_thrown ) then
4+
if (present(default)) vec = default
5+
call flag_not_found(found)
6+
return
7+
end if
8+
9+
nullify(p)
10+
call json%get(me=me, path=path, p=p)
11+
12+
if (.not. associated(p)) then
13+
call json%throw_exception('Error in '//routine//':'//&
14+
' Unable to resolve path: '// trim(path),found)
15+
else
16+
call json%get(p,vec)
17+
end if
18+
19+
if ( json%exception_thrown ) then
20+
if ( present(found) .or. present(default)) then
21+
call flag_not_found(found)
22+
if (present(default)) vec = default
23+
call json%clear_exceptions()
24+
end if
25+
else
26+
if ( present(found) ) found = .true.
27+
end if

src/json_get_vec_by_path_alloc.inc

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
type(json_value),pointer :: p
2+
3+
if ( json%exception_thrown ) then
4+
if (present(default)) then
5+
vec = default
6+
if (present(default_ilen)) then
7+
ilen = default_ilen
8+
else
9+
allocate(ilen(size(default)))
10+
ilen = len(default)
11+
end if
12+
end if
13+
call flag_not_found(found)
14+
return
15+
end if
16+
17+
nullify(p)
18+
call json%get(me=me, path=path, p=p)
19+
20+
if (.not. associated(p)) then
21+
call json%throw_exception('Error in '//routine//':'//&
22+
' Unable to resolve path: '// trim(path),found)
23+
else
24+
call json%get(p,vec,ilen)
25+
end if
26+
27+
if ( json%exception_thrown ) then
28+
if ( present(found) .or. present(default)) then
29+
call flag_not_found(found)
30+
if (present(default)) then
31+
vec = default
32+
if (present(default_ilen)) then
33+
ilen = default_ilen
34+
else
35+
allocate(ilen(size(default)))
36+
ilen = len(default)
37+
end if
38+
end if
39+
call json%clear_exceptions()
40+
end if
41+
else
42+
if ( present(found) ) found = .true.
43+
end if

0 commit comments

Comments
 (0)