00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00026 #include "Traits.ih"
00027
00028
00029 #include <boost/algorithm/string/predicate.hpp>
00030
00031 #define prefix_ inline
00032
00033
00034
00035
00036
00037 prefix_ void
00038 senf::console::ArgumentTraits<bool>::parse(ParseCommandInfo::TokensRange const & tokens,
00039 bool & out)
00040 {
00041 if (tokens.size() != 1)
00042 throw SyntaxErrorException("argument syntax error");
00043
00044 if ( boost::istarts_with(std::string("true"), tokens.begin()->value())
00045 || boost::istarts_with(std::string("enabled"), tokens.begin()->value())
00046 || boost::istarts_with(std::string("yes"), tokens.begin()->value())
00047 || boost::iequals(std::string("on"), tokens.begin()->value()) )
00048 out = true;
00049 else if (boost::istarts_with(std::string("false"), tokens.begin()->value())
00050 || boost::istarts_with(std::string("disabled"), tokens.begin()->value())
00051 || boost::istarts_with(std::string("no"), tokens.begin()->value())
00052 || (boost::istarts_with(std::string("off"), tokens.begin()->value())
00053 && tokens.begin()->value().size() >= 2) )
00054 out = false;
00055 else {
00056 int v (0);
00057 senf::console::parse(tokens, v);
00058 out = v;
00059 }
00060 }
00061
00062 prefix_ std::string senf::console::ArgumentTraits<bool>::description()
00063 {
00064 return "bool";
00065 }
00066
00067 prefix_ std::string senf::console::ArgumentTraits<bool>::str(bool value)
00068 {
00069 return value ? "true" : "false";
00070 }
00071
00072
00073
00074
00075 prefix_ void senf::console::ReturnValueTraits<bool>::format(bool value, std::ostream & os)
00076 {
00077 formatTrueFalse(value, os);
00078 }
00079
00080
00081
00082 prefix_ void senf::console::formatTrueFalse(bool value, std::ostream & os)
00083 {
00084 os << (value ? "true" : "false");
00085 }
00086
00087 prefix_ void senf::console::formatYesNo(bool value, std::ostream & os)
00088 {
00089 os << (value ? "yes" : "no");
00090 }
00091
00092 prefix_ void senf::console::formatEnabledDisabled(bool value, std::ostream & os)
00093 {
00094 os << (value ? "enabled" : "disabled");
00095 }
00096
00097 prefix_ void senf::console::formatOnOff(bool value, std::ostream & os)
00098 {
00099 os << (value ? "on" : "off");
00100 }
00101
00102 prefix_ void senf::console::formatOneZero(bool value, std::ostream & os)
00103 {
00104 os << (value ? "0" : "1");
00105 }
00106
00107
00108 #undef prefix_
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119