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::ArgumentTraits<std::string>
75 prefix_ void senf::console::ArgumentTraits<std::string>::
76 parse(ParseCommandInfo::TokensRange const & tokens, std::string & out)
78 senf_console_parse_argument(tokens,out);
81 prefix_ std::string senf::console::ArgumentTraits<std::string>::description()
86 ///////////////////////////////////////////////////////////////////////////
87 // senf::console::ReturnValueTraits<bool>
89 prefix_ void senf::console::ReturnValueTraits<bool>::format(bool value, std::ostream & os)
91 formatTrueFalse(value, os);
94 ///////////////////////////////////////////////////////////////////////////
96 prefix_ void senf::console::formatTrueFalse(bool value, std::ostream & os)
98 os << (value ? "true" : "false");
101 prefix_ void senf::console::formatYesNo(bool value, std::ostream & os)
103 os << (value ? "yes" : "no");
106 prefix_ void senf::console::formatEnabledDisabled(bool value, std::ostream & os)
108 os << (value ? "enabled" : "disabled");
111 prefix_ void senf::console::formatOnOff(bool value, std::ostream & os)
113 os << (value ? "on" : "off");
116 prefix_ void senf::console::formatOneZero(bool value, std::ostream & os)
118 os << (value ? "0" : "1");
121 ///////////////////////////////cci.e///////////////////////////////////////
128 // comment-column: 40
129 // c-file-style: "senf"
130 // indent-tabs-mode: nil
131 // ispell-local-dictionary: "american"
132 // compile-command: "scons -u test"