For C++ users, conduit includes a built-in version of the fmt
library (https://fmt.dev/). Since other projects also bundle fmt
, the conduit version is modified to place everything in the conduit_fmt
namespace instead of the default fmt
namespace. This is a safe approach to avoid potential confusion and static linking consequences.
When using conduit in C++, you can use its built-in fmt
as follows:
../../tests/docs/t_conduit_docs_tutorial_utils.cpp
t_conduit_docs_tutorial_utils_out.txt
In addition to direct fmt
support, conduit utils provides conduit::utils::format
methods that enable fmt
style string formatting with the arguments are passed as a conduit::Node
tree. These simplify use cases such as generating path string, allowing the pattern string and arguments to be stored as part of a conduit hierarchy (and in HDF5, YAML, etc files). This feature is also available in Conduit's Python API (conduit.utils.format
).
The args
case allows named arguments (args passed as object) or ordered args (args passed as list).
conduit::utils::format(string, args) -- object case:
../../tests/docs/t_conduit_docs_tutorial_utils.cpp
t_conduit_docs_tutorial_utils_out.txt
conduit::utils::format(string, args) -- list case:
../../tests/docs/t_conduit_docs_tutorial_utils.cpp
t_conduit_docs_tutorial_utils_out.txt
The maps
case also supports named or ordered args and works in conjunction with a map_index
. The map_index
is used to fetch a value from an array, or list of strings, which is then passed to fmt. The maps
style of indexed indirection supports generating path strings for non-trivial domain partition mappings in Blueprint.
conduit::utils::format(string, maps, map_index) -- object case:
../../tests/docs/t_conduit_docs_tutorial_utils.cpp
t_conduit_docs_tutorial_utils_out.txt
conduit::utils::format(string, maps, map_index ) -- list case:
../../tests/docs/t_conduit_docs_tutorial_utils.cpp
t_conduit_docs_tutorial_utils_out.txt