cmdopt: add bool value option specialisation

This commit is contained in:
Danny Robson 2015-06-30 22:08:31 +10:00
parent 8038e40f62
commit 88be946454

View File

@ -162,6 +162,48 @@ present::finish (void)
}
///////////////////////////////////////////////////////////////////////////////
namespace util { namespace cmdopt { namespace option {
template <>
void
value<bool>::execute (const char *restrict str)
{
static const std::string TRUE_STRING[] = {
"true",
"yes",
"y",
"1"
};
if (std::any_of (std::begin (TRUE_STRING),
std::end (TRUE_STRING),
[str] (auto i) { return i == str; }))
{
m_data = true;
return;
}
static const std::string FALSE_STRING[] = {
"false",
"no",
"n",
"0"
};
if (std::any_of (std::begin (FALSE_STRING),
std::end (FALSE_STRING),
[str] (auto i) { return i == str; }))
{
m_data = false;
return;
}
base::execute (str);
seen (true);
}
} } }
//-----------------------------------------------------------------------------
namespace util { namespace cmdopt { namespace option {
template class value<uint16_t>;