From 88be9464546449a4fd495b6fc1e50da5fec5ec3f Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Tue, 30 Jun 2015 22:08:31 +1000 Subject: [PATCH] cmdopt: add bool value option specialisation --- cmdopt.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/cmdopt.cpp b/cmdopt.cpp index 341161ed..08a25b91 100644 --- a/cmdopt.cpp +++ b/cmdopt.cpp @@ -162,6 +162,48 @@ present::finish (void) } +/////////////////////////////////////////////////////////////////////////////// +namespace util { namespace cmdopt { namespace option { + template <> + void + value::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;