I'm trying to use boost::property_tree to read in an infinite time duration from an XML config file for certain configurations (non-infinite for others). This code works for non-infinite durations.
My code where it reads in the value:
boost::property_tree::ptree property_tree;
boost::property_tree::read_xml(filepath, property_tree);
auto config = property_tree.get_child("Config");
std::chrono::seconds my_duration_value = std::chrono::seconds(config.get<unsigned int>("MyDurationField"));
What I would like to be able to do in the configuration file:
<Config>
<MyDurationField>inf</MyDurationField>
</Config>
Is there a way to do this that will work for infinite and non-infinite time durations? Thanks in advance.
std::chrono::seconds
won't store an infinite value. So that may be the problem. Under the hood seconds
is just a signed 64 bit integral type. You could store a very large value (0x7FFF'FFFF'FFFF'FFFF seconds or about 292 billion years), but not infinity.
If you changed the chrono
representation to a floating point type (e.g. double
) you might be able to pull it off, not sure. Here is std::chrono::seconds
but with a representation of double
:
std::chrono::duration<double>