mirror of
https://github.com/RetroDECK/Supermodel.git
synced 2024-11-22 13:55:38 +00:00
Added ValueAsBool(), ValueAsBoolWithDefault(), and ValueAsUnsignedWithDefault()
This commit is contained in:
parent
f4311a0ab2
commit
718c237063
|
@ -80,13 +80,37 @@ namespace Util
|
|||
{
|
||||
Node Node::s_empty_node;
|
||||
|
||||
bool Node::ValueAsBool() const
|
||||
{
|
||||
const char *value = m_value.c_str();
|
||||
if (!value || !stricmp(value, "false") || !stricmp(value, "off") || !stricmp(value, "no"))
|
||||
return false;
|
||||
else if (!stricmp(value, "true") || !stricmp(value, "on") || !stricmp(value, "yes"))
|
||||
return true;
|
||||
return bool(ValueAsUnsigned());
|
||||
}
|
||||
|
||||
bool Node::ValueAsBoolWithDefault(bool default_value) const
|
||||
{
|
||||
if (this == &s_empty_node)
|
||||
return default_value;
|
||||
return ValueAsBool();
|
||||
}
|
||||
|
||||
uint64_t Node::ValueAsUnsigned() const
|
||||
{
|
||||
if (m_value.find("0x") == 0 || m_value.find("0X") == 0)
|
||||
return strtoull(m_value.c_str() + 2, 0, 16);
|
||||
return strtoull(m_value.c_str(), 0, 10);
|
||||
}
|
||||
|
||||
|
||||
uint64_t Node::ValueAsUnsignedWithDefault(uint64_t default_value) const
|
||||
{
|
||||
if (this == &s_empty_node)
|
||||
return default_value;
|
||||
return ValueAsUnsigned();
|
||||
}
|
||||
|
||||
const Node &Node::operator[](const std::string &path) const
|
||||
{
|
||||
const Node *e = this;
|
||||
|
|
|
@ -161,7 +161,10 @@ namespace Util
|
|||
return m_value;
|
||||
}
|
||||
|
||||
bool ValueAsBool() const;
|
||||
bool ValueAsBoolWithDefault(bool default_value) const;
|
||||
uint64_t ValueAsUnsigned() const;
|
||||
uint64_t ValueAsUnsignedWithDefault(uint64_t default_value) const;
|
||||
|
||||
inline void SetValue(const std::string &value)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue