cmdopt: move bool parsing into inline headers

This avoids multiple definition issues with more aggressive inliners, eg
mingw
This commit is contained in:
Danny Robson 2016-04-27 15:52:52 +10:00
parent 0ec92951fc
commit 1356391259
2 changed files with 44 additions and 44 deletions

View File

@ -18,7 +18,6 @@
#include "debug.hpp"
#include <algorithm>
#include <cstring>
#include <iostream>
#include <iomanip>
@ -154,48 +153,6 @@ 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>;

View File

@ -20,6 +20,7 @@
#define __UTIL_CMDLINE_IPP
#include <sstream>
#include <algorithm>
#include "./introspection.hpp"
#include "./iterator.hpp"
@ -34,7 +35,7 @@ namespace util { namespace cmdopt {
//-------------------------------------------------------------------------
template <typename T>
void
inline void
option::value<T>::execute (const char *restrict str)
{
try {
@ -53,6 +54,48 @@ namespace util { namespace cmdopt {
}
//-------------------------------------------------------------------------
namespace option {
template <>
inline 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 detail {
template <typename T>