You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be useful to have a stdlib module for handling common file format for data storage. If we can provide an interface in stdlib for this kind of operations we would make it much easier to integrate a new file format in a library which is already using stdlib.
This can be implemented in stdlib by pulling in common libraries used for this task, like JSON Fortran and TOML Fortran. Alternative, the interface could be declared in the specification and libraries like JSON Fortran and TOML Fortran can provide an implementation of stdlib_json or stdlib_toml, respectively.
Requirements (feel free to add to this list)
map data structure
list data structure
date time derived type (for TOML)
A possible API
!> Standard library support for reading TOML documentsmodule stdlib_toml
interfacetoml_load!> Load TOML data structure from filemodulesubroutinetoml_load_from_file(filename, value, stat, message)
!> File name to read fromcharacter(*), intent(in) :: filename
!> Data structure, either a built-in type a [[stdlib_value::value_type]]
class(*), allocatable, intent(out) :: value
!> Error code, if not provided routine will halt in case of errorinteger, intent(out), optional:: stat
!> Error messagecharacter(:), allocatable, intent(out), optional:: message
endsubroutine toml_load_from_fileendinterface toml_load
interfacetoml_loadsmodulesubroutinetoml_load_from_string(string, value, stat, message)
!> File name to read fromcharacter(*), intent(in) :: string
!> Data structure, either a built-in type or a [[stdlib_value::value_type]]
class(*), allocatable, intent(out) :: value
!> Error code, if not provided routine will halt in case of errorinteger, intent(out), optional:: stat
!> Error messagecharacter(:), allocatable, intent(out), optional:: message
endsubroutine toml_load_from_stringendinterface toml_loads
end module stdlib_toml
A similar interface would be provided for reading JSON to allow a consistent interface for all common IO formats.
!> Standard library support for reading JSON documentsmodule stdlib_json
interfacejson_load!> Load JSON data structure from filemodulesubroutinejson_load_from_file(filename, value, stat, message)
!> File name to read fromcharacter(*), intent(in) :: filename
!> Data structure, either a built-in type a [[stdlib_value::value_type]]
class(*), allocatable, intent(out) :: value
!> Error code, if not provided routine will halt in case of errorinteger, intent(out), optional:: stat
!> Error messagecharacter(:), allocatable, intent(out), optional:: message
endsubroutine json_load_from_fileendinterface json_load
interfacejson_load!> Load JSON data structure from stringmodulesubroutinejson_loads_from_string(string, value, stat, message)
!> File name to read fromcharacter(*), intent(in) :: string
!> Data structure, either a built-in type or a [[stdlib_value::value_type]]
class(*), allocatable, intent(out) :: value
!> Error code, if not provided routine will halt in case of errorinteger, intent(out), optional:: stat
!> Error messagecharacter(:), allocatable, intent(out), optional:: message
endsubroutine json_loadsendinterface json_loads_from_string
end module stdlib_json
The text was updated successfully, but these errors were encountered:
I think it is a great idea. Another file format mentioned in your list (maybe on purpose) is the CSV format.
Anyway, would this result in stdlib depending on other separate projects to support the different file formats? And so, avoid to rewrite everything from scrath?
Anyway, would this result in stdlib depending on other separate projects to support the different file formats? And so, avoid to rewrite everything from scrath?
Maintaining an own parser implementation for every format can be quite demanding, especially with respect to validation for the implementation, for small formats this might be possible to do within stdlib.
Instead of depending on other libraries it might be possible to just define the interface another library would have to implement. A user would still need to manually depend on the respective project implementing the stdlib interface:
It would be useful to have a stdlib module for handling common file format for data storage. If we can provide an interface in stdlib for this kind of operations we would make it much easier to integrate a new file format in a library which is already using stdlib.
This can be implemented in stdlib by pulling in common libraries used for this task, like JSON Fortran and TOML Fortran. Alternative, the interface could be declared in the specification and libraries like JSON Fortran and TOML Fortran can provide an implementation of
stdlib_json
orstdlib_toml
, respectively.Requirements (feel free to add to this list)
A possible API
A similar interface would be provided for reading JSON to allow a consistent interface for all common IO formats.
The text was updated successfully, but these errors were encountered: