4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.de>
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 \brief Traits inline non-template implementation */
29 #include <boost/algorithm/string/predicate.hpp>
31 #define prefix_ inline
32 ///////////////////////////////cci.p///////////////////////////////////////
34 ///////////////////////////////////////////////////////////////////////////
35 // senf::console::ArgumentTraits<bool>
38 senf::console::ArgumentTraits<bool>::parse(ParseCommandInfo::TokensRange const & tokens,
41 if (tokens.size() != 1)
42 throw SyntaxErrorException("argument syntax error");
44 if ( boost::istarts_with(std::string("true"), tokens.begin()->value())
45 || boost::istarts_with(std::string("enabled"), tokens.begin()->value())
46 || boost::istarts_with(std::string("yes"), tokens.begin()->value())
47 || boost::iequals(std::string("on"), tokens.begin()->value()) )
49 else if (boost::istarts_with(std::string("false"), tokens.begin()->value())
50 || boost::istarts_with(std::string("disabled"), tokens.begin()->value())
51 || boost::istarts_with(std::string("no"), tokens.begin()->value())
52 || (boost::istarts_with(std::string("off"), tokens.begin()->value())
53 && tokens.begin()->value().size() >= 2) )
57 senf::console::parse(tokens, v);
62 prefix_ std::string senf::console::ArgumentTraits<bool>::description()
67 prefix_ std::string senf::console::ArgumentTraits<bool>::str(bool value)
69 return value ? "true" : "false";
72 ///////////////////////////////////////////////////////////////////////////
73 // senf::console::ReturnValueTraits<bool>
75 prefix_ void senf::console::ReturnValueTraits<bool>::format(bool value, std::ostream & os)
77 formatTrueFalse(value, os);
80 ///////////////////////////////////////////////////////////////////////////
82 prefix_ void senf::console::formatTrueFalse(bool value, std::ostream & os)
84 os << (value ? "true" : "false");
87 prefix_ void senf::console::formatYesNo(bool value, std::ostream & os)
89 os << (value ? "yes" : "no");
92 prefix_ void senf::console::formatEnabledDisabled(bool value, std::ostream & os)
94 os << (value ? "enabled" : "disabled");
97 prefix_ void senf::console::formatOnOff(bool value, std::ostream & os)
99 os << (value ? "on" : "off");
102 prefix_ void senf::console::formatOneZero(bool value, std::ostream & os)
104 os << (value ? "0" : "1");
107 ///////////////////////////////cci.e///////////////////////////////////////
114 // comment-column: 40
115 // c-file-style: "senf"
116 // indent-tabs-mode: nil
117 // ispell-local-dictionary: "american"
118 // compile-command: "scons -u test"