Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"set" procedure not accepting input of parameter_list type #13

Closed
trmwzm opened this issue Nov 2, 2018 · 5 comments
Closed

"set" procedure not accepting input of parameter_list type #13

trmwzm opened this issue Nov 2, 2018 · 5 comments

Comments

@trmwzm
Copy link

trmwzm commented Nov 2, 2018

... as a way of appending an existing list to another one, as a sublist. ... thank you for the library!

@nncarlson
Copy link
Owner

Hello Thierry, Can you explain in more detail what you would like to be able to do. It's not quite clear to me.

@trmwzm
Copy link
Author

trmwzm commented Nov 3, 2018

Hello Neal. If I have 2 parameter_list(s), let's say read from JSONs, I am looking to add a type bound procedure to be able to do:

type(parameter_list) :: p, p1, p2

call parameter_list_from_json_stream(json_1_unit, p1)
call parameter_list_from_json_stream(json_2_unit, p2)

call p%set ('json 1', p1)
call p%set ('json 2', p2)

Should be relatively easy using recursion and the iterators already in library (?) I will try to give it a go.

@trmwzm trmwzm closed this as completed Nov 3, 2018
@trmwzm trmwzm reopened this Nov 3, 2018
@nncarlson
Copy link
Owner

I think you should be able to do something like that already:

type(parameter_list) :: p
type(parameter_list), pointer :: p1, p2

p1 => p%sublist('json 1')
p2 => p%sublist('json 2')

call parameters_from_json_stream(json1_unit, p1)
call parameters_from_json_stream(json2_unit, p2)

Note the use of parameters_from_json_stream instead of parameter_list_from_json_stream. The latter takes a pointer as an argument which it allocates and fills internally. The former takes a preexisting parameter list and adds to it.

That said, if one had an existing parameter list pointer p1, it would be very useful to be able to make it a new sublist of a parameter list p. So something like this:

call parameter_list_from_json_stream(json1_unit, p1)
...
call p%set_sublist('json 1', p1)

I've wanted this myself on several occasions. It's not always convenient or possible to create the empty sublist first and then fill it. Is this what you are looking for? This would be very easy to add.

@trmwzm
Copy link
Author

trmwzm commented Nov 3, 2018

Yes, creating a sublist and subsequently filling it would be a workaround. The use case I was thinking of is a hierarchy of list which mirrors that of class composition. A class would have a constructor using a plist as a unique argument, and a "to_plist()" serialization. I can easily modify "to_plist" to take a pre-allocated plist as additional argument. Thank you very much!

@trmwzm trmwzm closed this as completed Nov 3, 2018
@nncarlson
Copy link
Owner

I'm intrigued by your serialization use case. If you can, and when you feel ready, I'd like to hear more about it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants