2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
15 \brief Traits inline template implementation */
21 #include <boost/format.hpp>
22 #include <senf/Utils/TypeInfo.hh>
24 #define prefix_ inline
25 //-/////////////////////////////////////////////////////////////////////////////////////////////////
27 //-/////////////////////////////////////////////////////////////////////////////////////////////////
28 // senf::console::detail::ReturnValueTraits<Type>
31 prefix_ void senf::console::ReturnValueTraits<Type>::format(Type const & value,
34 senf_console_format_value(value, os);
38 prefix_ void senf::console::senf_console_format_value(Type const & value, std::ostream & os)
43 //-/////////////////////////////////////////////////////////////////////////////////////////////////
44 // senf::console::ArgumentTraits<Type>
47 prefix_ void senf::console::ArgumentTraits<Type>::
48 parse(ParseCommandInfo::TokensRange const & tokens, Type & out)
50 senf_console_parse_argument(tokens,out);
54 prefix_ void senf::console::parse(ParseCommandInfo::TokensRange const & tokens, Type & out)
56 ArgumentTraits<Type>::parse(tokens, out);
60 prefix_ std::string senf::console::str(Type const & value)
62 return ArgumentTraits<Type>::str(value);
66 prefix_ void senf::console::format(Type const & value, std::ostream & os)
68 ReturnValueTraits<Type>::format(value, os);
72 prefix_ std::string senf::console::ArgumentTraits<Type>::description()
74 return prettyBaseName(typeid(Type));
78 prefix_ std::string senf::console::ArgumentTraits<Type>::str(Type const & value)
81 senf::console::format(value, ss);
82 std::string rv (ss.str());
84 if (rv.empty() || ! boost::algorithm::all(rv, CommandParser::isWordChar)) {
85 for (std::string::size_type i (0); i < rv.size(); ++i)
86 if (rv[i] == '"' || rv[i] == '\\')
88 else if (rv[i] < ' ' || rv[i] > 126) {
89 rv.insert(i+1, (boost::format("x%02x")
90 % unsigned(static_cast<unsigned char>(rv[i]))).str().c_str());
103 //-/////////////////////////////////////////////////////////////////////////////////////////////////
104 // senf::console::detail::CharArgumentTraits<CharT>
106 template <class CharT>
107 prefix_ void senf::console::detail::CharArgumentTraits<CharT>::
108 parse(ParseCommandInfo::TokensRange const & tokens, CharT & out)
110 typename base::type v;
111 base::parse(tokens,v);
115 template <class CharT>
116 prefix_ std::string senf::console::detail::CharArgumentTraits<CharT>::description()
118 return std::numeric_limits<CharT>::is_signed ? "byte" : "ubyte";
121 //-/////////////////////////////////////////////////////////////////////////////////////////////////
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"