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 <sstream>
00030 #include <boost/format.hpp>
00031 #include <senf/Utils/TypeInfo.hh>
00032
00033 #define prefix_ inline
00034
00035
00036
00037
00038
00039 template <class Type>
00040 prefix_ void senf::console::ReturnValueTraits<Type>::format(Type const & value,
00041 std::ostream & os)
00042 {
00043 senf_console_format_value(value, os);
00044 }
00045
00046 template <class Type>
00047 prefix_ void senf::console::senf_console_format_value(Type const & value, std::ostream & os)
00048 {
00049 os << value;
00050 }
00051
00052
00053
00054
00055 template <class Type>
00056 prefix_ void senf::console::ArgumentTraits<Type>::
00057 parse(ParseCommandInfo::TokensRange const & tokens, Type & out)
00058 {
00059 senf_console_parse_argument(tokens,out);
00060 }
00061
00062 template <class Type>
00063 prefix_ void senf::console::parse(ParseCommandInfo::TokensRange const & tokens, Type & out)
00064 {
00065 ArgumentTraits<Type>::parse(tokens, out);
00066 }
00067
00068 template <class Type>
00069 prefix_ std::string senf::console::str(Type const & value)
00070 {
00071 return ArgumentTraits<Type>::str(value);
00072 }
00073
00074 template <class Type>
00075 prefix_ void senf::console::format(Type const & value, std::ostream & os)
00076 {
00077 ReturnValueTraits<Type>::format(value, os);
00078 }
00079
00080 template <class Type>
00081 prefix_ std::string senf::console::ArgumentTraits<Type>::description()
00082 {
00083 return prettyBaseName(typeid(Type));
00084 }
00085
00086 template <class Type>
00087 prefix_ std::string senf::console::ArgumentTraits<Type>::str(Type const & value)
00088 {
00089 std::stringstream ss;
00090 senf::console::format(value, ss);
00091 std::string rv (ss.str());
00092
00093 if (rv.empty() || ! boost::algorithm::all(rv, CommandParser::isWordChar)) {
00094 for (std::string::size_type i (0); i < rv.size(); ++i)
00095 if (rv[i] == '"' || rv[i] == '\\')
00096 rv.insert(i++,"\\");
00097 else if (rv[i] < ' ' || rv[i] > 126) {
00098 rv.insert(i+1, (boost::format("x%02x")
00099 % unsigned(static_cast<unsigned char>(rv[i]))).str().c_str());
00100 rv[i] = '\\';
00101 i += 3;
00102 }
00103
00104 rv.insert(0,"\"");
00105 rv.push_back('"');
00106 return rv;
00107 }
00108
00109 return ss.str();
00110 }
00111
00112
00113
00114
00115 template <class CharT>
00116 prefix_ void senf::console::detail::CharArgumentTraits<CharT>::
00117 parse(ParseCommandInfo::TokensRange const & tokens, CharT & out)
00118 {
00119 typename base::type v;
00120 base::parse(tokens,v);
00121 out = v;
00122 }
00123
00124 template <class CharT>
00125 prefix_ std::string senf::console::detail::CharArgumentTraits<CharT>::description()
00126 {
00127 return std::numeric_limits<CharT>::is_signed ? "byte" : "ubyte";
00128 }
00129
00130
00131 #undef prefix_
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142