2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
15 \brief Traits inline non-template implementation */
20 #include <boost/algorithm/string/predicate.hpp>
22 #define prefix_ inline
23 //-/////////////////////////////////////////////////////////////////////////////////////////////////
25 //-/////////////////////////////////////////////////////////////////////////////////////////////////
26 // senf::console::ArgumentTraits<bool>
29 senf::console::ArgumentTraits<bool>::parse(ParseCommandInfo::TokensRange const & tokens,
32 if (tokens.size() != 1)
33 throw SyntaxErrorException("argument syntax error");
35 if ( boost::istarts_with(std::string("true"), tokens.begin()->value())
36 || boost::istarts_with(std::string("enabled"), tokens.begin()->value())
37 || boost::istarts_with(std::string("yes"), tokens.begin()->value())
38 || boost::iequals(std::string("on"), tokens.begin()->value()) )
40 else if (boost::istarts_with(std::string("false"), tokens.begin()->value())
41 || boost::istarts_with(std::string("disabled"), tokens.begin()->value())
42 || boost::istarts_with(std::string("no"), tokens.begin()->value())
43 || (boost::istarts_with(std::string("off"), tokens.begin()->value())
44 && tokens.begin()->value().size() >= 2) )
48 senf::console::parse(tokens, v);
53 prefix_ std::string senf::console::ArgumentTraits<bool>::description()
58 prefix_ std::string senf::console::ArgumentTraits<bool>::str(bool value)
60 return value ? "true" : "false";
63 //-/////////////////////////////////////////////////////////////////////////////////////////////////
64 // senf::console::ReturnValueTraits<bool>
66 prefix_ void senf::console::ReturnValueTraits<bool>::format(bool value, std::ostream & os)
68 formatTrueFalse(value, os);
71 //-/////////////////////////////////////////////////////////////////////////////////////////////////
73 prefix_ void senf::console::formatTrueFalse(bool value, std::ostream & os)
75 os << (value ? "true" : "false");
78 prefix_ void senf::console::formatYesNo(bool value, std::ostream & os)
80 os << (value ? "yes" : "no");
83 prefix_ void senf::console::formatEnabledDisabled(bool value, std::ostream & os)
85 os << (value ? "enabled" : "disabled");
88 prefix_ void senf::console::formatOnOff(bool value, std::ostream & os)
90 os << (value ? "on" : "off");
93 prefix_ void senf::console::formatOneZero(bool value, std::ostream & os)
95 os << (value ? "0" : "1");
98 //-/////////////////////////////////////////////////////////////////////////////////////////////////
105 // comment-column: 40
106 // c-file-style: "senf"
107 // indent-tabs-mode: nil
108 // ispell-local-dictionary: "american"
109 // compile-command: "scons -u test"