mirror of
https://github.com/holub/mame
synced 2025-07-04 09:28:51 +03:00
Changed fs::meta_value::to_string() to not be static and not require meta_type (#9510)
No need to pass in the meta_type when using std::visit() on the std::variant
This commit is contained in:
parent
07a357463b
commit
945cb29e74
@ -32,20 +32,34 @@ const char *meta_data::entry_name(meta_name name)
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string meta_value::to_string(meta_type type, const meta_value &m)
|
||||
std::string meta_value::to_string() const
|
||||
{
|
||||
switch(type) {
|
||||
case meta_type::string: return m.as_string();
|
||||
case meta_type::number: return util::string_format("0x%x", m.as_number());
|
||||
case meta_type::flag: return m.as_flag() ? "t" : "f";
|
||||
case meta_type::date: {
|
||||
auto dt = m.as_date();
|
||||
return util::string_format("%04d-%02d-%02d %02d:%02d:%02d",
|
||||
std::string result;
|
||||
|
||||
std::visit([this, &result](auto &&arg)
|
||||
{
|
||||
using T = std::decay_t<decltype(arg)>;
|
||||
if constexpr (std::is_same_v<T, std::string>)
|
||||
{
|
||||
result = as_string();
|
||||
}
|
||||
else if constexpr (std::is_same_v<T, uint64_t>)
|
||||
{
|
||||
result = util::string_format("0x%x", as_number());
|
||||
}
|
||||
else if constexpr (std::is_same_v<T, bool>)
|
||||
{
|
||||
result = as_flag() ? "t" : "f";
|
||||
}
|
||||
else if constexpr (std::is_same_v<T, util::arbitrary_datetime>)
|
||||
{
|
||||
auto dt = as_date();
|
||||
result = util::string_format("%04d-%02d-%02d %02d:%02d:%02d",
|
||||
dt.year, dt.month, dt.day_of_month,
|
||||
dt.hour, dt.minute, dt.second);
|
||||
}
|
||||
}
|
||||
return std::string("");
|
||||
}, value);
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace fs
|
||||
|
@ -46,7 +46,7 @@ enum class meta_type {
|
||||
|
||||
class meta_value {
|
||||
public:
|
||||
static std::string to_string(meta_type type, const meta_value &m);
|
||||
std::string to_string() const;
|
||||
static meta_value from_string(meta_type type, std::string value);
|
||||
|
||||
meta_value() { value = false; }
|
||||
|
@ -283,7 +283,7 @@ static void dir_scan(u32 depth, fs::filesystem_t::dir_t dir, std::vector<std::ve
|
||||
if(!meta.has(m.m_name))
|
||||
continue;
|
||||
size_t slot = nmap.find(m.m_name)->second;
|
||||
std::string val = fs::meta_value::to_string(m.m_type, meta.get(m.m_name));
|
||||
std::string val = meta.get(m.m_name).to_string();
|
||||
if(slot == 0)
|
||||
val = head + "dir " + val;
|
||||
entries[id][slot] = val;
|
||||
@ -301,7 +301,7 @@ static void dir_scan(u32 depth, fs::filesystem_t::dir_t dir, std::vector<std::ve
|
||||
if(!meta.has(m.m_name))
|
||||
continue;
|
||||
size_t slot = nmap.find(m.m_name)->second;
|
||||
std::string val = fs::meta_value::to_string(m.m_type, meta.get(m.m_name));
|
||||
std::string val = meta.get(m.m_name).to_string();
|
||||
if(slot == 0)
|
||||
val = head + (c.m_type == fs::dir_entry_type::system_file ? "sys " : "file ") + val;
|
||||
entries[id][slot] = val;
|
||||
@ -323,7 +323,7 @@ static int generic_dir(image_handler &ih)
|
||||
if(!vmeta.empty()) {
|
||||
std::string vinf = "Volume:";
|
||||
for(const auto &e : vmetad)
|
||||
vinf += util::string_format(" %s=%s", fs::meta_data::entry_name(e.m_name), fs::meta_value::to_string(e.m_type, vmeta.get(e.m_name)));
|
||||
vinf += util::string_format(" %s=%s", fs::meta_data::entry_name(e.m_name), vmeta.get(e.m_name).to_string());
|
||||
printf("%s\n\n", vinf.c_str());
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user