@@ -171,6 +171,7 @@ module json_module
171
171
type (json_data_non_polymorphic) :: data
172
172
173
173
! for the linked list:
174
+ type (json_value), pointer :: previous = > null ()
174
175
type (json_value), pointer :: next = > null ()
175
176
type (json_value), pointer :: parent = > null ()
176
177
type (json_value), pointer :: children = > null ()
@@ -283,10 +284,15 @@ end subroutine array_callback_func
283
284
interface json_destroy
284
285
module procedure :: json_value_destroy
285
286
end interface
287
+
288
+ interface json_remove
289
+ module procedure :: json_value_remove
290
+ end interface
286
291
287
292
! public routines:
288
293
public :: json_initialize ! to initialize the module
289
294
public :: json_destroy ! clear a JSON structure (destructor)
295
+ public :: json_remove ! remove from a JSON structure
290
296
public :: json_parse ! read a JSON file and populate the structure
291
297
public :: json_clear_exceptions ! clear exceptions
292
298
public :: json_check_for_errors ! check for error and get error message
@@ -1055,6 +1061,73 @@ recursive subroutine json_value_destroy(this)
1055
1061
end subroutine json_value_destroy
1056
1062
! *****************************************************************************************
1057
1063
1064
+ ! *****************************************************************************************
1065
+ ! ****f* json_module/json_value_remove
1066
+ !
1067
+ ! NAME
1068
+ ! json_value_destroy
1069
+ !
1070
+ ! DESCRIPTION
1071
+ ! Remove and destroy a json_value (and all its children)
1072
+ ! from a linked-list structure.
1073
+ !
1074
+ ! AUTHOR
1075
+ ! Jacob Williams : 9/9/2014
1076
+ !
1077
+ ! SOURCE
1078
+
1079
+ subroutine json_value_remove (me )
1080
+
1081
+ implicit none
1082
+
1083
+ type (json_value),pointer :: me
1084
+
1085
+ type (json_value),pointer :: parent,previous,next
1086
+
1087
+ if (associated (me)) then
1088
+ if (associated (me% parent)) then
1089
+ if (associated (me% next)) then
1090
+
1091
+ ! there are later items in the list:
1092
+
1093
+ next = > me% next
1094
+ nullify(me% next)
1095
+
1096
+ if (associated (me% previous)) then
1097
+ ! there are earlier items in the list
1098
+ previous = > me% previous
1099
+ previous% next = > next
1100
+ next% previous = > previous
1101
+ else
1102
+ ! this is the first item in the list
1103
+ parent = > me% parent
1104
+ parent% children = > next
1105
+ next% previous = > null ()
1106
+ end if
1107
+
1108
+ else
1109
+
1110
+ if (associated (me% previous)) then
1111
+ ! there are earlier items in the list:
1112
+ previous = > me% previous
1113
+ previous% next = > null ()
1114
+ else
1115
+ ! this is the only item in the list:
1116
+ parent = > me% parent
1117
+ parent% children = > null ()
1118
+ end if
1119
+
1120
+ end if
1121
+
1122
+ end if
1123
+
1124
+ call json_value_destroy(me)
1125
+
1126
+ end if
1127
+
1128
+ end subroutine json_value_remove
1129
+ ! *****************************************************************************************
1130
+
1058
1131
! *****************************************************************************************
1059
1132
! ****f* json_module/json_value_add_member
1060
1133
!
@@ -1090,13 +1163,15 @@ subroutine json_value_add_member(this, member)
1090
1163
p = > p % next
1091
1164
end do
1092
1165
1093
- p % next = > member
1166
+ p% next = > member
1167
+ member% previous = > p
1094
1168
1095
1169
nullify(p) ! cleanup
1096
1170
1097
1171
else
1098
1172
1099
- this % children = > member
1173
+ this% children = > member
1174
+ member% previous = > null ()
1100
1175
1101
1176
end if
1102
1177
0 commit comments