4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at
9 // http://senf.berlios.de/license.html
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on,
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
15 // Software distributed under the License is distributed on an "AS IS" basis,
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
17 // for the specific language governing rights and limitations under the License.
19 // The Original Code is Fraunhofer FOKUS code.
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V.
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
26 // Stefan Bund <g0dil@berlios.de>
29 \brief Traits inline non-template implementation */
34 #include <boost/algorithm/string/predicate.hpp>
36 #define prefix_ inline
37 //-/////////////////////////////////////////////////////////////////////////////////////////////////
39 //-/////////////////////////////////////////////////////////////////////////////////////////////////
40 // senf::console::ArgumentTraits<bool>
43 senf::console::ArgumentTraits<bool>::parse(ParseCommandInfo::TokensRange const & tokens,
46 if (tokens.size() != 1)
47 throw SyntaxErrorException("argument syntax error");
49 if ( boost::istarts_with(std::string("true"), tokens.begin()->value())
50 || boost::istarts_with(std::string("enabled"), tokens.begin()->value())
51 || boost::istarts_with(std::string("yes"), tokens.begin()->value())
52 || boost::iequals(std::string("on"), tokens.begin()->value()) )
54 else if (boost::istarts_with(std::string("false"), tokens.begin()->value())
55 || boost::istarts_with(std::string("disabled"), tokens.begin()->value())
56 || boost::istarts_with(std::string("no"), tokens.begin()->value())
57 || (boost::istarts_with(std::string("off"), tokens.begin()->value())
58 && tokens.begin()->value().size() >= 2) )
62 senf::console::parse(tokens, v);
67 prefix_ std::string senf::console::ArgumentTraits<bool>::description()
72 prefix_ std::string senf::console::ArgumentTraits<bool>::str(bool value)
74 return value ? "true" : "false";
77 //-/////////////////////////////////////////////////////////////////////////////////////////////////
78 // senf::console::ReturnValueTraits<bool>
80 prefix_ void senf::console::ReturnValueTraits<bool>::format(bool value, std::ostream & os)
82 formatTrueFalse(value, os);
85 //-/////////////////////////////////////////////////////////////////////////////////////////////////
87 prefix_ void senf::console::formatTrueFalse(bool value, std::ostream & os)
89 os << (value ? "true" : "false");
92 prefix_ void senf::console::formatYesNo(bool value, std::ostream & os)
94 os << (value ? "yes" : "no");
97 prefix_ void senf::console::formatEnabledDisabled(bool value, std::ostream & os)
99 os << (value ? "enabled" : "disabled");
102 prefix_ void senf::console::formatOnOff(bool value, std::ostream & os)
104 os << (value ? "on" : "off");
107 prefix_ void senf::console::formatOneZero(bool value, std::ostream & os)
109 os << (value ? "0" : "1");
112 //-/////////////////////////////////////////////////////////////////////////////////////////////////
119 // comment-column: 40
120 // c-file-style: "senf"
121 // indent-tabs-mode: nil
122 // ispell-local-dictionary: "american"
123 // compile-command: "scons -u test"