Skip to content

Commit 8d94004

Browse files
committed
Added function constructor for json_core
Also added new constructor for json_file which accepts a json_core instance. Fixes #175
1 parent 979e950 commit 8d94004

File tree

2 files changed

+244
-148
lines changed

2 files changed

+244
-148
lines changed

src/json_file_module.F90

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,20 +150,28 @@ module json_file_module
150150
! date: 07/23/2015
151151
!
152152
! 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.
154155
!
155156
!# Example
156157
!
157158
!```fortran
158159
! ...
159160
! 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
161163
! ...
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)
164171
!```
165172
interface json_file
166-
module procedure initialize_json_file
173+
module procedure :: initialize_json_file
174+
module procedure :: initialize_json_file_v2
167175
end interface
168176
!*************************************************************************************
169177

@@ -240,6 +248,10 @@ end subroutine json_file_print_error_message
240248
! This is just a wrapper for [[json_initialize]].
241249
!
242250
!@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.
243255

244256
subroutine initialize_json_core_in_file(me,verbose,compact_reals,&
245257
print_signs,real_format,spaces_per_tab,&
@@ -270,6 +282,10 @@ end subroutine initialize_json_core_in_file
270282
!
271283
! Cast a [[json_value]] object as a [[json_file(type)]] object.
272284
! 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.
273289

274290
function initialize_json_file(p,verbose,compact_reals,&
275291
print_signs,real_format,spaces_per_tab,&
@@ -298,6 +314,32 @@ function initialize_json_file(p,verbose,compact_reals,&
298314
end function initialize_json_file
299315
!*****************************************************************************************
300316

317+
!*****************************************************************************************
318+
!> author: Jacob Williams
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+
!@note [[initialize_json_core]], [[json_initialize]],
325+
! [[initialize_json_core_in_file]], and [[initialize_json_file]]
326+
! all have a similar interface.
327+
328+
function initialize_json_file_v2(json_value_object, json_core_object) &
329+
result(file_object)
330+
331+
implicit none
332+
333+
type(json_file) :: file_object
334+
type(json_value),pointer,intent(in) :: json_value_object
335+
type(json_core),intent(in) :: json_core_object
336+
337+
file_object%p => json_value_object
338+
file_object%json = json_core_object
339+
340+
end function initialize_json_file_v2
341+
!*****************************************************************************************
342+
301343
!*****************************************************************************************
302344
!> author: Jacob Williams
303345
! date: 12/9/2013

0 commit comments

Comments
 (0)