Commit 5eb3dfdc authored by Kučera Petr RNDr. Ph.D.'s avatar Kučera Petr RNDr. Ph.D.
Browse files

Model config file part

parent d53cbde8
......@@ -29,3 +29,13 @@ default-directory = data
logical-graph = graph/logical_graph.dot
section-graph = graph/section_graph.dot
section-graph-info = graph/section_graph_info.txt
# Parameters of model creation
#
[model]
# Multipliers are floats
# Additive constants are unsigned integers
min-duration-multiplier = 0.1
min-duration-addition = 60
max-duration-multiplier = 1.0
max-duration-addition = 300
......@@ -61,6 +61,13 @@ Loco::Cfg::Parse(const INISection &sect)
return false;
}
}
else if (subsect.mIdent == "model")
{
if (!model.Parse(subsect))
{
return false;
}
}
else
{
std::cerr << "[Cfg::Parse] Ignoring unknown config file section "
......@@ -120,3 +127,17 @@ Loco::CfgDebug::Parse(const INISection &sect,
sect.PathValue("section-graph-info", directory, section_graph_info);
return true;
}
bool
Loco::CfgModel::Parse(const INISection &sect)
{
min_duration_multiplier = sect.DoubleValue("min-duration-multiplier")
.value_or(min_duration_multiplier);
min_duration_addition = sect.UnsignedValue("min-duration-addition")
.value_or(min_duration_addition);
max_duration_multiplier = sect.DoubleValue("max-duration-multiplier")
.value_or(max_duration_multiplier);
max_duration_addition = sect.UnsignedValue("max-duration-addition")
.value_or(max_duration_addition);
return true;
}
......@@ -62,6 +62,16 @@ namespace Loco
bool Parse(const INISection &sect, const std::string &default_directory);
};
struct CfgModel
{
double min_duration_multiplier{0.1};
unsigned min_duration_addition{60};
double max_duration_multiplier{1.0};
unsigned max_duration_addition{300};
bool Parse(const INISection &sect);
};
struct Cfg
{
inline static const std::filesystem::path kDefaultCfgFile{"deadlock.ini"};
......@@ -71,6 +81,7 @@ namespace Loco
CfgOutput output{};
CfgMessage message{};
CfgDebug debug{};
CfgModel model{};
bool Parse(const INISection &sect);
bool ParseFile(const std::filesystem::path &fname);
......
......@@ -320,6 +320,13 @@ Loco::INISection::UnsignedValue(const std::string &v_ident) const
[](const std::string &s) { return std::stoul(s); });
}
std::optional<double>
Loco::INISection::DoubleValue(const std::string &v_ident) const
{
return GetValue<double>(v_ident,
[](const std::string &s) { return std::stod(s); });
}
std::optional<Loco::length_type>
Loco::INISection::LengthValue(const std::string &v_ident) const
{
......
......@@ -54,6 +54,7 @@ namespace Loco
std::optional<long unsigned>
UnsignedValue(const std::string &v_ident) const;
std::optional<length_type> LengthValue(const std::string &v_ident) const;
std::optional<double> DoubleValue(const std::string &v_ident) const;
TimeSpec TimeSpecValue(const std::string &v_ident) const;
std::string
ValueWithDefault(const std::string &v_ident,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment