Commit d6947c1c authored by Gauthier Quesnel's avatar Gauthier Quesnel
Browse files

external-sources: add enum to string functions

parent 16f26f14
......@@ -318,7 +318,7 @@ editor::show_sources_window(bool* is_show)
ImGui::TextUnformatted(cst_src->name.c_str());
ImGui::TableNextColumn();
ImGui::TextUnformatted(
external_source_str[ordinal(external_source_type::constant)]);
external_source_str(external_source_type::constant));
ImGui::TableNextColumn();
ImGui::Text("%" PRIu64, cst_src->buffer.size());
ImGui::TableNextColumn();
......@@ -362,7 +362,7 @@ editor::show_sources_window(bool* is_show)
ImGui::TextUnformatted(txt_src->name.c_str());
ImGui::TableNextColumn();
ImGui::TextUnformatted(
external_source_str[ordinal(external_source_type::text_file)]);
external_source_str(external_source_type::text_file));
ImGui::TableNextColumn();
ImGui::Text("%" PRIu64, txt_src->buffer.size);
ImGui::TableNextColumn();
......@@ -394,7 +394,7 @@ editor::show_sources_window(bool* is_show)
ImGui::TextUnformatted(bin_src->name.c_str());
ImGui::TableNextColumn();
ImGui::TextUnformatted(
external_source_str[ordinal(external_source_type::binary_file)]);
external_source_str(external_source_type::binary_file));
ImGui::TableNextColumn();
ImGui::Text("%" PRIu64, bin_src->buffer.size);
ImGui::TableNextColumn();
......@@ -424,12 +424,11 @@ editor::show_sources_window(bool* is_show)
ImGui::TextUnformatted(rnd_src->name.c_str());
ImGui::TableNextColumn();
ImGui::TextUnformatted(
external_source_str[ordinal(external_source_type::random)]);
external_source_str(external_source_type::random));
ImGui::TableNextColumn();
ImGui::Text("%" PRIu64, rnd_src->buffer.size);
ImGui::TableNextColumn();
ImGui::TextUnformatted(
distribution_type_str[ordinal(rnd_src->distribution)]);
ImGui::TextUnformatted(distribution_str(rnd_src->distribution));
}
ImGui::EndTable();
......
......@@ -140,10 +140,16 @@ external_source_type_cast(int value, external_source_type* type) noexcept
return true;
}
static inline const char* external_source_str[] = { "binary_file",
"constant",
"random",
"text_file" };
static inline const char* external_source_type_string[] = { "binary_file",
"constant",
"random",
"text_file" };
inline const char*
external_source_str(const external_source_type type) noexcept
{
return external_source_type_string[static_cast<int>(type)];
}
enum class distribution_type
{
......@@ -166,13 +172,20 @@ enum class distribution_type
weibull,
};
static inline const char* distribution_type_str[] = {
static const char* distribution_type_string[] = {
"bernouilli", "binomial", "cauchy", "chi_squared", "exponential",
"exterme_value", "fisher_f", "gamma", "geometric", "lognormal",
"negative_binomial", "normal", "poisson", "student_t", "uniform_int",
"uniform_real", "weibull"
};
inline const char*
distribution_str(const distribution_type type) noexcept
{
return distribution_type_string[static_cast<int>(type)];
}
struct constant_source
{
small_string<23> name;
......
......@@ -662,18 +662,18 @@ private:
if (!(is >> type_str))
return status::io_file_format_error;
auto it = binary_find(std::begin(distribution_type_str),
std::end(distribution_type_str),
auto it = binary_find(std::begin(distribution_type_string),
std::end(distribution_type_string),
type_str,
[](const char* left, const char* right) {
return std::strcmp(left, right) == 0;
});
if (it == std::end(distribution_type_str))
if (it == std::end(distribution_type_string))
return status::io_file_format_error;
const auto dist_id =
std::distance(std::begin(distribution_type_str), it);
std::distance(std::begin(distribution_type_string), it);
auto& elem = srcs.random_sources.alloc();
if (auto ret = elem.init(srcs.block_size, srcs.block_number);
......@@ -1544,8 +1544,7 @@ struct writer
const auto id = srcs.random_sources.get_id(src);
const auto index = get_index(id);
os << index << ' '
<< distribution_type_str[ordinal(src->distribution)];
os << index << ' ' << distribution_str(src->distribution);
write(*src);
......
Markdown is supported
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