cmdopt: move value implementation to header

This commit is contained in:
Danny Robson 2015-06-10 21:54:42 +10:00
parent b752e78036
commit 7df897cd5f
2 changed files with 50 additions and 48 deletions

View File

@ -20,7 +20,6 @@
#include <algorithm> #include <algorithm>
#include <cstring> #include <cstring>
#include <sstream>
using util::cmdopt::option::base; using util::cmdopt::option::base;
using util::cmdopt::option::bytes; using util::cmdopt::option::bytes;
@ -77,53 +76,6 @@ base::name (void) const
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
template <typename T>
value<T>::value (std::string _name, T &_data):
base (_name),
m_data (_data)
{ ; }
//-----------------------------------------------------------------------------
template <typename T>
void
value<T>::execute (const char *restrict str)
{
try {
std::istringstream os (str);
os.exceptions (
std::istringstream::failbit
| std::istringstream::badbit
);
os >> m_data;
if (!os.eof ())
throw invalid_value (__func__);
} catch (...) {
throw invalid_value (__func__);
}
}
//-----------------------------------------------------------------------------
template <typename T>
T
value<T>::data (void) const
{
return m_data;
}
//-----------------------------------------------------------------------------
template <typename T>
T&
value<T>::data (void)
{
return m_data;
}
//-----------------------------------------------------------------------------
namespace util { namespace cmdopt { namespace option { namespace util { namespace cmdopt { namespace option {
template class value<uint16_t>; template class value<uint16_t>;
template class value<uint32_t>; template class value<uint32_t>;

View File

@ -19,7 +19,57 @@
#endif #endif
#define __UTIL_CMDLINE_IPP #define __UTIL_CMDLINE_IPP
#include <sstream>
namespace util { namespace cmdopt { namespace util { namespace cmdopt {
///////////////////////////////////////////////////////////////////////////
template <typename T>
option::value<T>::value (std::string _name, T &_data):
base (std::move (_name)),
m_data (_data)
{ ; }
//-------------------------------------------------------------------------
template <typename T>
void
option::value<T>::execute (const char *restrict str)
{
try {
std::istringstream os (str);
os.exceptions (
std::istringstream::failbit
| std::istringstream::badbit
);
os >> m_data;
if (!os.eof ())
throw invalid_value (__func__);
} catch (...) {
throw invalid_value (__func__);
}
}
//-----------------------------------------------------------------------------
template <typename T>
T
option::value<T>::data (void) const
{
return m_data;
}
//-----------------------------------------------------------------------------
template <typename T>
T&
option::value<T>::data (void)
{
return m_data;
}
///////////////////////////////////////////////////////////////////////////
template <typename T, typename ...Args> template <typename T, typename ...Args>
T& T&
parser::add (char shortname, std::string longname, std::string description, Args&&... args) parser::add (char shortname, std::string longname, std::string description, Args&&... args)