Fix documentation build under maverick (doxygen 1.7.1)
[senf.git] / senf / Utils / Console / Traits.cci
1 // $Id$
2 //
3 // Copyright (C) 2008
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Stefan Bund <g0dil@berlios.de>
7 //
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.
12 //
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.
17 //
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.
22
23 /** \file
24     \brief Traits inline non-template implementation */
25
26 #include "Traits.ih"
27
28 // Custom includes
29 #include <boost/algorithm/string/predicate.hpp>
30
31 #define prefix_ inline
32 //-/////////////////////////////////////////////////////////////////////////////////////////////////
33
34 //-/////////////////////////////////////////////////////////////////////////////////////////////////
35 // senf::console::ArgumentTraits<bool>
36
37 prefix_ void
38 senf::console::ArgumentTraits<bool>::parse(ParseCommandInfo::TokensRange const & tokens,
39                                            bool & out)
40 {
41     if (tokens.size() != 1)
42         throw SyntaxErrorException("argument syntax error");
43
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()) )
48         out = true;
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) )
54         out = false;
55     else {
56         int v (0);
57         senf::console::parse(tokens, v);
58         out = v;
59     }
60 }
61
62 prefix_ std::string senf::console::ArgumentTraits<bool>::description()
63 {
64     return "bool";
65 }
66
67 prefix_ std::string senf::console::ArgumentTraits<bool>::str(bool value)
68 {
69     return value ? "true" : "false";
70 }
71
72 //-/////////////////////////////////////////////////////////////////////////////////////////////////
73 // senf::console::ReturnValueTraits<bool>
74
75 prefix_ void senf::console::ReturnValueTraits<bool>::format(bool value, std::ostream & os)
76 {
77     formatTrueFalse(value, os);
78 }
79
80 //-/////////////////////////////////////////////////////////////////////////////////////////////////
81
82 prefix_ void senf::console::formatTrueFalse(bool value, std::ostream & os)
83 {
84     os << (value ? "true" : "false");
85 }
86
87 prefix_ void senf::console::formatYesNo(bool value, std::ostream & os)
88 {
89     os << (value ? "yes" : "no");
90 }
91
92 prefix_ void senf::console::formatEnabledDisabled(bool value, std::ostream & os)
93 {
94     os << (value ? "enabled" : "disabled");
95 }
96
97 prefix_ void senf::console::formatOnOff(bool value, std::ostream & os)
98 {
99     os << (value ? "on" : "off");
100 }
101
102 prefix_ void senf::console::formatOneZero(bool value, std::ostream & os)
103 {
104     os << (value ? "0" : "1");
105 }
106
107 //-/////////////////////////////////////////////////////////////////////////////////////////////////
108 #undef prefix_
109
110 \f
111 // Local Variables:
112 // mode: c++
113 // fill-column: 100
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"
119 // End: