@@ -150,20 +150,28 @@ module json_file_module
150
150
! date: 07/23/2015
151
151
!
152
152
! Structure constructor to initialize a [[json_file(type)]] object
153
- ! with an existing [[json_value]] object
153
+ ! with an existing [[json_value]] object, and either the [[json_core]]
154
+ ! settings or a [[json_core]] instance.
154
155
!
155
156
! # Example
156
157
!
157
158
! ```fortran
158
159
! ...
159
160
! type(json_file) :: my_file
160
- ! type(json_value) :: json_object
161
+ ! type(json_value),pointer :: json_object
162
+ ! type(json_core) :: json_core_object
161
163
! ...
162
- ! ! Construct a json_object
163
- ! my_file = json_file(json_object)
164
+ ! ! Construct a json_object:
165
+ ! !could do this:
166
+ ! my_file = json_file(json_object)
167
+ ! !or:
168
+ ! my_file = json_file(json_object,verbose=.true.)
169
+ ! !or:
170
+ ! my_file = json_file(json_object,json_core_object)
164
171
! ```
165
172
interface json_file
166
- module procedure initialize_json_file
173
+ module procedure :: initialize_json_file
174
+ module procedure :: initialize_json_file_v2
167
175
end interface
168
176
! *************************************************************************************
169
177
@@ -240,6 +248,10 @@ end subroutine json_file_print_error_message
240
248
! This is just a wrapper for [[json_initialize]].
241
249
!
242
250
! @note: This does not destroy the data in the file.
251
+ !
252
+ ! @note [[initialize_json_core]], [[json_initialize]],
253
+ ! [[initialize_json_core_in_file]], and [[initialize_json_file]]
254
+ ! all have a similar interface.
243
255
244
256
subroutine initialize_json_core_in_file (me ,verbose ,compact_reals ,&
245
257
print_signs ,real_format ,spaces_per_tab ,&
@@ -270,6 +282,10 @@ end subroutine initialize_json_core_in_file
270
282
!
271
283
! Cast a [[json_value]] object as a [[json_file(type)]] object.
272
284
! It also calls the `initialize()` method.
285
+ !
286
+ ! @note [[initialize_json_core]], [[json_initialize]],
287
+ ! [[initialize_json_core_in_file]], and [[initialize_json_file]]
288
+ ! all have a similar interface.
273
289
274
290
function initialize_json_file (p ,verbose ,compact_reals ,&
275
291
print_signs ,real_format ,spaces_per_tab ,&
@@ -300,18 +316,56 @@ end function initialize_json_file
300
316
301
317
! *****************************************************************************************
302
318
! > author: Jacob Williams
303
- ! date: 12/9/2013
319
+ ! date: 4/26/2016
320
+ !
321
+ ! Cast a [[json_value]] pointer and a [[json_core]] object
322
+ ! as a [[json_file(type)]] object.
323
+
324
+ function initialize_json_file_v2 (json_value_object , json_core_object ) &
325
+ result(file_object)
326
+
327
+ implicit none
328
+
329
+ type (json_file) :: file_object
330
+ type (json_value),pointer ,intent (in ) :: json_value_object
331
+ type (json_core),intent (in ) :: json_core_object
332
+
333
+ file_object% p = > json_value_object
334
+ file_object% json = json_core_object
335
+
336
+ end function initialize_json_file_v2
337
+ ! *****************************************************************************************
338
+
339
+ ! *****************************************************************************************
340
+ ! > author: Jacob Williams
304
341
!
305
- ! Destroy the [[json_file(type)]].
342
+ ! Destroy the [[json_value]] data in a [[json_file(type)]].
343
+ ! This must be done when the variable is no longer needed,
344
+ ! or will be reused to open a different file.
345
+ ! Otherwise a memory leak will occur.
346
+ !
347
+ ! Optionally, also destroy the [[json_core]] instance (this
348
+ ! is not necessary to prevent memory leaks, since a [[json_core]]
349
+ ! does not use pointers).
350
+ !
351
+ ! ### History
352
+ ! * 12/9/2013 : Created
353
+ ! * 4/26/2016 : Added optional `destroy_core` argument
306
354
307
- subroutine json_file_destroy (me )
355
+ subroutine json_file_destroy (me , destroy_core )
308
356
309
357
implicit none
310
358
311
359
class(json_file),intent (inout ) :: me
360
+ logical ,intent (in ),optional :: destroy_core ! ! to also destroy the [[json_core]].
361
+ ! ! default is to leave it as is.
312
362
313
363
if (associated (me% p)) call me% json% destroy(me% p)
314
364
365
+ if (present (destroy_core)) then
366
+ if (destroy_core) call me% json% destroy()
367
+ end if
368
+
315
369
end subroutine json_file_destroy
316
370
! *****************************************************************************************
317
371
0 commit comments